watir-webdriver web inspector

An experimental minimal combinatorial code generation on element inspection. Check out the repo for sending your P.R ;)

The raw code is as below, and it's evolving!

gem list to gemfile

Say you have n-machines that needs to be in sync with their ruby gem versions, we can have one system to update all as per need and then create this Gemfile and distribute the same.

Here is a simple chunk of code that would help to convert all the gems install to a gemfile, which can later be used with bundler.

Packing ruby2.0 on debian.

One can use the below script to package ruby2.0 on squeeze.

To get going, just get the script form Here and says sudo bash ruby-deb.sh then enjoy ruby2.0! :)

Made it into The Guinness Book!

Couple of weeks back when I was cleaning my mailbox I noticed a mail which read Hey redditgiftor, YOU are a Guinness World Record holder! Ok just another spam I felt, but the mail ID seemed genuine to so just read it and noticed that it had a link to the original guinness site with a username and key!

Had a quick check on redditgits and turned out to be true, it was a Guiness record indeed! I was a part of 30k people heh heh sounds like a big number but is small when compared to 7 billion human beings ;)

Had to pay some $$ to get the certificate shipped to my place, it arrived yesterday, have a look at it below :

to_h in ruby 2.0

With few major changes ruby 2.0 is out today, out the many new features I really liked the to_h

We can convert a class to a Hash, using to_h:

    # Ruby 2.0:
    Student = Struct.new(:name, :age, :year) do
      def info
    dude = Student.new('Hemanth', '16', 2)
    dude.to_h # => {:name=>"Hemanth", :age=>"16", :year=>2}
    nil.to_h # => {}

P.S : This has been implemented for nilStruct and OpenStruct, but not for Enumerable/Array, so :

module Enumerable 
  # mapping array into a hash
  def to_h(&block)
    inject({}) {|hash, *v| block.call(hash, *v); hash}

After which we can use to_h on Array and other enumarations :

a = [:count, nil].to_h do |hash, value|
  hash[value] = 1 if value
# => {:count=>1}

P.S : I tired this by doing :  rvm install 2.0.0-p0 && rvm use ruby-2.0.0-p0 rvm++ :)

Do feel free to share you liking towards any other new feature.

Update 0 thanks to Hanmac :

Some fun to ** and to_h.

Person = Struct.new(:name,:age) do
alias to_hash to_h
p [Person.new("abc",30)].map {|**p| p }
# Would put : [{:name=>"abc", :age=>30}]

Filter elements by pattern jQuery.

The need was pretty simple : "Find the elements that contain a particular word and display them and hide others" Along with my friend Kambfhase we came with a simple hack to achieve this, well this in itself is very simple to be a jQuery plugin but can be a part of huger system.

Better HTML password fields for mobile ?

There is a particular issue that most of us would have noticed with few mobile devices in portrait with T9 (predictive_text) enabled : "To avoid prediction we have to use a lot of spaces and backspace".

Grayscale image when user offline

You must have noticed, webapps images in chrome going grayscale to indicate that the network is down, a simple demonstration of the same is been done here.

The trick is with very simple HTML5 event and CSS3 trick, sometime back had blogged about HTML5+JS offline/online notification on the same lines have done some silly code to emulate the offline gray-scaling of images, checkout the demo .

nth-child CSS pseudo-class Christmas colors

Lately /me noticed HN using Christmas color scheme for their post numbering, but the source sadly read <font color="#be2828">1.</font> below is some silly code emulating the same behavior without font tag indeed!

EventEmitter in nodejs

Sometime back had pawed at Making promises with javascript but node school of thought offers an attractive pattern of EventEmitters. 

EventEmitters are very much similar to PubSub, but is more tightly coupled and gives more control.

I shall try to demonstrate these EventEmiters with few simple code snippets.

Live reload with grunt

Sometime back I had published an entry on Node Packing with grunt but live reload has been so fascinating to most of the webdevs, it would be worth to make your own tiny server that reloads files as and when it gets edited.

Check out the video DEMO and then read the steps below:

Why parameter expansion in bash?

Most of us would have come across bash scripts that have the use of secondary commands for simple string manipulations, such as cut and awk , but wonders can be done with parameter expansion in bash at very effective and efficient manner.

Even before diving into the why parameter expansion it's a must to know how it works!

Node packing made easy with grunt

Publish node packages with npm is easier done than said! ;) First of all check out Hitchhikers guide to npm

After which, install grunt! npm install -g grunt and then the fun begins.

Making a promise with javascript

Chaining functions in javascript is fun, so is the understanding of Blaocking vs Non-Blocking code, but callback can soon end up in hell!

To save one from callback hell, normally named functions are preferred as save boats, but promises are more promising pattern!

Promises are not a new to the world of computer science, many JS frameworks have made promises for quite some time now, jQuery Deffered being one amongst them, taskjs is also very impressive.

CoffeeScript classes

When rails 3 was out I had a serious look at coffescript commit-diff but was not very much carried by it then.

But as the saying goes Real man code raw JS I always have great respect and love towards it, but the sugar and the kick this coffee is giving me is very high, especially with node.js

In this article I would like to express my <3 towards coffee classes.

Cluster computing with nodejs

A single instance of Node runs in a single thread. To take advantage of multi-core systems we may want to launch a cluster of Node processes to handle the load!

That is to say if a system has 8 cores in it a single instance of node would use only one core, but to make the most of it, we can make use of all the cores with the wonderful concept of workers and more interestingly they can share the same port!

This module is still in Stability: 1 - Experimental phase, check out the code below to enjoy the awesomeness of the cluster!

IRC notification bot with node.js

This bot is a product of a simple need of notifying people when their friends login to a particular channel.

The need :

  • Simple IRC bot, that would notify its master.

  • Easy to configure.

  • Easy maintainability.

The answer was to do it with node.js!

Heroku vs Nodejitsu for nodejs

It all started when I wanted to try out node with websockets with ws but strange but true heroku does not support node's ws but does support socket.io that internally use ws for it's client :\ Well heroku has been an old horse focusing on many programming languages.

Anyway on the other hand nodejitsu is Node.js clouds. Simple. Scalable. Enterprise-ready! Deploying apps here seem like you are working on localhost.

The below must give you a better picture of why Nodejitsu is a clear winner for nodejs!

Exposing your localhost to the Internet

Exposing your local web server to the internet is very useful at times, it gets a bit tough when you are on a DHCP.

The most common option being dynamic DNS and port forwarding with firewall turned off, yes it's a pain!

While exploring for alternatives came across showoff.io which is a paid service, digging more came across a suggestion from latentflip that being a wonderful gem called localtunnel there is another one called pairkit which is still in private beta.

Program dependency management with node.js

Lately was working with a few PRs for The Yeoman project and tried to hack through a shelljs script to audit the OS before installation.

P.S :  npm install shelljs as this is the dependency for this dependency management script :D

Perl in node.js

Yes! Perl5 can be embedded in node.js! First of all just do a npm install perl

P.S : node-perl requires a perl5 binary built with -fPIC and -Duseshrplib

This is synchronous but useful embedded Perl5 for node.js

If you want to try any version of perl, you must check out perl-node.

Temp dir with ruby

Played around with few programming languages to handle temp dirs, but amongst the lot /me really liked ruby's paradigm.

Mainly liked :

  • yield for the win!

  • Easy maintenance of code.

  • Temp dir removal is assured.

Get node details from Drupal

Currently I'm trying to migrate my blog from drupal to something must lighter, migrating data is indeed the first step!

A simple SQL statement was very useful to get the node details, which will be very useful in making a custom made CMS.

This is very tiny entry in my blog to remind me that the migration is still pending!

Convert any image to HTML5 canvas

Even before talking about the technicalities of converting an image to a canvas element, check out the demo!

DEMO input any image URL there and hit the convert button!

P.S : It also accepts data-uri!

HTML5 Fullscreen video crossbrowser

With the evolution of HTML5 APIs taking a video to Fullscreen and back is very easy and indeed no flash!

P.S : I shall be using webm for the demo, the below image and explanations must make things clear on why webm.


Chaining functions in Javascript

Most of us are aware of the all famous Jquery demo

which is a gem of an example of chaining functions.

There are many resources out their on which demonstrates various ways of chaining javascript function but, I always like to explore my own ways of doing things, let people call it re-inventing the wheel, but like doing that I like to make my own wheel! [ Enough of Nihilism! ]

Below is a simple code that /me managed to pull, which is closest to the Jquery demo and as always there might be better ways of doing the same, do let me know your way of doing this.

Remote debugging android browsers.

This entry briefs about remote debugging browsers that are active in any of the Android devices.

The focus is mainly on the three major mobile browsers :

  • Opera.

  • FireFox.

  • Chrome.

Control telephone calls from the browser!

Control telephone calls from the browser, yes browser! But Mozilla Mobile Browser as of now.

The phone functionality can be used with the help of  navigator.mozTelephony, which is part of the WebTelephony API.

P.S : This is a nonstandard API and is subjected to change and works only with Firefox Mobile (Gecko) 12.

FFI Python vs Ruby

Lately wrote about Python vs Ruby Singelton, this is a similar write up that is crips and talks about FFI in both of them.

FFI foreign function interface :

A foreign function interface (FFI) is a mechanism by which a program written in one programming language can call routines or make use of services written in another. Despite the name, FFIs are not necessarily restricted to function calls; many FFIs permit method calls on objects; and some even permit migration of non-trivial datatypes and/or objects across the language boundary.

Python vs Ruby Singleton

I had dug a bit into Singleton Pattern in JavaScript lately and also was playing with some Python and Ruby Singleton Design pattern and asstonisginly they are very simple and one can enjoy reading the code, as so little code helps one to implement this pattern.