Programming

The five programming books that meant most to me

As seems to be the done thing on the internets this holiday season, here’s my list. The C++ Programming Language: This was one of the first programming books I ever read. It taught me what C/++ programs look like, how to write a basic parser, basic object-oriented programming, the difference between stack and heap allocation, […]

Posted in | | Leave a response

Twitter is my randomness entropy

Inspired by Henry’s Facebook comment. import urllib2, hashlib TWITTER = ‘http://twitter.com/statuses/public_timeline.json’ def hashed(seq): sha1 = hashlib.sha1() for x in seq: sha1.update(x) yield sha1.digest() def words(wordsize, seq): for x in seq: for i in xrange(0, len(x), wordsize): yield int(x[i:(wordsize + i)].encode(‘hex’), 16) def twitrandoms(wordsize = 4, chunksize = 37): def infinite_twitrandom(): while True: data = urllib2.urlopen(TWITTER).read() […]

Posted in , | | Leave a response

Help me write idiomatically correct Python

Why can’t the features I like from every programming language be available all the time? It really bugs me that, for instance, I can’t get lazy lists and patter matching in Python and I can’t get, well, there’s got to be something that Python has that’s sort of a pain in Haskell. I/O, for example. […]

Posted in | | 9 Responses

One-liner syndrom

Jeff Atwood talks about card shuffling algorithms in a recent blog post. As it turns out, the easiest way to implement a shuffle is by sorting. It’s not exactly faster, as the typical sort is O(n log n) compared to the O(n) of the Knuth Fisher-Yates shuffle algorithm. We’ll just sort by a random number– […]

Posted in , | | Leave a response

Synchronous HTTP GET in JavaScript

Taking the “A” out of “AJAX.” function get(url) { var ajax = new XMLHttpRequest(); ajax.open(‘GET’, url, false); ajax.send(null); return ajax.responseText; } Of course this will be different for IE….

Posted in | | Leave a response

Roman Numeral Parser

I wondered the other night how straightforward a task parsing roman numerals (up to 4999) is. As revealed by about 30 seconds of Googling: pretty straightforward. Here it is in Python: import re ROMAN_RE = re.compile(“”” ^ # beginning of string (M{0,4}) # thousands – 0 to 4 M’s (CM|CD|D?C{0,3}) # hundreds – 900 (CM), […]

Posted in | | 2 Responses

Pleasing small victories

So a coworker got me hooked on Project Euler today, and I’ve been spending far too much of my free time on it. However, it did lead to a very pleasing moment. One of the problems deals with Collatz sequences: For any number, divide by two if the number is evenly divisible by two, multiply […]

Posted in , | | Leave a response

An ode to Python 3000

Inspired by the what’s new page: def reduce(f, seq, val = None): if val is None: val = next(seq) for x in seq: val = f(val, x) return val

Posted in | | Leave a response

Java programmers are funny

Having dealt with code of the ObjectModelAdapterFactoryBuilderInterfaceFacade variety before, I of course find Stevey’s comments about Java to be spot on. Sun Microsystems Demands University Study Retraction The University of Washington, apparently hoping to capitalize on the recent hype around their controversial study on Baby Einsteinâ„¢-style videos, followed up yesterday with another, similar study. In […]

Posted in | | Leave a response

Haskell Unit Tests with HUnit

I read an OnLamp article today called A Beautiful Regex Matcher… In Haskell. Interesting little piece of code, but there was a (silly little) bug in it. This struck me as a fine opportunity to figure out how HUnit — one of Haskell’s unit testing frameworks — works. Here’s what I came up with: import […]

Posted in , | | Leave a response