Wednesday, September 29, 2010

Set's for Go

One of my favorite things about Python lately has been the built-in Set class.  Due to my recent fling with Go I decided to implement it there too.  If you're interested, check out my github repository, or just install it directly with the following command.


Saturday, September 4, 2010

Zygote: My skeleton files for a new project with GNU autotools

For the third time this week I've started a new minor project in C and had to remind myself how to use the GNU build system.  This time I thought it worth a few minutes to build a set of skeleton files for everyone to use.  The result is called Zygote and its available on github.

This small package contains all the things you need to write a C program with a Python script to run tests where it is available.  All of the files are public domain so you can use this as the basis for any project.  Let me know if you find it useful.

Friday, September 3, 2010

Autoconf not finding pkg-config on OSX? An Easy fix

I've run into this a couple times lately so it's worth noting for others.  aclocal only searches /usr/share/aclocal by default.  This poses a problem because our pkg-config is in /usr/local, but there's an easy fix.  Create a new file named /usr/share/aclocal/dirlist with a line for each additional directory you want to search.  In our case just /usr/local/share/aclocal.  Presto, now autoconf can find pkg-config's macros.

Thursday, September 2, 2010

Act Like You're Teaching to Avoid Sloppy Work

This short tip on Lifehacker is worth a read. Seems pretty obvious, but it never really occurred to me before. I'm not a fan of pair programming, but I can see how this aspect can be a significant quality improvement.

Do stuff more efficiently and make fewer mistakes by acting like you are teaching someone how to do it. For example, if I'm painting my living room, I imagine I'm showing someone else the right and wrong things to: preventing drips and bubbles, how to prepare the room, etc. This helps me to be less sloppy when I'm doing things because when you teach someone how to do something you want them to do it right (and you tend to move a bit slower). If you pretend, in your mind, that you're teaching someone then you, too, will be more likely to do it right and make fewer mistakes.

Wednesday, September 1, 2010

Back to Basics: Bubble Sorted Date Strings in C.

Earlier today I ran across a job posting that had a small test, I wasn't interested in the job but I liked the test.  One problem was to write a date sorter without using a date parsing library.  The format to be parsed is: "Sep 1 2010".  Normally I would write something like this in a few lines of Python or Perl, but I decided to tackle the problem in C, just to make it harder.  Since regular expressions were allowed, I thought it was okay to use sscanf.

One of the first thing's you'll see is that I took a page from Perl's spaceship operator, and defined a macro that will compare two numbers and return -1 if it is less, 0 if equal and 1 if greater.  Normally for a sorting algorithm you would only need to know if it is less or not, but I wanted to chain comparisons together by falling down to the next comparison when two values are equal.

Another trick I used is a bit of a hack to find the the number corresponding to the month.  You'll notice that I cast char *a to uint32_t as a way to avoid strcmp.  I'm not sure if I would do this in production code, but its a fun trick.

Full code is below.