AMD in Javascript

AMD stands for Asynchronous Module Definition. In a nutshell, it’s a format or a specification for writing javascript.

So, what is a Javascript module?

Its a reusable code which exports specific objects, making them available for other modules through dependency references to be used their programs.

These modules can be loaded asynchronously, if desired.  That means, there’s  a huge improvement in website performance as the files are only loaded when they are needed.  Also, it provides developers with the flexibility to define order in which module dependencies have to be loaded and load multiple javascript files during runtime.

AMD implementation is used by jQuery, Dojo, Firebug etc. There are various javascipt module loaders like RequireJS,  Browserify,  Webpack, SystemJS


Round, ceil, floor : Decimal to integer

Javascript has inbuilt functions for converting decimal number to an integer value.

Math.round function is used to round a number to its nearest integer. If fractional part of the number >=0.5 then the argument is rounded to next higest integer.
If fractional part of the number < 0.5 then the argument is rounded to lowest integer.
Syntax: Math.round(number)
eg. Math.round(7.5) = 8
Math.round(7.2) = 7

Math.ceil function returns integer greater than or equal to a given number. Ceil means think of the ceiling of the room which is above your head.
Syntax: Math.ceil(number)
eg. Math.ceil(7.5) = 8
Math.ceil(7.2) = 8
Math.ceil(7) = 7
Math.ceil(-7.5) = -7
Math.ceil(-7.2) = -7

Math.floor function returns integer lesser than or equal to a given number. Floor means think of the floor of the room which is below you
Syntax: Math.floor(number)
eg. Math.floor(7.5) = 7
Math.floor(7.2) = 7
Math.floor(7) = 7
Math.floor(-7.5) = -8
Math.floor(-7.2) = -8


What is a BLOb?

BLOb, Binary Large OBject : is a collection of binary data stored as a single entity in a database management system. Blobs are typically images, audio or other multimedia objects. Database support for blobs is not universal. Blobs were originally just big amorphous chunks of data invented by Jim Starkey at DEC(Digital Equipment Corporation)

The four BLOB types are

  • TINYBLOB : A BLOB column with a maximum length of 255 (28 – 1) bytes. Each TINYBLOB value is stored using a one-byte length prefix that indicates the number of bytes in the value
  • BLOB : A BLOB[(M)] column with a maximum length of 65,535 (216 – 1) bytes. Each BLOB value is stored using a two-byte length prefix that indicates the number of bytes in the value.
    An optional length M can be given for this type. I
  • MEDIUMBLOB : A BLOB column with a maximum length of 16,777,215 (224 – 1) bytes. Each MEDIUMBLOB value is stored using a three-byte length prefix that indicates the number of bytes in the value.
  • LONGBLOB : A BLOB column with a maximum length of 4,294,967,295 bytes or 4GB (232 – 1). Each LONGBLOB value is stored using a four-byte length prefix that indicates the number of bytes in the value.

“#!” Shebang (Sha-bang, Hashbang)

I came across this line #!/usr/bin/env and was wondering what is this and for what? I browsed some articles to get some overview about it. Any script beginning with #! is called shebang(other names are hashbang, sha-bang etc). When a script with shebang is run, it passes the file as an argument to the specified program instead of trying to execute it.

The form of a shebang interpreter directive is as follows:

#! interpreter [optional-arg]

The interpreter must be an absolute path to an executable

In order to run the script, we need to tell the shell three things:

  1. That the file is a script –>accomplished using shebang #!

  2. Which interpreter we want to execute the script

  3. The path of said interpreter

2 and 3 is accomplished using env. 

Some typical shebang lines:

  • #!/bin/sh — Execute the file using sh
  • #!/usr/bin/perl — Execute using Perl
  • #!/usr/bin/python — Execute using Python

Shebang lines may include specific options that are passed to the interpreter.

Understanding some techy terms/concepts

  • Memoization – I give you 2 candies for breakfast, you have 2 candies. 3 candies after lunch, now you have (3+2=5) 5 candies. After dinner I give you 1 candy, Ho w many candies do you have at the end of the day?(assuming you haven’t eaten any :-P) You have (5+1=6) 6 candies at the end of the day. In short, what are you doing here? You are using the count of previous candies and adding the current count to it. Rather than, counting all over from the beginning. This concept is used in Dynamic Programming, remember things to save time later.
  • Deadlock – For getting a job I need experience, For becoming experienced I need a job. (especially for freshman)
  • Bootstrapping/Booting – Sequence of operations that starts the operating system, i.e. OS of a computer when it is turned on. Loading of an OS into the memory for running application, one loaded.
  • Protocol – Person A speaks French to Person B. But, Person B can only speak English. So, what they need to do in order to communicate?  Come up with a standard language understood by both of them or get a translator. Same thing happens when two devices are communicating, therefore a protocol i.e. a set of rules or standards is needed to govern the correct interpretation of communication.
  • Mount – This term is used for Unix based operating systems. Mounting means giving a location in a directory tree to a new storage device. Unmount means undoing the mount.

Framework and its potentialities

What is so special about frameworks? We hear about these web frameworks frequently like Django, Cake PHP, Rails etc.  Let’s dive into frameworks.

Framework gives you a ready-made code base which has been tested and designed by many developers and is ready to use solution for common generic problems. That is, it provides with a generic functionality which has flexibility to be changed, which helps you take advantage of this generality. It provides powerful template where the logic can be injected, helps in simplifying complex things.


  • Saves lot of time, DRY(Don’t Repeat Yourself) means fewer lines of code
  • Provides a standard through which the user can develop the module or a complete application instead of starting from lower level details.
  • More time can be devoted in developing the software and not in preparing the environment and tools of development.
  • Code is extensible for future use with clean code

Heads Up! Framework doesn’t work everywhere, for instance smaller projects which require simple coding seems to work faster than setting up a framework.

Setting environment variable for python in Windows

Tip for those running python script on Notepad++
Press F5 to run current script and to avoid output screen disappear instantaneously type in command: cmd /k python -i “$(FULL_CURRENT_PATH)”.