hemanth's blog
Tweaking Command Not Found
1 Jan 2012
Most of the time in ubuntu, when we come across the message like :
The program 'program_name' is currently not installed. You can install it by typing:
sudo apt-get install program_name
We would end-up doing "sudo apt-get install program_name" and installing it.
This repeats so why not automate the same? Solving this question, I had to do the below :
Bash shell has a hook called command_not_found_handle
command_not_found_handle ()
Getting server info using nodejs
29 Dec 2011
Getting server information using nodejs is very easy especially using the os module.
Wrote a simple script to fetch hostname, loadavg, uptime, freemem, totalmem, cpus, type, release, networkInterfaces, arch, platform, getNetworkInterfaces from the server where the node is running.
Below is the code to get the server info using nodejs :
HTTP-request header from node.js
23 Dec 2011
The message header of requests and responses in the Hypertext Transfer Protocol define the operating parameters of an HTTP transaction.
Say if you want to do a language detection in the browser : One must be aware that browser settings don't actually affect the navigator.language property that is obtained via javascript, but they do affect is the HTTP 'Accept-Language' header, but this value is not available through javascript at all!
So we need some server side help, why not use javascript itself on the server side?
Unicode symbols as function names
1 Dec 2011
Unicode stings for function/method names is a very rare scenario, but who knows in the near future people might use them daily! [ Too much of an expectation aye? ;) ]
Say : one needs to convert dollars to pounds and writes a method to do so, might name it "dollar2pound", but a code monkey might name it $2£
Below is the result of such a play in few of my favorite programming languages :
To makes things silly/simple, lets assume our methods takes an integer argument and prints ❤'s those many time.
Invalid HTML in Google's homepage
19 Nov 2011
When validating my homepage /me got 1Error and 1warning, was curious to paw more!
w3.org validator says : 37 Errors, 2 warning(s) on validation of google.com!
Edit 1 : It says : 39 Errors, 2 warning(s)
/me loves reading obfuscated code, with javascript in view on of the most obfuscated code can be found in the source pages of google pages, may it be gmail, g+ or even their 404 page! It's fun reading it.
Simple closure for cross browser XHR instance
14 Nov 2011
Yes that is right, there are many libraries to handle XHR, but raw JS is always fun!
There are many ways of doing this, but here is a unique way of getting an XHR instance.
A simple closure, that tries to create a simple XHR instance :
typeof JavaScript tweaked
8 Nov 2011
Most of the programming critters pawing at JavaScript would have used the typeof operator that returns a string indicating the type of the unevaluated operand.
But the well know confusing with typeof, is the string it returns!
- typeof [] => "object"
- typeof {} => "object"
- typeof null => "object"
The below is a simple, but very effective tweak for the typeof operator
JavaScript Event tracking and management
7 Nov 2011
Events play a major role in all most all the JavaScript libraries. Experimenting on the same lines, coded a simple prototype with raw JavaScript to make the basic event management and tracking easier and names it event.js.
So what does event.js do?
- Add events to DOM elements. [Cross-Browser support]
- Get the event type for the particular DOM element.
- Remove a single or all events.
Simple Cookie Management with JavaScript
25 Oct 2011
On of the most common things that most of the web developer would do is cookie management.
Was pawing at some JavaScript and made a simple cookie management class in JavaScript that does basic cookie management like :
- setCookie
- getCookie
- removeCookie
- getAll
- removeAll
Okies, so now enough of talking here is the silly code :
Introducing the slang API
24 Oct 2011
Lately was working on some slang filtering module, but for the LOLz of it made a simple JSON API.
The deal is pretty simple, the API takes in an SMS slang word and expands the acronym.
So, here is a simple jQuery code to get results :
RSS