How to install and configure grunt on mac Osx

This post is intended to assist folks who are trying to install and work with grunt on mac osx

Install Node.js and npm with Homebrew

First, install Homebrew by typing in the following command ruby -e “$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"

Then, type in brew update to ensure your Homebrew is up to date.

brew update

Run

brew doctor 

to make sure your system is all good.

Follow any other recommendations from brew doctor.

Read more →

Normalizing Ranges of Numbers

Range Normalization is a normalization technique that allows you to map a number to a specific range.

Lets say that we have a data set where the values are in a range of 1 to 10, however we wish to normalise it to a range between 0 and 5

Mathematically speaking the equation comes down to

eq1

eq2

translated to Python

class Normaliser:

   def \_\_init\_\_(self,dH,dL,nH,nL):
       self.dH = dH
       self.dL = dL
       self.nH = nH
       self.nL = nL

   def normalize(self,x):
       return ((x - self.dL) / (self.dH - self.dL))  * (self.nH - self.nL) + self.nL

   def denormalize(self,x):
       return ((self.dL - self.dH) * x - self.nH * self.dL + self.dH * self.nL) / (self.nL - self.nH)

if \_\_name\_\_ == "\_\_main\_\_":
   norm = Normaliser(10,1,5,0);

   for a in range(1,11):
       x = norm.normalize(a);
       y = norm.denormalize(x);
       print str(a) + " : " + str(x) + " : " + str(y)

The results

Read more →

Gheat Java – Heat maps

heat_map

A heat map is a graphical representation of data where the individual values contained in a matrix are represented as colors.

This article will attempt to explain the process or creating and using GHEAT-JAVA, which is a port of famous aspen based gheat and took great inspiration from Gheat.net

Writing a service which would serve heat map tiles is a bit tricky,there are three major components involved

  1. The client part i.e. some kind of mapping library which has a concept of layer, I chose Google maps.
  2. The data source part, i.e. a spatially aware database or an in memory data structure, I have used postgres ,an in memory quad tree and a flat file as data sources.
  3. The renderer part or basically the code which excepts requests , parses tile bounds, fetches data and then renders gradients on the tile and later colorizes them.

The Tiling layer (Client part)

Google maps allows developers to add a custom layer , the code looks like this

Read more →

Embedding Flash,Quicktime,Windows Media,Silverlight or HTML5 Video

Flash Object

This is quick Snippet which demonstrate how to embed flash object in a web page.

<object type="application/x-shockwave-flash"
 data="path-to-my-flash-file.swf"
 width="0" height="0">
 <param name="movie" value="your-flash-file.swf" />
 <param name="quality" value="high"/>
</object>

Quicktime

This is quick Snippet which demonstrate how to embed quicktime object in a web page

<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"
      codebase="http://www.apple.com/qtactivex/qtplugin.cab"
      width="200" height="16">
<param name="src" value="pathToMyMovie.mov" />
<param name="autoplay" value="true" />
<param name="pluginspage" value="http://www.apple.com/quicktime/download/" />
<param name="controller" value="true" />
<!--[if !IE]> <-->
  <object data="movie.mov" width="200" height="16" type="video/quicktime">
    <param name="pluginurl" value="http://www.apple.com/quicktime/download/" />
    <param name="controller" value="true" />
  </object>
<!--> <![endif]-->
</object>

Windows Media

This is quick Snippet which demonstrate how to embed Windows Media object in a web page.

Read more →

Mod Proxy equivalent in IIS using ARR and URL Rewrite Module

IIS7 is quite modular, it is shipped with lots of goodies as separate modules and together it is now one of the most powerful and flexible web server.

In this post I intent to cover how we can easily configure ARR and URL Rewrite Module to get a similar functionality as of Mod Proxy in Apache.

Here I will demonstrate configuration of a reverse proxy which according to the definition is

Reverse proxy is a type of proxy server that retrieves resources on behalf of a client from one or more servers. A general use case to configure such proxies could be to handle cross domain Ajax requests, so basically if I would like to call a service hosted as http://anotherdomain.com/service from http://localdomain/service I would need to configure a proxy which will request resources from anotherdomain.com/service on behalf of localdomain ### Configuration

Read more →

Signing android release apk from the command line (via ant)

This post is probably out too late ,as almost all IDE’s these days (which support android development) ,probably have an Integrated release signing or debug signing utility/wizard built in, but if somebody is using an old IDE or perhaps want to integrate release in a CI(continues integration) environment , this tutorial might come in handy.

Basically one has to sign an apk either with a debug key (which is generally present in your .android folder) or a create a fresh application specific keystore , to know more go here

Read more →

Importing Exporting CSV Files in PostgreSQL Databases via COPY

This is going to be a short article which will illustrate importing and exporting a table from or to a csv file using PostgreSQL COPY command.

Importing a table from CSV

Assuming you already have a table in place with the right columns, the command is as follows

COPY FROM ‘/path/to/csv/SourceCSVFile.csv’ DELIMITERS ‘,’ CSV;

Exporting a CSV from a table.

COPY TO ‘/path/to/csv/TargetCSVFile’ DELIMITERS ‘,’ CSV;

Read more →

Serve the contents of any directory with Python’s SimpleHTTPServer

Generally, when I am in a middle of prototyping a concept or in a need of quickly executing Ajax requests or using browser features which would need the page to be hosted on a web server, I use Python’s SimpleHTTPServer module.

Python’s SimpleHTTPServer is a great way of serve the contents of the current directory,all one needs to do is change directory and execute a command which will expose all contents as if they were hosted in a web page.

Read more →

Position div in the center of the page using css

When I first started web programming, creating a center aligned div was one of the most common task that I saw myself doing.

since div is a block element, i.e. it takes up the full width available, and has a line break before and after it, it can easily be centered using relative styling

{
margin-left:auto;
margin-right:auto;
width:70%;
background-color:#b0e0e6;
}

However lately I have preferred using absolute positioning technique over relative, this works for all browsers and is best for login screens or alert messages over a translucent shim.

Read more →

Basic authentication in web.py via attribute

Here I demonstrate the process of Basic Authentication in web.py python web framework.

There is a proof of concept article provided in the main site,however I just thought doing the same via an attribute might be a cleaner solution.

HTTP Basic authentication implementation is one of the easiest ways to secure web pages because it doesn’t require cookies, session handling, or the development of login pages. Rather, HTTP Basic authentication uses static headers which means that no handshakes have to be done in anticipation,however the n the credentials are passed as plain-text and could be intercepted.

Read more →

Installing Redis on Ubuntu

Redis is an open source, advanced key-value store. Installing it on Linux debian platforms is pretty easy.

There are two ways of getting this done, one is perhaps an easy and less verbose method and it involves using an alternative repository Dotdeb.

A while ago I had posted a tutorial about installing redis from the googlecode repo, but things have changed since then and here I post a fairly latest way of installing it.

Read more →

gzip compression in apache using mod_deflate

HTTP Compression is a very simple and effective way to save bandwidth and improve web applications performance over network.

Output compression is basically a process of compressing web servers response by using a loss-less compression algorithm called gzip.

This technique is fairly modern and almost all modern browsers honor it, however if a page is requested from a browser which does not send a header Accept-Encoding: gzip,deflate then the response comes back uncompressed.

Read more →

Start Stop Restart Apache 2 Web Server

I have been using Linux environment a lot lately, particularly for hosting my web experiments and other application. One of the biggest and most searched question for newbies have been

How do I restart Apache 2 Web Server under Debian / Ubuntu Linux or UNIX operating systems?

In this post I simply attempt to lay this down for my and their benifit.

Start Apache2 # sudo /etc/init.d/apache2 start

Stop Apache2 # sudo /etc/init.d/apache2 stop

Read more →

How To Install and use Python Web.py framework on Windows

Web.py has been one of my favorite web frameworks as its pretty easy to get cracking on it.

It’s super quick to install and one can come up with a prototype and rapid web services in matter of minutes.

Install on windows

If you haven’t configured easy_install on windows, then read this article.

Once easy_install has been configured believe it or not, all you have to do is open a command prompt and type

Read more →

How to setup easy_install on Windows

If one has been using python, then installing various libraries and modules is basically a breeze using easy_install utility, however for folks using windows, easy_install utility has to be setup properly before using it.

First lets make sure that python is properly installed and PYTHON_HOME environment variable is configured:

Install Python on Windows

If not already installed download python installer from here.

After it’s done downloading, double click to run the installer, and select default options (unless you have other custom needs of course ).

Read more →

Find Longitude and Latitude in Google Maps

This post is basically a way of quick appreciation to the Google maps Team, they are obviously a bunch of caring, loving people ,who make useful (although surreptitious) tools for the betterment of Geek Kind.

So as most of you may have accidently clicked a mysterious looking link at the bottom of your Google maps page ( on the left hand panel)google_latlon_tool1

This awesome looking link opens up a popup which lets you choose wonderful goodies which makes your Google maps page more useful than it already is:

Read more →

How to set up Redis in Ubuntu Linux

Redis is an open source, advanced key-value store, and is quickly picking up momentum in real-time software development , it is now a well known and trusted product and can be used in various problem scenarios as a No SQL implementation.

Redis is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.

Here is quick guide to Install Redis in Ubuntu 10.04, and it should be similar for higher versions and similar deb environment.

Read more →

Image Carousel

Here is another of many JavaScript based Image Carousel, I had seen many similar to these made in SilverLight and Flash, I came across a wonderful carousel made in SilverLight sometimes back which was very fluid in behavior and could easily be customized and configured to take various shape and form.

carousel

I have managed to port it to JavaScript, it works best on chrome or FF, hope this would be fun to play with.

Read more →

Data URI and IE

Few days ago I was experimenting with a nifty technique of embedding images in web pages by base64 encoding them first and then using a standard known as Data URI Scheme, which basically defines a method of assigning a ‘src’ of an image tag as a base64 serialized string, like this:


background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAUBAMAAACKWYuOAAAAMFBMVEX///92dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnZ2dnYvD4PNAAAAD3RSTlMAACTkfhvbh3iEewTtxBIFliR3AAAAUklEQVQY02NgIBMwijgKCgrAef5fkHnz/y9E4kn+/4XEE6z/34jEE///A4knev7zAwQv7L8RQk40/7MiggeUQpjJff+zIpINykbIbhFSROIRDQAWUhW2oXLWAQAAAABJRU5ErkJggg==");

   

Although this technique could save some server round trips, however Microsoft ver. (IE < 8). does not support this scheme even though its a standard, which then makes this technique unfavorable to use as its not cross browser.

Read more →