h1

7998 Romans

September 18, 2007

Daniel and I were discussing how to test candidates before hiring them. You can push the requirements further when the candidates get a “take-home” test. So, what would such a test look like?

It must be easy enough so that the candidates don’t discourage. However, it must be challenging enough to test their problem solving skills and be able to produce some code we can discuss. Ideally, I’d like to see a code portfolio: a set of interesting problems and accompanying solutions. My take is that the following problem will be able showcase the attributes I’m looking for:

  • ability to research
  • flexible solution
  • good coding style

Given a file with roman numbers and their integer values in the following format:

487 -> CDLXXXVII
1442 -> MCDXLII
MCCXCVII -> 1297
211 -> CCXI
MCLXIV -> 1164

Find the lines where the roman and integer values don’t match. How many lines are there? Which ones?

h1

The Mac Mini and the Soldering Iron

September 12, 2007

I had been planning to buy a Mac Mini for a while now. I wanted to turn it into a web application server. I was going to install Gentoo on it and drop it somewhere/anywhwere in the house. These plans came to fruition 3 weeks ago when I dropped by the Apple store.

I took my time and configured everything just the way I like it. I rebooted it a few times to check that all services just started by themselves. When I brought it to the living room and pressed the ON button, I sat back in the couch and kept an eye on a “ping” to see how long it would take to boot up. The ping never was answered.

I brought the monitor and the keyboard to the living room (read: hassle) and booted the Mini. It booted without problems. I took out the keyboard and rebooted: no problem. I took out the screen and rebooted: no dice.

I knew the answer before google came back: the Mac Mini was never designed to run headless—the firmware wants a monitor.

This is not for the faith of heart but I found a few links with the same solution: a VGA dummy.

I resisted the idea at first, I knew my soldering skills were not excellent. I had never understood the explanations from the books I had read. I recruited youtube on this one, here are the good videos I found:

“how to solder”

How did we ever get anything done before the Internet?

The soldering itself is a long story: wrong solder, bad soldering iron, soldering cup technique and all. I managed to get it done, however.

Then came the moment of truth. I held my breath and closed my eyes and pressed ON again. Imagine the sweat rolling down my face as I waited to see if it would burst into flames OR have ping print “64 bytes from 192.168.0.112: icmp_seq=141 ttl=64 time=1.255 ms”.

Yes, it worked.

h1

Renaming Thousands of Files

August 25, 2007

If I told you I had to rename 1,000 files, change the extensions or
change hyphens to underscores:

  • how long would it take you?
  • what tools would you use?
  • what would you do?
  • how much would that answer change for 10,000/100,000/1,000,000 files?

Take a moment to think, please, before you keep reading.

This was a situation I was faced with this week. And it reminded me of Steve Yegge’s phone interview blog post You should read it for yourself, but here’s the problem statement:

Last year my team had to remove all the phone numbers from 50,000 Amazon web page templates, since many of the numbers were no longer in service, and we also wanted to route all customer contacts through a single page.

Let’s say you’re on my team, and we have to identify the pages having probable U.S. phone numbers in them. To simplify the problem slightly, assume we have 50,000 HTML files in a Unix directory tree, under a directory called ”/website”. We have 2 days to get a list of file paths to the editorial staff. You need to give me a list of the .html files in this directory tree that appear to contain phone numbers in the following two formats: (xxx) xxx-xxxx and xxx-xxx-xxxx.

How would you solve this problem? Keep in mind our team is on a short (2-day) timeline.

These are not “never-gonna-happen” situations. Your set of skills should include “entreprise” problem solving and “low-level” scripting.

For the curious, here’s how I solved the renaming problem:

find . -name *.TXT > src
cp src dest
vim dest
paste src dest > todo
vim todo
source todo

A good old “find”, some vim regular expression magic, “paste”, and more vim magic (to add “mv” to every line). Another advantage to this technique is that you’ll be able to “preview” the changes before you source the file.

h1

Programming Exercises - Again

August 21, 2007

It was a while back and I wanted to come up with programming exercises for ruby.

This time, it’s Erlang.

I dug up the code I had done then. I felt that I would need this for future reference. Here’s what I coded to learn Ruby:

  • anagram/permutations (list/string – difference?)
  • tower of hanoi
  • reverse polish notation calculator
  • n choose k
  • threads: print “red” / print “blue”
  • threads: multiple dns lookups
  • letter histogram
  • interactive Celsius/Fahrenheit converter
  • roman/arabic numbers converter

To this, I want to add:

  • streams? (next business day? next Monday the 17th?)
  • subsets of a list
  • standard deviation

The advantage of always coding the same algorithm, especially when learning, is that it becomes less about the logic itself, which you presumably already worked out, and more about the language.

It’d be interested to find out what other people are using.

h1

Code Syntax Highlighting for Blogs with VIM

August 11, 2007

After my recent disappointments with the state of syntax highlighting for code embedded in HTML, I did a little bit of research. I would also like to thank Marc-André Cournoyer for his recommendation.

I found a way to do it with TextMate, or with other blogging plugins. However, I’m not always on my Mac, and I don’t like locking myself into proprietary solutions.

That’s when I remembered that Vim has all you need to turn the code you are seeing into HTML with the exact same colors. If you need to turn a snippet (or the whole file, for that matter) into HTML, just select it and type “:TOhtml”. A new buffer will open with your code wrapped in old-style HTML!

If you are more into CSS and are ready to leave HTML 3.2 behind, you can toggle a flag “:let html_use_css=1″ before running “:TOhtml”. You’ll get semantic CSS like this:

.Statement { color: #ffff00; }
.Constant { color: #ff6060; }
.PreProc { color: #ff40ff; }
.Comment { color: #8080ff; }

There are a couple of things to keep in mind. Vim will use your current color scheme to HTMLize the code. If you’re not satisfied with your current color scheme you can switch with “:colorscheme camo”, for example.

If you want anoter incentive: Vim support 481 syntaxes (!) currently and more are added all the time.

Finally, here’s the shell script I use to automate the process:

#!/bin/sh

gvim +colorscheme camo \
     +let html_use_css=1 \
     +runtime! syntax/2html.vim \
     +wq \
     +q $1

Most of my inspiration came from this article.

h1

Source Code Screenshot for “go”

August 9, 2007

go source code

I wish I had a better way to publish the source code and show it highlighted.

Any suggestions?

h1

Bookmark your Directories: Introducing “go”

August 9, 2007

Not all directories are created equal. When you work on a specific machine, there are directories where you are bound to spend more time than others. The same thing happens on the web, there are pages you will want to visit more often than others. Thankfully, this problem has already been solved with bookmarks. I’m just bringing bookmarks to bash.

For years, I’ve had different systems to allow me to move around faster around my often-used directories. I’ve tried soft links, aliases, and a few other tools. I’m not inventing anything new, I’m just making it more lightweight.

Here’s a screenshot that will explain how “go” works.

go_usage

You just have to create a flat file named “.gorc” and place it in your home directory. It should contain one path per line, like this:

/home/jonathan/etc
/home/jonathan/media/working
/home/jonathan/lang/ruby/rails
/home/jonathan/lang/erlang/tests/programming_erlang
/home/jonathan/personal/log
/home/jonathan/notes/technical

If you need to add/edit/remove paths, just fire up your favorite text editor. You can also append easily to it with.

echo $PWD >> ~/.gorc

Finally, here’s the source code.

function go() {
  if [ ! -f $HOME/.gorc ]; then
    echo $HOME/.gorc does not exist…
    return 1
  fi

  if [ -n "$1" ]; then
    local dest=`cat $HOME/.gorc | sed -n $1p`
  else
    local places=`cat $HOME/.gorc`
    local dest=`pick_from_list $places`
  fi

  [ -n "$dest" ] && cd $dest
}

function print_list() {
  local i item

  for item in $@“; do
    ((i++))
    echo $i. $item >&2
  done
}

function pick_from_list() {
  print_list $@

  local n
  read -p ${PROMPT->}  n
  ((n–)) # zero-based index shift

  if ((n < 0 || n >= $#)); then
    return 1
  fi

  shift $n

  echo $1
}

Just make sure you “source” the file in your .bashrc and you’re good to go.

h1

Broadening my Source Control Horizons

July 28, 2007

It all started when I caught Tech Talk: Linus Torvalds on git on reddit. This was a very interesting talk for many reasons:

  • I wasn’t too familiar with Linus Torvalds—what a guy!
  • it had very strong opinions—I like those
  • it covered distributed source control

Source control isn’t something I learned in school. However, by the last year of university, we had to collaborate on enough projects to realize that a way to share source code was an absolute must. Unfortunately, my first exposure to source control was CVS.

I would like to say that CVS is better than nothing, but Linus would disagree with me. CVS taught me the basics of source control and it changed the way I work. Later on, I switched to SVN which was basically a CVS upgrade—a CVS with a lot of little annoyances removed.

For a lot of people, including me until the above video, the CVS/SVN view of source control is their complete exposure to source control. This sad perspective is akin to the one of people who think that Java programming is all there is to programming.

The video hinted to “life after CVS/SVN”. Linus didn’t go into much details, but I figured that if someone, anyone, had a right to an opinion, he would be a good candidate. I installed GIT and started reading the tutorials.

I started getting interested in Ruby on Rails after I watched their famous screencast and wondered: “so, what’s the catch!?”. Learning GIT happened much in the same way. And with similar results.

GIT changes your view of source control. Because of its decentralized nature, a lot of administration bureaucracy disappears. Have you ever asked yourself the following questions?

  • Where will the repository be hosted?
  • What kind of access will we give? (uh… HTTP, SSH, NFS?!)
  • How will we manage the user accounts?
  • What will be our branch naming conventions?
  • Who gets write access? Under what conditions?
  • What kind of branching scheme should we adopt?
  • Who will merge the branches?
  • When will merge occur?
  • How is the repository going to be backed up?
  • What happens to our remote users? (in the case of multiple sites)

What if I told you that all these problems can go away? What if all these problems are caused by the same set of assumptions?

Distributed source control is a radical shift.

I tried GIT and then I decided on Mercurial, another distributed source control system. Both systems have pros and cons, but Mercurial felt easier to use and had better documentation.

My decision on Mercurial doesn’t have to be a final one. I fully intend to revisit GIT in the near future. There are some of its features that I miss and the fact that I’ve been working with Mercurial for a month now makes me more familiar to the underlying concepts.

h1

Newfound Respect for JavaScript

May 11, 2007

A long time ago, in the list of “how can I say I’m a web developer if I don’t know this” items, I had determined that JavaScript was my final frontier. A lot of things have happened since then.

Douglas Crockford describes JavaScript as “The World’s Most Misunderstood Programming Language” and “Lisp in C’s Clothing” [source]. Now that I’ve delved more into the depths of JavaScript, I can relate to both these statements. I’ve been introduced to Scheme about a year ago, and have been actively Scheming for the last month or so. Consequently, a lot of the “weird” concepts of JavaScript are just my day-to-day Scheme concepts.

Once you start playing with first-class functions and closures in a language, playing with them in another doesn’t represent a barrier to entry. I might describe this feeling as “coming home”–when all the toys you are familiar with are available for your evil purposes once more.

Most people that I’ve known, including myself, have started their JavaScript journey in the worst possible way. We had heard that JavaScript was not a real language, we had been annoyed by image rollovers and other JavaScript trickeries, and most of the examples out there were spectacularly bad. We copied and pasted our first scripts. We got results and didn’t ask too many questions. In the end, how many of us could claim to be JavaScript experts or even to have known one?

Furthermore, Crockford himself confirmed something that I had suspected: that all JavaScript books were incredibly bad. The only one he could recommend was JavaScript - The Definitive Guide (I only own this book in pocket reference). Hopefully, AJAX and the recent surge of JavaScript interest might convince good authors to step up to the plate.

Recently, I’ve been going through a lot of good material. Here’s what I recommend:

Found a pattern? :-D Yeah, he’s that good.

h1

Interviews and Coding Ability Gradation

April 23, 2007

I’ve had the chance to interview a few people lately. It’s just getting started, my calendar includes 3 interviews this week.

There are 2 parts to the interviews I give. In the first part, I like to talk about general interest in what’s going on in our field. In the second part, I ask people to code for me.

First Part: Passion

I ask about tech news websites that the applicant is using, if any. I ask about blogs that are read. I ask about RSS feeds that are reviewed.

I also like to ask “what’s going on right now in the industry? what’s the buzz?”

Another one I’ve been using: “what’s the next programming language you want to learn?”

I’ve been wanting to ask about portfolio. If you have been programming for a few years, I’d like to think you could show me something you’ve done. If we expect artists to bring a portfolio of their work, can’t we expect the same from programmers?

Personally, I’ve got 3 webapps up and running that I’d like to show and talk about. The thing you see in my glittering eyes and my wide smile is passion. I’m looking for that in others.

Second Part: Skills

At this point of the interview, I probably already made my opinion.

But I’d like to see some code too.

At first, I thought I would ask people to code: group_by. This is something I coded myself a few times, in Ruby for fun and in Javascript for practical purposes. However, I realized that it was not something I’d like to code under pressure. I decided to water it down.

What I used for the last 2 interviews was: any or all. Let’s just say that the results were not… productive. The problem with ‘any or all’ is that you either get it or you don’t. I needed better resolution.

One of the problems is that function pointers are just not part of the repertoire of most of the programmers I know. Thank you Javaschools!

I decided to change my approach. I decided to combine bullet-in-the-brain-easy programming with elephant-in-the-room function pointer enlightenment.

Here is the coding test I came up with. I’d like to get some honest opinions. Also, feel free to use it for your own interviews.

*** If you want to have a go at the test, everything that follows could be considered a SPOILER. (Thanks Fred) ***

Now, I believe there are 3 outcomes out of the questions in this test.

  • brute-force code all 3 questions (worst)
  • brute-force code all 3 questions but realize that there’s something wrong (better)
  • abstract away the act of summing from what is being summed up (best)

I’m going for reactions, insights and skills.

I want to believe that I don’t have to resort to FizzBuzz.

I submit my own answers. I spare you the inner private class magic that would be required in Java.