Archive for May, 2007

A clever workaround to Apple’s userdata-laden media files.

Thursday, May 31st, 2007

Apparently Apple is putting your account information in the DRM-free media files it sells. I’ve come up with a clever solution to this problem: don’t put the files on file-sharing sites. That way, your personal data can never get out. Easy! I’m relatively certain that your off-brand media player or TiVo or whatever you end up feeding these files in to (hooray for being able to feed the files in to whatever you want) won’t sell your email address to spammers. (And if you’re really paranoid, convert the m4a/aac files to mp3 and be done with it.)

Because I’m secretly the Lakers’ general manager

Wednesday, May 30th, 2007

So Kobe asked for a trade. No big surprise, nor will it be when the Lakers basically get nothing in return. If I may be so bold, I recommend that the front office gun for a deal with Chicago, trading Kobe for Luol Deng, Kirk Hinrich and PJ Brown’s expiring contract. The money works, and Chicago is pretty much the only team in the league that wants to and can legitimately content for the title next year (which makes Bryant appealing to them) and has plenty of talented younger players (which the Lakers should go for if they’re going to rebuild.) Next year after they can dump Kwame Brown’s contract, LA will only have Lamar Odom and Vlad Radmanovic on the payroll as big-ticket, perennially broken players. Which, for the Lakers at least, would be braggable.

I personally think Chicago would be foolish to go for this, but who knows. They gave Ben Wallace a $60,000,000 deal, so it definitely seems like they’re swinging for the fences. Maybe Kobe could be the guy to get them over the hump? They could even break the bank and try to pull Jermaine O’Neal (who has a player option with the Pacers for next year) on to the team as well. I personally wouldn’t want to be in the Eastern conference should that happen.

At any rate: I’m just saying. Now back to your regularly scheduled nerdery.

Because nobody should ever have a case of the Mondays on a Tuesday

Tuesday, May 29th, 2007

Youtube videos of live folk covers of antiquated rap anthems is clearly what Al Gore created the internets for.

Using Parsec in simple Haskell programs

Saturday, May 26th, 2007

I read two very useful articles about Haskell recently. First is Haskell IO for Imperative Programmers which explains how to do simple IO. (It’s less obvious than you’d think, especially if you’re coming from one of the more popular languages like Java or Ruby.) The second is called JSON Parser in Haskell. It covers in a brief yet very informative way the exceptionally useful Parsec library that ships with many Haskell implementations.

Each of these articles are incredibly useful. You have to know how to get data in and out of your program, and there aren’t a lot of tasks that don’t require parsing data. The two techniques together, as you might expect, are crazy useful.

To summarize perhaps too quickly, you can do simple stdin/stdout IO using the “interact” function. Here’s the Haskell implementation of the popular “tac” utility:

main = interact $ unlines . (map reverse) . lines

The “lines” method turns a large string (stdin) in to a list of strings, “unlines” turns a list of strings in to one large string (stdout), “interact” ties the whole process together, and “(map reverse)” is where you would put your code.

In place of “lines” you can usefully drop Parsec in such that you can work directly on data structures instead of fussing with lines of text. (Haskell isn’t Perl, after all.) Here’s a quick example that reads pairs of integers:

module Main where
import Text.Printf
import Text.ParserCombinators.Parsec

atoi :: String -> Int
atoi = read

intsList :: Parser [(Int,Int)]
intsList = do
  intsList' <|> (eof >> return [])
      where intsList' = do
              a <- many1 digit
              many1 space
              b <- many1 digit
              newline
              r <- ( many space >> (intsList' <|> return []))
              return ((atoi a, atoi b) : r)

parseInput :: String -> [(Int,Int)]
parseInput s = case parse intsList "stdin" s of
                 Left err -> []
                 Right cs -> cs

rpt :: (Int,Int) -> String
rpt (a,b) = let c = maximum $ map ( length . cyc ) [a..b]
            in printf "%d %d %d" a b c
    where cyc n | 1 == n       = [1]
                | 1 == mod n 2 = n : cyc (1 + 3 * n)
                | otherwise    = n : cyc  (div n 2)

main = interact $ unlines . (map rpt) . parseInput

And just like that you can move input parsing in to a parser where it belongs and not worry about it in the rest of your system. Certainly a lot more work than the same thing in, for instance, Ruby:

STDIN.each { |l| a,b = l.split.map {|x| x.to_i} ; puts whatever(a, b) }

However, dropping Parsec works the same way for arbitrarily complex data structures. This same code structure workspairs of integers, HTTP, JSON, whatever. Needless to say, I find this very pleasing.

Happy Birthday, Bob

Thursday, May 24th, 2007
Darkness at the break of noon
Shadows even the silver spoon
The handmade blade, the child's balloon
Eclipses both the sun and moon
To understand you know too soon
There is no sense in trying.

Pointed threats, they bluff with scorn
Suicide remarks are torn
From the fool's gold mouthpiece
The hollow horn plays wasted words
Proves to warn
That he not busy being born
Is busy dying.

Temptation's page flies out the door
You follow, find yourself at war
Watch waterfalls of pity roar
You feel to moan but unlike before
You discover
That you'd just be
One more person crying.

So don't fear if you hear
A foreign sound to your ear
It’s alright, Ma, I’m only sighing.

As some warn victory, some downfall
Private reasons great or small
Can be seen in the eyes of those that call
To make all that should be killed to crawl
While others say don’t hate nothing at all
Except hatred.

Disillusioned words like bullets bark
As human gods aim for their mark
Made everything from toy guns that spark
To flesh-colored Christs that glow in the dark
It’s easy to see without looking too far
That not much
Is really sacred.

While preachers preach of evil fates
Teachers teach that knowledge waits
Can lead to hundred-dollar plates
Goodness hides behind its gates
But even the president of the United States
Sometimes must have
To stand naked.

An’ though the rules of the road have been lodged
It’s only people’s games that you got to dodge
And it’s alright, Ma, I can make it.

Advertising signs that con you
Into thinking you’re the one
That can do what’s never been done
That can win what’s never been won
Meantime life outside goes on
All around you.

You lose yourself, you reappear
You suddenly find you got nothing to fear
Alone you stand with nobody near
When a trembling distant voice, unclear
Startles your sleeping ears to hear
That somebody thinks
They really found you.

A question in your nerves is lit
Yet you know there is no answer fit to satisfy
Insure you not to quit
To keep it in your mind and not fergit
That it is not he or she or them or it
That you belong to.

Although the masters make the rules
For the wise men and the fools
I got nothing, Ma, to live up to.

For them that must obey authority
That they do not respect in any degree
Who despise their jobs, their destinies
Speak jealously of them that are free
Cultivate their flowers to be
Nothing more than something
They invest in.

While some on principles baptized
To strict party platform ties
Social clubs in drag disguise
Outsiders they can freely criticize
Tell nothing except who to idolize
And then say God bless him.

While one who sings with his tongue on fire
Gargles in the rat race choir
Bent out of shape from society’s pliers
Cares not to come up any higher
But rather get you down in the hole
That he’s in.

But I mean no harm nor put fault
On anyone that lives in a vault
But it’s alright, Ma, if I can’t please him.

Old lady judges watch people in pairs
Limited in sex, they dare
To push fake morals, insult and stare
While money doesn’t talk, it swears
Obscenity, who really cares
Propaganda, all is phony.

While them that defend what they cannot see
With a killer’s pride, security
It blows the minds most bitterly
For them that think death’s honesty
Won’t fall upon them naturally
Life sometimes
Must get lonely.

My eyes collide head-on with stuffed graveyards
False gods, I scuff
At pettiness which plays so rough
Walk upside-down inside handcuffs
Kick my legs to crash it off
Say okay, I have had enough
What else can you show me?

And if my thought-dreams could be seen
They’d probably put my head in a guillotine
But it’s alright, Ma, it’s life, and life only.

Dave Thomas on Paying Back

Tuesday, May 22nd, 2007

Dave Thomas has a fine idea for improving conferences by adding a focus on charitable giving:

Just imagine the difference we could make if, as an industry, we turned each of these conferences into a chance to raise much needed money for worthy charities. Imagine if, rather than getting yet one more burlap bag with a sponsor’s name on it, you instead got a slip of paper saying that the price of that bag was being used to buy vaccine for 5 kids, or a book for a literacy project. Imagine what could happen if a conference with 5,000 attendees raised just $20 per attendee. Then imagine $50, or $100. It starts to get serious.

As somebody who falls squarely in to the “I’m not going to use your Complete Enterprise Solution even if you give me a tote bag and a glow-in-the-dark yo-yo” camp, I think this is a great idea. Nobody needs another Sun-branded pen or Google Frisbee; there are lots of people out there who could make good use of a nerd’s pocket change.

Things to do when you’re a nerd and you can’t type

Sunday, May 20th, 2007

I spent Thursday and Friday at work essentially without fingers. Well, I had fingers, but only one useful hand of them. Interestingly enough, I learned that I’m at least in the short term incapable of hunt-and-peck typing. Finger muscle memory takes over when I try and everything goes all crazy-go-nuts. Not a good time.

My original plan for my convalescence was to go charge a book on JavaScript to the company account and see if I couldn’t learn a bit about a language that I’m likely going to use for an upcoming project. However I don’t know what the good JavaScript books are, and walking to the book store is a lot more work than surfing the internet, so I checked for good online resources.

It turns out that there are many. In particular, Yahoo!’s YUI team has put together large collection of videos about JavaScript. I watched videos of three of Douglas Crockford’s lectures: “The JavaScript Programming Language,” “An Inconvenient API: The Theory of the DOM” and “Advanced JavaScript.” All three were good lectures. They were, for shots of a lecture about a programming language, well produced, and Crockford’s talks were well structured. I got a lot more out of the first talk than the other two, but that could arguably be couched more as a compliment for the introduction video than a knock on the other two, as I felt like I knew the language pretty well after it. (I’d never used the language seriously before.)

I didn’t get too far in to any of the other videos, but there are a ton of them there, so there’s got to be at least a few more good ones. If you’re looking to pick up JavaScript, I can recommend the YUI Theater as a good place to start.

Hot and cold

Sunday, May 20th, 2007

First off, thanks to everybody who voted in The Kid’s ice cream poll. He had a ton of fun with the project. Here’s a brief snapshot of his results:

Popular Ice Cream Flavors

Vanilla edged out mint chip by one vote. (11 for vanilla, 10 for MC.) Rocky road an coffee brought up the end of the top nine (he was supposed to find the top eight, but there was a tie) with four votes. The Kid put together a much more complete report for school, learned about different ways to visualize data and how to use it to draw conclusions and make a point. I’m pretty happy that his class did the assignment.

I’m sorry it took me quite so long to get this posted. I burned the hell out of a couple of my fingers on Thursday morning, and it wasn’t until later on this weekend that I was able to type again. The lesson here was: don’t touch the engine of a lawn mower shortly after you’re done using it. Anyway, all’s better now. Stephanie took such good care of my fingers that it doesn’t look like the blisters are even going to break, which is braggable.

What’s your favorite flavor?

Tuesday, May 15th, 2007

My son is doing a project for class this week that involves survey data and presenting it in graph form.  (Yeah, stats!)  Can you take a second to answer the $64,000 question below by 6 p.m. PT tomorrow (Wednesday).  Thanks!

From  The Kid:

What are your three favorite ice cream flavors? 1. 2. 3. Thank you for taking time to fill out my survey! Sincerely, The Kid

If you’ve already responded via email: Thank You!  Your answer is already recorded.

Disturbingly Concise

Sunday, May 6th, 2007
import Control.Monad

powerset :: [a] -> [[a]]
powerset = filterM (const [True, False])

I saw this over on a rather good introduction to dynamic programming. It does exactly what you’d expect it to do. (i.e., powerset [1,2] = [[1,2],[1],[2],[]].)

Outstanding.


This is a free Wordpress template provided by Mathew Browne | Web Design | SEO