March 2010
1 post
JavaScript Inheritance
JavaScript inheritance can be done dozens of different ways. One of the major plusses of the language is that it’s flexible enough to allow many possible paradigms. However, this also turns into a major language detractor, since everyone does it just a little differently. Here are a couple and some reasons I lean one way most of the time.
First, there’s a functional pattern. I...
February 2010
1 post
Shoes
Nelly’s “Air Force Ones” is a classic. I remember riding around in the car in high school surfing radio stations in the attempt to always have “Air Force Ones” playing. It was ridiculous how long we could actually keep this up.
Since “My Adidas” was released by Run DMC in 1986, shoes have been a classic trope in hip hop, but nothing takes it to...
November 2009
1 post
Dead Simple Concurrency with Clojure
Concurrency is hard. In an environment where processors don’t get faster, we just get more of them, concurrency is going to get more important. We’ll take these as givens.
Enter Clojure. Promising a vast array of interesting features promising to make concurrency easier.
So in my attempts to learn the language, my goal was to get something running concurrently as quickly as possible....
September 2009
1 post
Really Liking Ruby
class Node
def initialize(label, left, right)
@label = label
@left = left
@right = right
end
attr_accessor :label, :left, :right
def breadth_first unvisited = [self]
while not unvisited.empty?
node = unvisited.shift
yield node
unvisited << node.left if node.left
unvisited << node.right if node.right
end
end
end
August 2009
2 posts
Migrated west until I hit an ocean. From the bayou to Houston to Austin. Skipped the desert and hit a beach. Cold as all hell up the foothills. I-10 always the closest thing to a home I had. Until I ran out of mile markers and there’s only east to go.
People. This is me again. I hate to cut things down like this. But, uh....
– Bill Graham at Monterrey Pop during the Grateful Dead’s set.
July 2009
1 post
Jurassic Park
MALCOLM The problem with scientific power you’ve used is it didn’t require any discipline to attain it. You read what others had done and you took the next step. You didn’t earn the knowledge yourselves, so you didn’t take the responsibility for it. You stood on the shoulders of geniuses to accomplish something as fast as you could, and before you knew what you had, you...
April 2009
1 post
…that inside this building is the president, and not just any...
– Dave Eggers about Clinton circa 1994 in A Heartbreaking work of Staggering Genius.
March 2009
4 posts
I need to see what’s inside that box. If I learned anything from 24,...
– 30 Rock, “Apollo, Apollo”
Worst Line of Code and Why
I needed to grab the latest Link object for a certain Forum from Django’s ORM.
Normally, I’d do this with:
link = forum.link_set.order_by('-id')[0]
But for some reason, adding the slice (which adds a limit to the SQL query), was considerably slowing down the call. Whereas, just getting the iterator was fine.
link_qs = forum.link_set.order_by('-id')
Which is disturbing. I...
February 2009
2 posts
Trust me, they don’t apply to your app. If in doubt, explain your use case...
– Python is not Java
i've lost it
i grew up. learned how to take care of myself. buy beer. car insurance.
and suddenly the words don’t pretty. oh! forgot the insomnia of restless sparkling girls’ eyes from across the bar. two sets at a time.
oh!
suddenly midnights are: consumption. alcohol. television. transportation. oh!
nothing geography can’t solve?
January 2009
1 post
Elegant Fibonacci Iterator
After a bunch of versions of Fibonacci functions months back, the following iterator appeared in my notebook.
def fib():
future = [0, 1]
while True:
future.append(sum(future))
yield future.pop(0)
Though of no particular engineering marvel. It is, at O(n), slower than the best case O(log(n)) I can do using matrix multiplication of powers of two.
I find it particularly...
December 2008
3 posts
Numbers that fool the Fermat test are called Carmichael numbers, and little is...
– footnote pg. 53 SICP
Mocking with Python
After recent conversations about the surgery I did to the DISQUS IMAP processing code in order to make it testable, I was steered toward Python mock modules. Of which there are a lot.
So I installed the python-mock module and coded up a quick example use case.
Often when writing unit tests, you stumble upon dependencies that the code you’re testing uses, but are orthogonal to the actual...
November 2008
1 post
1 tag
Tackling JavaScript
Lately, I’ve been looking at JavaScript a little differently. Instead of writing JavaScript as dirty hacks to do DOM manipulation, handle JavaScript as a first-class language in itself and write elegant code to do DOM manipulation. Something I should have been doing all along. Toward that goal, I tackled a little project to exercise writing elegant JavaScript code.
At least until I can have...
August 2008
9 posts
Juicy
I always rap on and on about how hip-hop is the natural extension of postmodernism, but rarely offer up much on the subject. In an effort to start getting some of it on paper, I’m going to start tackling the topic here.
Saturday I went down to Mountain View for Rock the Bells. Mostly for Dead Prez. After their set, I get into the postmodernism speil with April, a poet herself, when a golden...
Grabbing a Site's Favicon
Grabbing a site’s favicon from Python code is slightly complicated by support of the standard
<link rel="icon" type="image/png" href="/path/image.png"/>
and the older favicon.ico in the server’s root director. But parsing a site’s html using Python’s sgmllib is easy enough.
import sgmllib
def get_favicon_url(url):
"""
Get the favicon used for site at url.
...
How I Got My Summer Internship
It was late in the game when I got accepted to UT Graduate School. A lateness I attribute to every other applicant being much more interesting than me but ultimately deciding to instead go on and do something completely amazing.
So I had a week to decide, and everyone had already hired interns. Even my inside contacts couldn’t change that the hiring had already been done. So I resigned...
Optimizing Swample
There was one big lesson I learned about software development that I picked up in a Algorithms and Data Structures class at Rice. When implementing a large application, get something working first, then add features one at a time. In that vein, I got swample working and online quickly. But soon thereafter, I focused on optimization.
As I touched on last time, from the beginning I wanted to...
Launching Swample
The best advice that’s post-it noted to my monitor is “patience/do it now!”. I lean left or right depending on context. It’s been a lean right couple of weeks. It’s better to do something and be making progress than have a great idea. A step forward is a step forward.
So this past week, I wrote and launched Swample. It’s something Richard and I had been talking...
Post-Fix Definitions
The last line of my last post bothered me from the time I wrote it.
However, the real lesson is that I should have just posted the sketch. The desire for perfection is useless.
Not that I don’t agree with it, I do. I just couldn’t precisely define what I actually meant by it.
Mathematics is a field where perfection is everything. So it bothered me that I could say that the desire for...
Science Next to Art or A Theorem Deferred
I was writing some code last week to compute the period of the continued fraction expansion of the square root of the natural numbers. When I needed a condition to know when the repetition started to end my recursion. There’s a natural point when double the leading term appears that pops up in the tables.
√2 = [1; 2]
√7 = [2; 1, 1, 1, 4]
√97 = [9; 1, 5, 1, 1, 1, 1, 1, 1, 5, 1, 18]
But...
Black Marble Composition Notebooks or Life Without...
For the last couple years of my time at Rice I kept all my class notes in one black marble bound composition notebook. Spring 2005. Fall 2005. Every class in the same book marked off. English notes on post-modern novels next to frantically scribbled “Let ∂>0.” next to the next little snippet of my next short story.
When I graduated I intended on keeping the same composition...