I am Hack Sparrow
Captain of the Internets.

Archive for July, 2011

How to install Node.js on Webfaction

I just got Node.js running on my Webfaction account :) Installation was pretty straightforward and Node completely blew my mind. The greatness of Node.js deserves a post of its own; we will get there another day, for now let's install Node.js on your Webfaction account. Even though Node.js is currently not in Webfaction's App list, installing and getting it running was a breeze, so worry not if you wanna install Node.js on y ...

Python: length or size of list, tuple, array

Let me clarify something at the beginning, by array, you probably mean list in Python. list is the equivalent of arrays in JavaScript or PHP. Arrays in Python is an altogether different thing. Ok, having cleared that, getting the the size of a list or tuple (or array, if you will), is pretty straighforward. You just call the l ...

Python: difference between list and tuple

To put it lightly, tuples are lists which can't be edited. Once you create a tuple, you cannot edit it, it is immutable. Lists on the other hand are mutable, you can edit them, they work like the array object in JavaScript or PHP. You can add items, delete items from a list; but you can't do that to a tuple, tuples have a fixed size. Here is an example demonstrating the mutable nature of lists in Python. [code] >>> anima ...

Python: split string method and examples

So you are looking to break up a string into smaller strings (in an array if you are coming from a PHP / JavaScript background) based on a delimiter or character. Python provides a very straightforward and easy function to do that. The function is called split, it returns a list as the result (you really don't want to a Python array for this one) and here are some examples. Examples 1 to 3 are to be tri ...

Python: check if a character or substring is in a string

Let me start with a little history about myself. I have been developing on the Web for more than five years now - in PHP. Yes, in goddamn PHP! I had been exposed to Python much earlier, but for some strange reason I never made the effort to learn it or use it. If I had learnt Python earlier, I wouldn't be struggling to to check if a substring exists in a string or not today. On the brighter side, I realize what a beauti ...