Posts tagged with "programming"

Writing applications versus frameworks

February 22nd, 2012

At work, since I mostly write web applications I usually end up consuming frameworks rather than writing them. So, I have been reading a lot of framework-ish code on GitHub lately, and it has turned out to be an awesome source for finding clever tricks, patterns and coding conventions. Writing frameworks requires a slightly different [...]


First element of an object in JavaScript

January 17th, 2012

This one will go into the bag of clever hacks which you should use sparingly, if not ever. Given an object like this: var obj = { a: "foo", b: "bar", c: "baz" } Here’s how we get the “first” property of the object/dict: for (var first in obj) break; console.log("First property is: "+first); We’re [...]


ECMAScript harmony features in Chrome Canary

December 26th, 2011

The latest Canary build of Google Chrome allows you to unlock some new features from ECMAScript Harmony. However, they are disabled by default, so to enable them you have to type about:flags into your address bar, and turn on “Enable Experimental JavaScript” which is found right at the bottom of the page. Now, you have [...]


Abusing Scala’s anonymous argument

December 7th, 2011

In Scala, you can use the underscore (_) to refer to an argument you are lazy to name. val numbers = List(1,2,3,4) numbers.map(2 * _) // List(2, 4, 6, 8) You can go a step further. val numbers = List(1,2,3,4) numbers.map(2*) You can completely omit the _ as well, because * is actually a method [...]


Printing colors in the terminal

December 5th, 2011

If you fancy adding a bit of color to your console print statements, you can do that by using the ANSI escape sequences. Pasting the following in a Python console (Linux/Mac) will get you some green text! print "\033[0;32mGREEN TEXT\033[0m" Although that looks gibberish, the format can be broken down like this: START_SEQx;y;zmDISPLAY_TEXTEND_SEQ Starting sequence: [...]