lukebaker.org

lukebaker.org

Disc Golf Courses By County

with one comment

With a healthy blanket of snow still on the ground, I took on an indoor disc golf project this weekend.  I’ve been wondering about the distribution of golf courses across the country, so after downloading some data on disc golf courses I created a map of all the disc golf courses in the USA by county.

 

Original SVG

Hat tip: How to Make a US County Thematic Map Using Free Tools

Written by Luke

March 8th, 2011 at 5:39 pm

Claire Mae Baker

with 5 comments

My wife and I are the proud parents of Claire Mae Baker.  She was born a few weeks early, but everyone is healthy.

5lbs. 12oz.
19 inches
June 27, 2008 8:32pm

Written by Luke

July 1st, 2008 at 12:06 pm

Posted in General

SmugMug Tweaks

without comments

SmugMug Admin Rating Sample

Lately, I’ve been working on some SmugMug tweaks to take advantage of their offer of a free lifetime account for developers who use their API. The first one was a quick hack which uploads some recent SmugMug photos to your Flickr account. This allows people who switched to SmugMug to still keep up with their Flickr network. More information is available on the project’s page.

The second and more interesting one is some JavaScript that adds the ability for SmugMug users to rate their own photos. This is the first of two projects to aid my work flow. Eventually I want to be able to upload a bunch of photos in a private album, rate them, and then in one fell swoop move all photos with a rating higher than X to a public album.

I provide two installation options which both pull the script from my server and inject it into the pages. This should allow for invisible upgrades. Savvy or cautious users can install it other ways.

Another interesting aspect of this project is its integration with SmugMug’s API. First, we’re using the API on SmugMug’s own site. This isn’t the typical use case of a photo site’s API. Secondly, the script gets proper API authorization behind the scenes, without asking the user for any information. Provided that the user is already logged in to SmugMug’s site, then my script gains that user’s credentials when interacting with API. This is not evident in the API docs and requires a bit of a hack.

Any users should be aware of security concerns whenever external JavaScript is inserted into your page.  Protect yourself as you see fit.

Written by Luke

December 17th, 2007 at 1:02 pm

ActiveRecord in PHP

with 3 comments

I’ve been meaning to release this code for quite some time. I’ve finally had a bit of time and motivation to sit down and take care of it. Ever since I started working with Ruby on Rails, I would cringe whenever I had to write yet more PHP code to do simple CRUD actions. Furthermore I really enjoyed the Rails syntax that you use to interact with its implementation of the ActiveRecord pattern. As such, I went forward and built a clone using PHP5. So far it has been used for a few projects and has been a joy to use.

Props to my employer, Gospel Communications, who allowed me to spend some time on this during work hours, as well as give me full copyright of the code.

More information and documentation over on the project’s home page.

Written by Luke

September 24th, 2007 at 6:25 pm

Frangipani Flower

with 2 comments

In its fifth year in the Michigan climate, my frangipani, a tropical plant, has finally bloomed. Today the first flower of the season unfurled, with many more on their way. Some pictures:

the flower

the flowergrowth this year

Written by Luke

July 6th, 2007 at 5:11 pm

Posted in General

Search Along A Driving Route

with 8 comments

I recently went on a 3000 mile road trip, and as I was preparing for the trip, I wanted to know the answer to questions like “Where are all the Speedway gas stations that are within a mile of my route?”. I couldn’t find anything that would allow me to search for businesses near a given driving route, instead I could only search for things near a given point or city. I decided to build a mashup using Yahoo! Pipes and Google Maps that would allow me to do just what I wanted.

How to use it:

  1. Install the search-route bookmarklet.
  2. Go to Google Maps and create route.
  3. Click the search-route bookmarklet you installed in step #1.
  4. Search!

If you don’t want to bother installing the bookmarklet and want to try out the searching, you can test a local driving route or a long distance driving route.

How it Works:

After the user creates the route on Google Maps, clicking the bookmarklet sends the URL of their Google Maps page to a script on my site. This script will download the URL from Google Maps and parse out the encoded route in that page. Once we have this, we can give the user a search page with their route and map using Google Maps’ API. When the user searches, we call a Yahoo! Pipe which is passed the search parameters and a special id referencing this user’s route. The Yahoo! Pipe will download a specially crafted Atom feed for this route from my server. This Atom feed contains a list of some of the latitude and longitude points of the route. The Yahoo! Pipe then does a Yahoo! Local search on each point using the search parameters the user specified. Searches on particularly long routes can take several seconds to complete.

Written by Luke

April 19th, 2007 at 3:23 pm

Posted in General,Projects

AT&T: Support and Naked DSL

with 4 comments

Lots of people like to complain about support from various large companies, particularly if the support is comcastic. I certainly have enjoyed complaining about them from time to time. However, today I had one of my first good experiences with AT&T’s support (formerly SBC in our area).

  1. The line quality was good. No static making it hard to hear the support people.
  2. Relatively short wait on hold.
  3. The people I talked to spoke English in such a way that I could easily understand them. One even had a charming southern accent.
  4. I received useful information the first time I asked for it.

I also discovered that AT&T now offers naked DSL or as they call it “dry-loop DSL”. In other words, they allow you to purchase DSL without requiring you to have phone service through them. I had heard mention of this happening in the future, but didn’t realize it was already available.

Unfortunately if you remove your phone service, your DSL no longer qualifies for whatever special offers they have, which means you’ll be paying more for your DSL. So, despite removing phone service, your bill may not decrease by all that much. The support folk informed me that if I were to switch to dry-loop DSL, they have to shut of my phone AND DSL prior to turning on the dry-loop DSL. I was told that I might be DSL-less for up to 5 business days. Surprisingly, the support person was apologetic about this issue.

Dry Loop DSL Options from AT&T

  1. Express: 1.5 Mbps / 384 Kbps — $44.99
  2. Pro: 3.0 Mbps / 512 Kbps — $49.99

To talk directly to the dry-loop folk at AT&T, call 1-888-800-4095 (7am – 9pm M-F; 8am – 5pm Saturday).

Written by Luke

March 9th, 2007 at 12:47 pm

Posted in General

PHP and Named Parameters

with one comment

Since working with Ruby on Rails, I’ve become much more conscious about how my code looks. Occasionally, when working with PHP there are things that are a part of the language that tend to make my code look ugly or just not very clear and succinct.

One such case is when defining arrays, particularly nested associative arrays. PHP makes working with arrays fairly handy, however I always shudder when I have to create / populate an array explicitly. Some of the code I’m working with lately uses associative arrays as a way to have named parameters in PHP. Here’s some example code that uses associative arrays in this way:

  1. $p1 = new Person(‘Luke Baker’,
  2.      array(‘home_phone’ => ’555-5555′, ‘cell_phone’ => ’555-5551′));
  3. $p2 = new Person(‘John Doe’,
  4.      array(‘cell_phone’ => ’555-5531′, ‘email’ => ‘john@doe.com’);

Named parameters let us accept lots of different types of information, without splitting them up into individual parameters and having to remember which order the parameters are in. I can handle home_phone, cell_phone, and email in the person constructor and the call to the constructor doesn’t have to worry about the order of parameters or filling in null values for information it doesn’t have.

The above example doesn’t look too ugly, but we also aren’t stretching the named parameters very much. Here’s a slightly messier example:

  1. $p3 = new Person("John Calvin", array(‘dates’ => array(‘birth’ => ‘July 10, 1509′, ‘death’ => ‘May 27, 1564′)));

We could break it into different lines, which doesn’t look too shabby:

  1. $p3 = new Person("John Calvin", array(
  2.     ‘dates’ => array(
  3.         ‘birth’ => ‘July 10, 1509′,
  4.         ‘death’ => ‘May 27, 1564′
  5.     )));

Another option, might be to use JSON to represent that associative array. We could have our constructor decode the second parameter from JSON if it looks like it might be JSON. Once it is decoded, we’re back to an array representation in PHP, which is what we started with. In other words, we can easily allow our constructor to accept either JSON or an array as the second parameter. Then we could write the call the to constructor as follows:

  1. $p3 = new Person("John Calvin",
  2.     ‘{"dates" : {"birth" : "July 10, 1509", "death" : "May 27, 1564"}}’);

Maybe I’m silly, but I like the look of the JSON example a bit better. I certainly won’t be using JSON everywhere I declare arrays, but here and there I find it useful. What do you think, is it worthwhile to support JSON in this way?

Written by Luke

March 1st, 2007 at 8:51 pm

Posted in Programming

Yahoo! Pipes

without comments

The web is buzzing about Yahoo! Pipes. It’ll be interesting to see what people build with Pipes. I couldn’t think of any need I had that would be fulfilled by Pipes, until today. I host this site on TextDrive / Joyent, and they have a forum that I lurk on from time to time. I’m mostly just interested in what a few select people say, particularly the top few people who work at TextDrive. Unfortunately on that forum, there aren’t any RSS feeds available that will monitor particular users’ posts. Until now, I’ve been using a bookmark to do a search on the forum that returns the latest posts from a specific user. In about 10 minutes of playing with Yahoo! Pipes, I had a working Pipe just to my liking. Hopefully, this does the trick for me.

I’m curious to see if I’ll “miss” posts by the select three users. The feed I’m filtering, contains the 15 most recent posts to the forum. This means that each post might not be listed in the feed for very long, as it may get pushed down by more recent posts. Presumably, either my RSS reader would have to access to Pipe or possibly Yahoo! Pipes would have to access the feed during that window in. If they don’t, then I’ll miss a post. It seems like this might be a problem for a significant number of uses for Yahoo! Pipes, so I’m interested to see how that plays out. Granted this “problem” is inherent in feeds, but it may be compounded when you’re filtering lots of feeds for specific information.

While we’re on the topic of working with feeds and publishing the results, it is worth noting you can do some simple manipulation and publishing with Google Reader, as well.

Written by Luke

February 13th, 2007 at 6:52 pm

Posted in General

The static keyword in PHP5

with 2 comments

With PHP5, PHP introduced some more robust object oriented capabilities to the language. I’ve been diving into this quite a bit lately and learning a lot. I figured all the stuff I discovered about the static keyword would be enough fodder for a post. Most of this information can probably be gleamed straight from the docs, but I for one didn’t really soak up the denseness of the documentation my first few times around.

Static Members

What isn’t immediately obvious, is that static members are shared among all the instances of the class that has the static member. In other words, it is like a global variable for that class and instances of that class. While you can’t access a static member directly from an instantiation of the class, you can create methods that access or manipulate the static member. Time for a quick example.

  1. class Foo {
  2.   static $var = 0;
  3.   function increment() { self::$var++; }
  4.   function get() { return self::$var; }
  5. }
  6.  
  7. $f1 = new Foo();
  8. $f1->get();  // returns 0
  9. Foo::$var; // returns 0
  10. $f1->increment();
  11. $f2 = new Foo();
  12. $f2->get();  // returns 1
  13. $f2->increment();
  14. $f1->get();  // returns 2
  15. Foo::$var; // returns 2

Now, the other interesting find is that the static member is global not only to that class and instances of that class, but also all sub-classes and instances of those sub-classes. You can prevent this propagation down inheritance tree, by declaring the static member as private or by redeclaring that static member inside the sub-classes, as well as the methods that work on the static method.

  1. class Foo {
  2.   static $var = 0;
  3.   function increment() { self::$var++; }
  4.   function get() { return self::$var; }
  5. }
  6. class Bar extends Foo { }
  7. Foo::$var++;
  8. Bar::$var;  // returns 1

Static Methods

The main area that I got hung up with static methods was using inherited static method calls. For the work I was doing, I wanted to be able to call a static method and within the static method know which class this method was called on. Unfortunately, everything I tried didn’t work.

  1. class Foo {
  2.   static function get_my_class() { return get_class(); }
  3.   function get_my_class2() { return get_class($this); }
  4. }
  5. class Bar extends Foo {}
  6. Bar::get_my_class();  // returns ‘Foo’
  7. $b = new Bar();
  8. $b->get_my_class2();  // returns ‘Bar’

It turns out that static methods belong to the class in which they’re defined and they have no clue where they got called from. Similarly, the same idea can be applied when thinking about static members. The class that has the actual code, determines what variable is affected. Consider one last example:

  1. class Foo {
  2.   static $var = 0;
  3.   function increment() { self::$var++; }
  4.   function get() { return self::$var; }
  5. }
  6. class Bar extends Foo {
  7.   static $var = 23;
  8.   function increment() { self::$var++; }
  9. }
  10. $f = new Foo();
  11. $b = new Bar();
  12. $b->get(); // returns 0 (Foo)
  13. $b->increment();  // increment Bar’s $var
  14. Bar::$var; // returns 24 (Bar)
  15. $b->get(); // returns 0

Written by Luke

February 11th, 2007 at 10:01 pm

Posted in Programming