Archive for the Category ◊ General ◊

Author:
Wednesday, May 01st, 2013

In this post I will present my views on various aspects of software architecture. These views are not limited to any specific technology.

What is Software Architecture?

A software architecture is typically a set of design decisions to address various non-functional requirements and attributes of a software system/application. It primarily focuses on aspects such as performance, reliability, scalability, testbility, maintainability and various other attributes, which can be key both structurally and behaviorally of a software system.

Architecture phase Architecture vs design

All architecture is design, but not all design is architecture

A new software product development requires a strong focus on some of these non-functional attributes based on the domain and the nature of the application. It establishes the context for design and coding. Example: A banking application may require special attention on security and availability of the application. Architectural decision have to be well thought to setup a strong base and long term view into consideration; its not only very difficult to change these decisions later on, but, will have significant ripple effects on the software.

Some of the things to keep in mind when architecting a software solution are:

  1. A, do not reinvent the wheel policy – Best architects copy solutions that are already proven in the software world. Architects are the one who adapts them to the current context, improve upon their weaknesses and design in such a way that it enables incremental improvements.
  2. Simplest architectures are the best – One always has to remember that there will be trade-offs. Example: For a highly scalable system you will trade off cost. Attempting to put an architecture in place which addresses all the non-functional attributes, you are asking for the trouble. By this approach you are not only creating complexity into the system but, making it extremely difficult for the design and implementation team.
  3. Demo’able architectural blueprint – A software architecture blueprint should ultimately be converted into executable code. It should not be a mere sketch on a paper or a soft-copy of the model, which the software designers find impossible to visualize and construct.
  4. Key responsibilities - Define and validate the system’s architecture, maintain the conceptual integrity of the system, assess and attack technical risks to the system, resolve the design and implementation teams conflicts, document the architecture.
  5. Keep tool set upto date – Modern day software requires architects to have updated tool sets in their bag to fulfill various challenges. They particularly have to be aware of how to effectively use them. There are several out of the box architectural tactics, patterns to help architect solve recurring problems.

I plan to cover some of these patterns and tactics in my next post.

 

Category: General  | Leave a Comment
Author:
Wednesday, May 01st, 2013

In most webpages we judiciously use jQuery and a few other JS plugins. Plus some of our own JS files. We also have a bunch of CSS files and images. Which means when our webpage is loaded in the browser, it has to make several requests to the server to get all the additional files. Sure, the browser tries to fetch several files in parallel. But most browsers put an upper limit to how many parallel requests to make. In most cases this limit is 6. That means if your web page refers to more than 6 files, then some files will have to wait till others have been downloaded. Its easy to see examine this behavior using your browser’s developer tools (Chrome developer tools, Firebug or IE’s F12 window). On most browsers you can hit F12 key to access developer tools. You can find out which files are being requested by your browser and in what order from the Network tab. Here’s an example of how it looks in Chrome:

chrome dev tools

As you can see from the picture some files are loaded after other have finished. Hence you can significantly reduce the load time of your page by referring as few files as possible. There are also tools/libraries that can help you combine several JS files into one (CSS files too). If you are using images to achieve a gradient look, try using CSS gradient instead. May be some files are not needed in a some pages. Anyways, you can figure out a suitable solution once you know what’s going on and the Network monitoring feature of your browser can help you figure out just that.

Firefox users can use Firebug: http://getfirebug.com/network

IE users can use Internet Explorer Developer Tools: http://msdn.microsoft.com/en-us/library/gg130952(v=vs.85).aspx

Happy optimizing!

- Anand Gothe

Category: CSS3, General, HTML5  | One Comment
Author:
Saturday, March 23rd, 2013

Writing email is a part of our day to day activities. If you are work at office you write email to your colleagues,clients. There are few rules of email etiquette help us communicate better via email.

1) Use appropriate Subject Lines

emailsubject

 

 

 

 

Do not keep the subject line blank. Keep the subject line simple and more appropriate to the content of the email. The recipient will decide to read the email reading the subject line of the email.

2) Always use “Reply to All”

reply to all

 

 

 

 

 

 

3) Be simple and to the Point.

Email is harder to read then the printed messages. The email that goes on and on is less likely to be read . If the email is just 2 or 3 sentences then may be you should just pick up the phone and talk to the person.

4) Use proper grammar, punctuation and spelling.

Poorly written email with bad grammar reflects on you and your company.Almost every email tool has speller and grammar checker program. So use it.

5) The 24 Hour Rule

Always reply to your email within 24 hours . This tells your customer that you are focused on prompt service .

6) Do not write in All Caps.

capsimages

 

 

 

 

 

Writing in all caps makes it difficult to read the email.Its also sends another unintended message that you are shouting .

 

7) Read you email before sending it .

Taking your time and read your email before sending it .

8) Use disclaimer at the bottom of the email .

The information transmitted, including attachments, is intended only for the person(s) or entity to which it is addressed and may contain confidential and/or privileged material. Any review, re transmission  dissemination or other use of, or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and destroy any copies of this information.

Most of you might think that this will take more space in email . But these words will save a lot of money for your company whenever there are any legal issues.

 

Author:
Saturday, January 26th, 2013

A few months back Intel announced a “mini desktop motherboard + processor” combo, ambitiously named  NUC – Next Unit of Computing. These are small 4×4 inch motherboards with processors baked in and lots of connection ports. Put it in a tiny box, add some RAM and a hard disk and you’ve got yourself a really small (but powerful) PC. You can already buy devices based on NUC, from vendors like Gigabyte and Velocity. Several more vendors will introduce similar devices on coming months.

nuc-dc3217by-image Now, there isn’t anything new here. Small form-factor PCs have been around for quite some time now: Giada Mini PCs, Zotac’s ZBOX series and ASRock Mini PCs. What’s exciting about Intel’s move is that, this give a huge push to the Mini PC segment. All the models currently (Jan 2013) listed on Intel’s website have a 3rd generation Intel Core i3 processor. An i5 version is expected to come out soon. However, other vendors like Habey and Gigabyte have already announced and i5 mini-pc based on Intel’s NUC concept.

I’m really excited because these are powerful (yet-tiny) desktop PCs that would consume a fraction of electricity (compared to the huge box that sits under my desk).  Some models will also support dual monitors out of the box. Great of programming. They’ll come with vesa mount support, so it’ll fit right behind your monitor! I think the NUCs will really catch on, and in couple of years, completely replace the bulky desktop PCs.

Category: General | Tags: , ,  | Leave a Comment
Author:
Thursday, January 03rd, 2013

We have a large TV in our front office. About a year back, we set it up to display twitter feeds, weather, news and pictures. We did this by connecting it to a Windows 8 (preview) PC and set up live tiles for with like AccuWeather, FlipToast (twitter), NDTV news and picture gallery. It’s been working just fine. However, one thing kept nagging me. I felt like we’re wasting a perfectly fine desktop PC just to drive a simple front-office display. That was until recently, when I found out about the Android Mini PC!

The Android Mini PC is a small device, the size of a pen drive, that you can directly plug into your TV and convert it into a large android tablet! The model I bought was Rikomagic 802 III, which has a dual-core processor, 1GB RAM and 8GB system memory, Wifi and runs Android 4.1. It worked right out of box, all I had to do was plug it into the TVs HDMI port and USB port (for power). I also connected a wireless USB keyboard+mouse. It booted in few seconds with gorgeous Android desktop. All I had to do was download a few apps from Play Store and set up some widgets on the home screen. I used Android Pro Widgets for twitter feed, AccuWeather for weather, NDTV App for news and “Photo Frame Home Screen” for pictures. Here’s a picture of how it turned out:

Have I told you the best part yet? The mini pc cost me only $70 (including shipping) and freed it up the desktop PC that was connected to the TV.

Happy New Year!

- Anand Gothe

Tuesday, April 17th, 2012
Plates is the templating library in flatiron. Plates binds data to markup. It’s Javascript, Markup and JSON. It works in the browser and in node.js. All templates are actually valid HTML, with no special characters for value insertion. The relationship between tags and values is defined through object literals that are passed to Plates.bind:
You have to install plates before using it
Plates can be used in the program by requiring it.
var http = require(‘http’),
plates = require(../lib/plates’);
var server = http.createServer(function (req, res) {
res.writeHead(200);
var userSpan = ‘<span id=”spFirstName”>Prajeesh</span>&nbsp;<span id=”spLastName”>Prathap</span>’
var userHtml = ‘<div id=”pnlLogin”></div>’;
var map = plates.Map();
map.where(‘id’).is(‘spFirstName’).use(‘value’).as(‘Prajeesh’);
var content = plates.bind(userHtml, { ‘pnlLogin’: userSpan });
res.end(content)
});
server.listen(8083);


Category: General  | Leave a Comment
Monday, April 16th, 2012
Director is a URL router module which comes as part of the flatiron framework.  It works in a browser for single page apps and in Node.js. It’s not a plugin for another framework. It’s not dependent on anything. It’s a modern router that was designed from the ground up with javascript.
Installing flatiron
You can install flatiron using npm (npm install flatiron –g)
Director handles routing for HTTP requests similar to journey or express:
var http = require(‘http’);
var director = require(../lib/director’);
function sayWelcome(route) {
this.res.writeHead(200, { ‘Content-Type’‘text/plain’ });
this.res.end(‘Welcome to flatiron routing sample’);
}
var router = new director.http.Router({
: {
get: sayWelcome
}
});
router.get(‘/index’, sayWelcome);
router.get(‘/home’, sayWelcome);
var server = http.createServer(function (req, res) {
router.dispatch(req, res, function (err){
if (err) {
res.writeHead(404);
res.end(‘Error!!!’);
}
})
});
server.listen(8083);
When developing large client-side or server-side applications it is not always possible to define routes in one location. Usually individual decoupled components register their own routes with the application router. Director supports ad-hoc routing also.
router.path(/\/customers\/(\w+)/, function (res) {
this.post(function(id) {
//sayWelcome(‘some’);
this.res.writeHead(200, { ‘Content-Type’‘text/plain’ });
this.res.end(‘Create a customer with Id = ‘ + id)
});
this.get(function (id) {
//sayWelcome(‘some’);
this.res.writeHead(200, { ‘Content-Type’‘text/plain’ });
this.res.end(‘Gets a customer with Id = ‘ + id)
});
this.get(/\/orders/, function (id) {
this.res.writeHead(200, { ‘Content-Type’‘text/plain’ });
this.res.end(‘Gets orders for a customer with Id = ‘ + id)
});
});















Category: General | Tags: ,  | Leave a Comment
Wednesday, April 11th, 2012
A common problem when writing Node.js programs is in ensuring all exceptions are handled. Node.js will helpfully die when exceptions are not caught and handled, which forces you, the author, to ensure robustness in your Node.js applications.  Node emits an uncaughtException event when an exception bubbles all the way back to the event loop. If a listener is added for this exception, the default action (which is to print a stack trace and exit) will not occur.
process.on(‘uncaughtException’, function (ex) {
console.log(‘Unhandled exception caught: ‘ + ex);
process.exit();
});
If you are writing asynchronous code, you can follow the below given pattern to throw and handle exceptions in the code. In this pattern the first argument of the callback is err, if an error happens it is the error, if it doesn’t it is null.
var divideAsync = function (arg1, arg2, callback) {
if (arg2 == 0) return callback(new Error(‘division by 0 is not possible’));
return callback(null, arg1 / arg2);
}
divideAsync(9, 0, function (ex, result) {
if (ex) {
console.log(‘Error in division ‘ + ex);
process.exit();
}
console.log(‘result ‘ + result);
});
You can also use the traditional try {} catch (err) {} to catch exceptions as given below
console.log(‘Starting directory: ‘ + process.cwd());
try {
process.chdir(‘/tmp’);
console.log(‘New directory: ‘ + process.cwd());
}
catch (err) {
console.log(‘chdir: ‘ + err);
process.exit();
}
For synchronous code, if an error happens you can return an instance of Error object and later check the result for this
object as given below.
var divide = function (arg1, arg2) {
if (arg2 == 0) return new Error(‘division by 0 is not possible’);
return arg1 / arg2;
}
var x = divide(5, 0);
if (x instanceof Error) {
console.log(‘Exception logged’);
process.exit();
}
Category: General  | Leave a Comment
Tuesday, April 10th, 2012
Pure javascript, while great with unicode-encoded strings, does not handle straight binary data very well. This is fine on the browser, where most data is in the form of strings. However, node.js servers have to also deal with TCP streams and reading and writing to the filesystem, both which make it necessary to deal with purely binary streams of data. Node has several strategies for manipulating, creating, and consuming streams. Raw data is stored in instances of the Buffer class. A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized. The Buffer class is a global, making it very rare that one would need to ever require(‘buffer’).
Converting between Buffers and JavaScript string objects requires an explicit encoding method. The encodings that are supported are ‘ascii’, ‘utf8′, ‘usc2′, ‘base64′, ’binary’ and ‘hex’.
Writing to buffers
new Buffer(size) methods allocates a new buffer of size octets. Once the buffer is created, the buffer.write method is used to write a string value to the buffer
var buffer = new Buffer(100);
var stringToWrite = ‘Sample text to add to a buffer’;
//Write data to a buffer
buffer.write(stringToWrite, ‘utf-8′);
//finding the length of buffer
var offset = Buffer.byteLength(stringToWrite);
console.log(offset);
//Appending data to the existing buffer
buffer.write(‘. This is an appended text’, offset, ‘utf-8′);
console.log(buffer.toString(‘utf-8′));
Copy values to buffer
buffer.copy allows one to copy the contents of one buffer onto another. The first argument is the target buffer on which to copy the contents of buffer, and the rest of the arguments allow for copying only a subsection of the source buffer to somewhere in the middle of the target buffer. For example:
var helloBuffer = new Buffer(50);
helloBuffer.write(‘Hello ’, 0, ‘utf-8′)
var welcomeBuffer = new Buffer(‘node.js.’);
var helloStringLength = Buffer.byteLength(‘Hello ‘);
var welcomeStringLength = Buffer.byteLength(‘node.js.’);
//Copies from welcomeBuffer to helloBuffer
welcomeBuffer.copy(helloBuffer, helloStringLength, 0);
console.log(helloBuffer.toString(‘utf-8′));
Cropping the buffer
buf.slice([start], [end]) method returns a new buffer which references the same memory as the old, but offset and cropped by the start (defaults to 0) and end (defaults to buffer.length) indexes. The slice is not a new buffer and merely references a subset of the memory space. Modifying the slice will also modify the original buffer. For example:
var nodejsSlice = helloBuffer.slice(helloStringLength, helloStringLength + welcomeStringLength);
console.log(nodejsSlice.toString());
nodejsSlice.write(‘Prajeesh’);
console.log(helloBuffer.toString());


Category: General | Tags:  | Leave a Comment
Friday, April 06th, 2012
You can use the JavaScript timers, such as setTimeout(), clearTimeout(), setInterval(), clearInterval() in your node apps. All of the timer functions are globals. You do not need to require() this module in order to use them. To schedule the repeated execution of callback every delay milliseconds you can use the setInterval() method. The setInterval returns an intervalId which can be later used to clear the interval execution with the clearInterval() method.
Similary to schedule execution of a one-time callback after delay milliseconds use the setTimeout() method.
var index = 0;
setTimeout(function (timeoutMessage) {
console.log(timeoutMessage);
}, 100, ‘Hello timeout’);
var intervalId = setInterval(function (message) {
index++;
if (index == 5) {
clearInterval(intervalId);
}
console.log(message);
}, 200, ‘Hello interval’);


Category: General  | Leave a Comment