How to Query a Shape file for Point inside a polygon using ogr python

Recently I was trying to build a quick geo lookup service in python, which could be used like an “info tool” in QGIS. This task is trivial in almost all geospatial databases, however I wasn’t able to find much online around querying a shape file.

In this post I will demonstrate a simple python code to query a shape file which contains world countries. The file can be downloaded from here.

Read more →

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 →

Raphael-js-tutorial-part-II

This is second part of the tutorial about getting started with Raphael.js. To see this first part go here.

Writing Text with Raphael

Some code first ;)

var canvas = Raphael(0, 0, 250, 250 );

var t1 = canvas.text(50, 50, *"Some text Goes here"*);

var t2 = canvas.text(60,90,"First line \n Second Line \n Third line");

var t3 = canvas.text(214, 140, "1079").attr({"text-anchor":"middle",'font-size':16,"font-family":"arial","fill":"#fff"});

In the above examples canvas.text will create a simple text element at 50,50. Strangely VML /SVG do not have Line breaks therefore the programmer is responsible for creating new lines,in most cases appending** ‘\n’** does the trick.

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 →

Raphael JS Tutorial - Part I

Raphael.JS is a SVG/VML library which helps you to create quick vector shapes and images. Its very small and compact (only 86kb),easy to use,well documented and works in all browsers and yes even IE. Here is a list of all major browsers this library works on: Chrome 5.0+ Firefox 3.0+, Safari 3.0+, Opera 9.5+ and Internet Explorer 6.0+

,finally its distributed under MIT license. In this tutorial ,I intend to introduce basics of this library and help you get started.

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 →

A guide to hosting in Red Hats OpenShift PaaS

In this post,I am going to write about OpenShift, which is Red hat’s free, auto-scaling Platform as a Service (PaaS) for applications.

OpenShift to me is very similar to Google’s app engine in some ways,but openshift’s offerings are quite diverse, for instance support for ruby, php, Perl, node.js, etc..

Openshift is not like a traditional VPS hosting , although once registered with them, user does get a shell access,but its quite limited , instead OpenShift has a concept of gears and cartridges.

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 →

Cross browser drop shadow with CSS3

When css3 arrived, one of the goodies that I found was, the inclusion of Drop Shadow effect, namely **Box Shadow **and Text Shadow.

Here I present a cross browser utility css class which can be used for a drop shadow effect, without any image.

.shadow {
      /* For IE 8 */
   -ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000')";
   /* For IE 5.5 - 7 */
   filter: progid:DXImageTransform.Microsoft.Shadow(Strength=4, Direction=135, Color='#000000');
   -moz-box-shadow: 3px 3px 4px #000;
   -webkit-box-shadow: 3px 3px 4px #000;
   box-shadow: 3px 3px 4px #000;
}

For cross browser text shadow effect ,I found a nice article here.

Read more →

Cross browser CSS3 border-radius (rounded corners)

When I started programming and had to begin designing my first user interface in HTML, I was always puzzled as to why are all visual elements in HTML rectangular. I soon learned that in those days if one would want a circle to be drawn on a page, then the only way possible was using an image, the same was true for drawing elements with rounded corners.

Thankfully HTML5/CSS3 guys were listening and the latest css3 standard supports defining the corner radius of a circle, this can be used to make an element look like a circle too if you want.

Read more →

Cross Browser Opacity or Transparency

Css has a very useful property called Opacity, which basically is a measure of transparency of an element.

All modern browsers Yes yes even IE has support for it.

In most browsers the value is between 0 minimum [transparent] i.e not visible to 1 maximum [opaque] i.e. completely visible

In IE the value is between 0 and 100 ,don’t ask why they just like to make us unhappy.

Here I present a helper css class which will work in all browsers.

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 →