I am Hack Sparrow
Captain of the Internets.

Archive for April, 2012

Base64 Encoding / Decoding in Node.js

So how do you encode a string to base64 is Node.js? Is there something easy like base64_encode() of PHP's? Node.js 'being' JavaScript, has a more logical approach to encoding strings, instead of having thousands of inconsistently defined global functions. Here is how you encode normal text to base64 in Node.js: [code] var b = new Buffer('JavaScript'); var s = b.toString('base64'); // SmF2YVNjcmlwdA== [/code] And here is how you decode base64 encoded strings: [code ...

How to Generate md5, sha1, sha512, sha256 Checksum Hashes in Node.js

Checksums in Node.js are generated using the crypto library's createHash() method. The usage format is this: [code] crypto.createHash(algo) [/code] Where algo is the algorithm of your choice - md5, sha1, sha512, sha256 etc. The algorithms supported are entirely dependent on the OpenSSL version on your machine. Here are some examples of generating hashes for string inputs: [code] var crypto = require('crypto'); var md5 = crypto.createHash(' ...

Node.js compilation error on Ubuntu – Install using apt-get

This post this written for people who will encounter this mysterious Node.js compilation error. [code] *** glibc detected *** /usr/lib/gcc/i686-linux-gnu/4.6.1/cc1plus: malloc(): smallbin double linked list corrupted: 0x0a4a0eb8 *** ... /home/$USER/Downloads/node-v0.6.15/deps/v8/src/ia32/lithium-ia32.cc: In member function 'int v8::internal::HTemplateInstruction::OperandCount() [with int V = 2]': /home/$USER/Downloads/node-v0.6.15/deps/v8/src/ia32/lithium-ia32.cc:2265:3: internal compi ...

Install Memcached on Mac OS X

There are two ways to install memcached on Mac OS X. One is the easy way, the other is the harder but more flexible way. Installing memcached using brew is the easy way, and it is just a matter of a single command. [code] $ brew install memcached [/code] There you have memcached installed on your Mac! ...

Make Forever.js Reboot-Proof with Cron

Some time ago, I wrote a post on keeping Node.js apps running even after logging out from the shell. It was cool and all, but soon you will soon realize that Forever alone is not enough. Because, on system reboots, Forever itself is killed. Who will restart your app now? There are many options for handling this kind of scenario, but today we wi ...