All posts by Alan

Mojang’s new game Scrolls seems familiar…

I saw an article today about the announcement of the new game Scrolls by the developers of Minecraft and the idea looked really familiar.

Then I realized, its the same idea I started working on 8 years ago during my freshman year of high school.

The difference is they have the resources to finish it and the experience to do it right. Just another example of how having an idea isn’t nearly as important as actually creating something.

The game I made was called Dark Magic. It was a combination between a trading card game and a strategy game. You would create a deck of cards and then play those cards on a playfield. It was supposed to be Magic: The Gathering meets Civilization.

Each player started with a castle, and the goal was to capture the other player’s castle. You could use terrain to update your territory to produce more resources and build units to collect resources or fight (never got the fighting working properly though, probably the nested loops 10 levels deep).

I never quite completed the game so it has a lot of bugs in it, but here is a link to it anyways:

It is a .exe, so I doubt many people will want to run it, but I promise it is clean, no viruses or anything. Install it in a VM if you don’t trust it. Just make sure to set your screen resolution to 1024×768. Yes, I know, you shouldn’t need to set your resolution to play a game, but when I wrote it I didn’t think anyone would be running at anything else.

It is written in Visual Basic 6 and that’s not even the worst part of it. I had just started programming when I wrote this, so I made some really horrible design decisions.

I have some great stories about problems I had when writing it, but it taught me a lot that I wouldn’t have learned until much later if I hadn’t had the motivation of getting this game working.

Its amazing how looking back at something you did a long time ago can show you the lessons that you read about. Finding a project to work on, creating something instead of just coming up with ideas, the importance of shipping, don’t make assumptions about the user’s system.

I got some of them right, others wrong, but hopefully those lessons will help me with my future projects. For now, maybe I will try to install Visual Studio 6 and fix a few of the old bugs.

And if you don’t want to install it, here is some screenshots of the game. The graphics were all done by my old friend Ryan Warren. Its been a long time since I have talked to him, but you can see his blog at

Let me know if you try running it, I would be interested to see what anyone thinks about it.

Bi-Color LEDs with Arduino

A few years ago I bought some bi-color or dual-color LEDs. These are LEDs that have only 2 leads like regular LEDs, but can display 2 colors.

An LED is a type of diode, so it only allows electricity to flow one way through it. But when that electricity is flowing, it lights up.

The bi-color LEDs are essentially 2 of these in one package in opposite directions.

With an Arduino, you normally connect one end to ground and the other end to a digital pin and just write a HIGH to that pin to light the LED.

I wasn’t sure at first how to use the bi-color LEDs with the Arduino, but it turns out it is simple. All you have to do is connect each end to a digital pin and write LOW to one and HIGH to the other. Reverse them and it lights in the other color.

This works because writing LOW sets the pin to 0V just like writing HIGH sets it to 5V. This means that one at LOW and one at HIGH creates a voltage drop across the LED, lighting it up.

Turns out it is nice and easy.

Automatic Twitter Posting in PHP

I got a suggestion a few months ago to make post to Twitter. It is now working and you can see it posting every day at @FlyingPieNotify

Since the rest of the site was written in PHP already, I figured I would do the Twitter posting in PHP as well. I had done it before when working on webbr so I figured it would be just as easy.

But it turns out Twitter recently deprecated Basic authentication and made OAuth mandatory. This means I can’t just send my username and password, but instead needed to register as an application and go through a handshake process before I could post.

The good news is, if you are just posting from a single account and a single script, you only need to do this once.

Here is how I was able to get my server posting a name from the database to Twitter every day. For this, I assume you have a webserver running PHP that is accessible from the general internet (not on a local network only), and a basic knowledge of PHP.

Step 1: Register as an application

To use OAuth with Twitter, they require you to register as an application. This makes sense if you are writing an application to deal with multiple users, but even for 1 you have to do it.

If you go to you can register a new application. Most of the information here doesn’t matter for our purposes. The only thing you need to pay attention to specifically is the callback URL. For this, put a URL to a page that you can create on your server, such as We will create this site soon.

Once your application is created, you will be given a consumer secret and a consumer key. We will need these in the next step.

Step 2: OAuth authentication

Now we need to go through the OAuth process to give our code access to the account. Since we only want to post for this one account, we don’t need to make this code very robust.

I used the Twitter-async library from Grab the EpiCurl.php, EpiOAuth.php, and EpiTwitter.php files and put them on your server somewhere you can access them easily, preferably in your include_path.

Now create a file on your server that you can access. In this file, include the files we just created, and then add this code:

$twitterObj = new EpiTwitter($consumer_key, $consumer_secret);
echo 'Authorize with Twitter';

Make sure you replace the consumer key and secret with the ones you got when you registered your application.

Now create a second file with the name and URL that you put as the callback URL when you registered your application with Twitter. In this file, put:

$twitterObj = new EpiTwitter($consumer_key, $consumer_secret);

$token = $twitterObj->getAccessToken();

echo 'oauth_token: '.$token->oauth_token.'
echo 'oauth_token_secret: '.$token->oauth_token_secret;

Again, make sure to include the Epi files and to put in your consumer key and secret.

Now load your first file in your browser, click the link, authorize your application with Twitter, and copy down the token and token secret that are shown in your browser.

Now we have authenticated, so we don’t need to do that again! You can just delete the 2 files you created, but leave the libraries there, we will use them again.

Step 3: Posting to Twitter

Now that we have an authentication token for our account and our application, we are ready to post.

To post, all we need to do is:

$twitterObj = new EpiTwitter($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret);

$result = $twitterObj->post_statusesUpdate(array('status' => $post));
$result = $result->responseText;

You need to make sure to have the keys from your application and the secret that you got when you authenticated here or it will not work.

Now if you look at this, you may be wondering about the last line. It looks like it is unnecessary, but because of the library we are using, we actually need it. This is because it is an asynchronous library, so our call to post does not mean that the post has been made. Referencing the response of our call forces our code to block until the call has completed.

Now you just need to write some code to generate your message and run when needed. For Flying Pie Notifier, I just used a cron job that runs once a day and pulls the name from the database for that day.

After this, there is a lot more you can do with these PHP scripts. The documentation for the Twitter-async library shows how to use the rest of the Twitter API in addition to posting.


Brittney and I have decided to do thing-a-day this year.

Each year, we will make at least one thing. Sometimes it will be something we do together, sometimes something just one of us did it.

Hopefully a few of my things will be some of the blog posts I have been meaning to write for a while.

You can check us out at and see more about thing-a-day at

We didn’t put our first day posts up on the thing-a-day site (trying to figure out how to get posterous to do it automatically didn’t seem to work) but we will probably post the rest of them there.

Flying Pie Notifier Update

I previously blogged about my newest side project, On September 20, Flying Pie Pizza mentioned the site on their Facebook page. The response was amazing. Here is the Google Analytics showing the number of visitors before and after the Facebook post. Google Analytics

As you can see, the number of visitors to the site went from essentially 0 to 234 in one day. And now, weeks afterafter this initial mention, the average number of visitors is at about 4 per day.

The same thing is shown in the number of users signed up. Before the mention, Flying Pie Notifier had 34 users registered, 23 of whom were receiving our weekly updates. 2 days after, we were up to 161 registered, and now it is up to 177.

This still isn’t a lot of traffic for a website, but for a local one that you should only ever have to visit once, I am really happy with the response. Site activity has died down a bit, but we have only had 2 people unsubscribe from the site, so we still have hundreds of people being notified of when it is their day.

Some of the new users signed up with full names or multiple names at once, which unfortunately isn’t supported right now. I had to go through these, but I got them all cleaned up so it should work for those users now.

The only problem remaining is that AOL appears to be blocking the emails I send to their users. Luckily there were only 2 people with AOL addresses who signed up, but I will blog later about how I am handling this.

As always, if you have any comments or have any suggestions for Flying Pie Notifier, leave a comment or send me an email.

Replacing a Cracked Lumix DMC-ZS3 Screen

Last year I bought a Panasonic Lumix DMC-ZS3 (also known as the DMC-TZ7) and have loved the camera. It has an amazing 12x zoom, takes great pictures, and does 720p video. If you are in the market for a camera, I would recommend the new version of it, the Lumix DMC-ZS7 which has GPS tagging and is currently cheaper on Amazon.

About a month ago, I cracked the screen on it. The camera still worked, but since there is no viewfinder I could never see what I was getting pictures of or adjust any settings. It made it really hard to get good pictures, especially when trying to use the zoom.

I ordered a new screen from and it works great. If you need a screen for this camera, I would recommend buying it there.

It is a bit tricky to replace the screen though. Luckily, I found a video that shows all the steps. The text is in German, but you can see all the steps which is all you really need.

The only difference I found from this video was that the screen I bought did not have the metal bezel around it that the one in the camera and in the video. All I had to do was remove the bezel and put it on the new screen and it follow the rest of the steps the same as the video.

Total it took me about 20 minutes to replace the screen, and then it was working perfectly.

Sending Email To Gmail From PHP Without Being Marked As Spam

While working on Flying Pie Notifier, I ran into a problem with Gmail marking the notification emails as spam. I was able to find the Gmail Bulk Sender Guidelines and make some changes. I think I got Gmail to finally recognize that the notifications are not spam.

My first step was to make sure that SPF was set up correctly and to check the reverse DNS PTR record for the IP address I was sending from. Both of these are simple to set up with just DNS records.

Unfortunately, those changes didn’t seems to fix the problem completely, so I had to move on to the next step, DKIM (DomainKeys Identified Mail). DKIM is a way of cryptographically signing emails that are sent to verify that they are sent from the domain they claim they were sent by.

I found a PHP library called PHP-DKIM that would perform the signing, but it was incompatible with the PEAR Mail_Mime module that I was using to send HTML email. I had to make some modifications to the code to get them to work together.

Here are the steps I used to set up DKIM signing with Pear::Mail_Mime and PHP-DKIM:

  1. Generate a public and private key pair.
    First I needed to generate a public and private key pair to use for signing messages and for other people to verify the signature. These commands generate 2 files, key.priv and, containing my new private and public keys:

    openssl genrsa -out key.priv 2048
    openssl rsa -in key.priv -out -pubout -outform PEM
  2. Publish the public key in a DNS record.
    DKIM public keys are published in a special DNS record so the recipient can look up the key and use it to verify the message signature. I followed the PHP-DKIM README and put my keys in a dkim-cfg.php file along with my domain name and a selector name and ran dkim-test.php.

    Loading dkim-test.php will tell you if you have any problems with your configuration so far, and if not it gives you a DNS record. For me, it generated this record which I added to my DNS: TXT "v=DKIM1; k=rsa; g=*; s=email; h=sha1; t=y; p=MHwwDQYJKoZIhvcNAQEBBQADawAwaAJhAODvTnvu4+OO+47m/3iRImsshlhQ+u30 0cHSdCJPndsD2meo63lNl8ELktIZKUEEEGFYNbwuZHWISCmuFHEiQNIHeag+awen 75oPBZqd1ABVdjyTwZa1matMzQhg5rSGpQIDAQAB ;"

    I then used and to check my record and make sure it was set up correctly.

  3. Signing Code
    I had downloaded the PHP-DKIM library from, but found that the way it treated headers was not compatible with the PEAR Mail_Mime library that I was already using. PHP-DKIM expects a single header string formatted the way headers are transmitted between servers when sending email. Mail_Mime wants an associative array of headers that it then uses to generate the header string when it sends the final message.

    I decided to modify PHP-DKIM to get it to work with the associative array approach, since I thought that was the better of the solutions.

    You can find my modified version of the library at The only file I modified is dkim.php. I changed to use an array for headers and cleaned up the code a bit to make it easier (in my opinion) to read.

    To make the library work with Mail_Mime header arrays, I added code to the AddDKIM method that concatenates the headers together. This is simple in PHP, and just requires:

    $headers_line = '';
    foreach ($headers as $key => $value)
    $headers_line .= $key.': '.$value."rn";

    After that, I just had to change what the function returned. Instead of returning a new header string, I just return the DKIM signature string. This can then be added to the headers using:

    $dkim = AddDKIM($headers, $subject, $message);
    $headers['DKIM-Signature'] = $dkim;

    This code could be cleaned up to automatically add the header, but it works until I take the time to rewrite the library and make it object oriented.

  4. Testing
    When I first tried to use my new code to send emails to my own Gmail account, I found that I had some errors in my implementation. In Gmail, you can see the full headers and the results of DKIM and SPF checks by clicking the arrow next to Reply and selecting Show Original. This will show you the full headers of the message, including the verifications added by Gmail.

    When I did this on my message, I got an error telling me the body hash was wrong. The body hash is used to verify that the email message was not tampered with during delivery. Since I had sent the message myself, I knew it had not been modified. Therefore, Gmail was calculating the hash based on a different version of the message than my current code.

    I was able to find a service that could help me track down the problem. At you can find information about an automated responder that will let you know the results of the DKIM verification.

    By sending my message to the Port25 reflector test address, I got a report letting me know all the details of the DKIM verification process. One of the pieces of information in this email was the canonicalized body of the email. Canonicalization is the process of standardizing the message to specific requirements to make sure both sides are doing the hash calculation on the same data. I could then use the NiceDump function in PHP-DKIM to print out the canonicalized message that I was calculating the hash on. This let me see where I had caused a problem when modifying the library.

    Using the same testing address, I was able to find a few other problems with my modifications to the library and get it working. Once I had the bugs worked out, the reflector address reported the DKIM verification as passing. It worked!

There is no definite solution for not having your emails marked as spam. All you can do is try to follow all the guidelines that Gmail and other providers specify. It seems to me that Flying Pie Notifier is no longer being marked as spam, so I think I should be good for now. DKIM is a part of that, but I also had to make sure my mail server and DNS records were all set up correctly.

If you want a really detailed technical explanation of DKIM, you can find the specifications in the RFC at

If you have any issues with this code or are trying to implement it yourself, leave a comment and I can try to help you out.

Originally this post used a 384 bit private key. This key size is trivially broken now, so I have updated it to specify a 2048 bit key.


Introducing my latest website project: Flying Pie Notifier.

If you aren’t from Boise, Flying Pie is an amazing pizza place and has been my favorite for years. In addition to having amazing pizzas, they have something called It’s Your Day. Each day they have a different person’s name. If it is your name, you can come in and make your own pizza.

I did It’s Your Day a while ago and had a lot of fun. But I always forgot to look online and see when my name or my friend’s names were coming up. So I decided to make a website to remind myself.

Right now, you can go to and sign up. Just enter your email address and the name you want to be notified about and you will get a notification sent to you when your name is coming up. You can also sign up to get a weekly reminder of the It’s Your Wednesday group (and maybe some other things soon).

I am working on adding in some extra features, so let me know if there is anything you want. I would love to hear any comments or suggestions.

Arudino and 1-wire

For my birthday this year, my wife got me the Arduino Start Kit from Adafruit Industries.

If you aren’t familiar with Arduino, it is a great open source platform for doing small electronics projects. The start kit I got has a Arudino Duemilanove, which is the latest basic version of the platform. The Duemilanove has a small processor on it that can be easily programmed over USB, and a lot of input and output pins to play with.

After getting the kit set up and my prototyping board soldered together, I decided that my first project would get seeing if I could get some old 1-wire temperature sensors working. A few years ago, I got a sample of 5 of these sensors but was never able to get them working with my homemade serial adapters. The sensors I got are the DS1820 from Dallas Semiconductor. These are old and have now been replaced by the DS18S20, but they work the same.

Turns out that the Arduino community had already done all the hard work at getting these working, so it only took me a few minutes to get it set up.

Hardware: Each of these sensors has 3 legs: power, ground, and data. If you are only using a few sensors that are close to the power supply, you can instead use parasitic power as I did. This reduces the number of wires to the sensor needed to 2, data and ground. To do this, I shorted the power and ground pins and wired them to ground. I then attached the center data pin to one of the digital IO pins of the Arduino.

Here you can see the Arduino with the sensor connected on the prototype shield from the starter kit.

This is a close up of the connections. The brown wire connects the power and ground pins. The black wire connects these to ground. The yellow wire is connected to digital I/O pin 2 on the Arduino.

Software: The Dallas Temperature Control Library is a library that allows simple control of the 1-wire temperature sensors. All you have to do is download it, put it in your Arduino libraries folder, and open the Simple example.

The example sets up the library and reads the current temperature from the first sensor, printing it out to the serial monitor.

After years of having these sensors sitting around in a drawer, it only took me a few minutes to get them working. Now I just need a larger project to use these in.

Back Again

Well it has been almost 3 years since I last blogged, but now that I have graduated I am going to try to start again.

I have decided to start posting again about all the projects I am working on. I always seem to have a few things going on, but I rarely record anything from them. To help myself keep track of it all and maybe help anyone doing something similar, I will be posting updates about my different projects.

I have a lot of different things going on right now, so over the next few weeks I will start cataloging some of them here. Then I can start updating them as I make progress.

Hopefully having graduated and having a purpose for this blog will help me to stay more consistent and keep posting.