Archive for the 'Rants' Category
Misconceptioned Memcached

You’ve heard of memcached, haven’t you?
Made by Livejournal to sustain millions of angst-ridden teen diaries, now used by web giants like Slashdot, Digg, Wikipedia, Facebook, Youtube, and countless more. Even this very Wordpress blog supports it.
The same misconception seems to haunt all those unfamiliar with the memcached: it’s some sort of magical layer that sits between your database and your application layer, and somehow it makes things faster. The magic is scary. How would something know what it needs to speed up from the database? It must require all sorts of nasty configuration, all sorts of nasty corner cases to cover?
Admit it. The thought of using memcached terrifies you. Well, I have good news for you: That’s not what memcached is. Are you read for it?
Memcached is a hash table.
No, seriously. It’s that simple. It’s a hash table that sits in memory, that can scale between multiple servers. All you do is launch the memcached daemon on your server with memcachedand you can use it!
“Well obviously that’s not all there is…” you say. It is! As far as the server is concerned, that’s all the configuration it needs.
Now, the client side…
How does the hash table work? It’s just like a dictionary. To save data: you send it a key/value pair, and it saves it. To retrieve data: you send it a key, and it gives you the value. Explicit. Simple. Efficient. It supports a handful of simple operations like set, get, and replace.
Here’s how to use 3 distributed memcached servers to cache a huge query in Python:
import memcache ... cache = memcache.Client(['192.168.1.100:11211', '192.168.1.101:11211', '192.168.1.102:11211']) ... def get_post(post_id): "Return data associated with post with given post_id" result = cache.get(post_id) if not result: # No cache, perform potentially costly SQL query result = model.Post.get_post(post_id) # Save result in cache for next time cache.set(post_id, result) return result
Do you see what they did there?
Yes, it’s not magic. Yes, you have to cache things explicitly. Yes, this is incredibly powerful. Now go. Go make a Slashdotting-proof web service, that’ll show them.
1 commentGentoo, Rockband, Code, and Music

Today, you’ll get to hear about what I’ve been up to! This wont be on the exam.
- After a year and a half stint with Ubuntu, I’m back to my true love Gentoo. That is, with a
shinymatte new quad core beast of a machine. - Bought Rockband for my PS3 couple of weeks ago. Drums are ridiculously hard. Been rocking out. Good fun is being had by all those who dare rock. Can’t wait for Still Alive to be released for free. It shall be a triumph!
- What started out as pretty code is now a bonafide open source Python module: workerpool. People are using it. No, really.
- muxtape.com: A super simple music sharing web app launched last week. Its been enriching my life — doing what Pandora once did. Here’s my muxtape. Be right back, there’s someone at the door.
Blu-ray, scientology, and J. J. Abrams
- Sony’s Blu-ray beat out Microsoft’s HD-DVD in the hi-def wars. Sony stock is going up. Microsoft stock not so much, especially with the recent bid at Yahoo.
- Scientology is now censoring eBay, as its has been permitted to arbitrarily delete auctions. Boycott time?
- J.J. Abrams, an ex-Scientologist and producer of Lost and Cloverfield, announced a Cloverfield sequal.
- In other Abrams news, Fringe (X-Files on drugs?) is being filmed in Toronto (UofT’s Bahen building, to be precise) as I write this. I dropped by today and saw an enormous FBI seal plastered on the lobby floor. Also, Great Hall has been revamped into an FBI HQ with suited agents running around. Very exciting.
- Bonus fun item: I learned that Naveen Andrews (Sayid from Lost) has a fetish for older women. He fathered a child with his math teacher at the age of 16, and is currently dating Barbara Hershey who is a solid 21 years older.
Politics, photoshop, and Kanye
-
The Black Eyed Peas’ will.i.am released an inspirational music video remixing Barack Obama’s “Yes We Can” speech.
The remix features various people singing and reciting parts of the speech.
The only non-English lyrics are Hebrew. Just saying.Nevermind, spotted some sign language, Spanish, and possibly some Asian dialect I can’t really hear over the music. - There’s a collection of videos called “you suck at photoshop“. They’re both educational and amusing. Very well done.
- Did you know Kanye West has a blog? Yes, I know Britney Spears has a blog too, but Kanye actually posts interesting things.
Code storytelling
It’s fun writing code that tells a story. Hopefully it’s also fun reading it.
class TerminationNotice(Exception): "Exception raised inside a thread when it's time for it to die." pass class SuicideJob(QueryJob): "A worker receiving this job will commit suicide." def run(self): raise TerminationNotice() class QueryWorker(Thread): "Devoted worker who will pull jobs from the `jobs` queue and perform them." def __init__(self, jobs): self.jobs = jobs Thread.__init__(self) def run(self): "Get jobs from the queue and perform them." while 1: job = self.jobs.get() if not isinstance(job, QueryJob): debug.error("%r ate a job that wasn't a edible: %r" % (self, job)) continue try: job.run() except TerminationNotice: # Nice knowing you :( break
Around the world *techno beats*
Excuse my lack of updates for September. It was a month monopolized by being on trips and recuperating from trips, and then going on more trips.
In early September, I ventured to the steady-weathered California and visited San Francisco with a side dish of Mountain View. Free Google food was had by all, as well as fun. This trip was well-documented on Facebook with plenty of incriminating, yet inspiring, photos and videos.
As I write this, I am in Italy. I departed on Sept. 30th, and so far I’ve lodged in Venice, Florence, and Rome. I’ve also spent enjoyable hours in Milan, Siena, Pisa, Pompei, and Naples for pit stops, wine tastings, and guided tours.
Many pictures were taken and further documentation will be presented on this here blog upon my arrival to my beloved Toronto. I miss you, Toronto. I miss your delicious food with reasonable prices and free washrooms. I miss being huddled by immigrants — at least they usually shower (unlike the throngs of tourists here). When I get back, I’m going to go out and hug somebody.
For now, you may indulge in this lolpigeon:

Silent but lethally awesome
I went to the Metropolis showing at Dundas Square on Tuesday.
Metropolis is a silent film from 1927. The showing was accompanied with the beautiful live Trip Hop beats DJ’ing of Andrew McPherson.
I’ve never seen a silent film before, but it was absolutely amazing. The acting was passionate and expressive, despite not having a lot of dialogue (some dialogue was narrated in captions, but not much). The music was a perfect addition to it. It’s a whole new genre opened up to me, and I highly recommend it to anyone else.
No comments


