Post-Rice Haze
Devin Naquin
Recent Rice alum. Living and coding.
A lot of people have used The Cure’s “Close to Me”, Diplo included. NME gives a rundown, but uses a terrible Diplo example.
Now Lady Sovereign’s thrown her two cents in with her new single. I like. Plus it’ll give me good material for Lady Sovereign/Diplo/The Cure extended transitions.
For some reason, I followed Barack’s senate race in 2004. Though living in Texas and being from New Orleans meant it was of little relevance to me.
The gem that came out of the race was this little track. When Barack started running for president, I kept wishing I could find this track, but it had gotten lost somewhere deep in my hard drive. Well. I found it.
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 haven’t figured out why, but I wanted to get the code I was working on done before figuring out why this query was slow, so I hacked around it.
So, of course, I could just convert that QuerySet to a list and index the list with:
link = list(forum.link_set.order_by('-id'))[0]
But that would load the entire result into memory. My results could potentially be extremely large, so I didn’t want to go down that route.
So I wrote the obvious solution, using the iterator, but only saving the first result. Which turned out to be one of the worst lines of code I’ve ever written.
In all it’s glory:
for link in forum.link_set.order_by('-id'):
break
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?
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 elegant.
Whitney and I picked up a stray kitten a little while back. My first real pet.