Code

Namey - A Random Name Generator

Recently, I had an idea for a project where I wanted to be able to create random names for people on the fly. It's a fictional schedule for a fictional cable channel, the Not Lifetime Movie Network. Some of the movie titles needed random names. I dug around, and found a few name generators out there, but none of them had an API, or available source code, so I ended up making my own. This quickly turned into a classic project -- I spent maybe an hour or two writing some code to generate a list of fake movies, and ten times longer coming up with a generic library for random name generation. it went something like this:

I don't actually like xkcd that much, but this sums things up nicely.

But when I was done, I had Namey -- a website where you can quickly generate some random names, as well as an underlying library written in ruby. It uses files generated by the US Census Bureau for the 1990 census to generate whatever sort of name you would like. You can pick a gender, specify if you want a last name or not, and if you would like a common name, rare name, etc.

The data itself looks a lot like this (in fact, this is the data):

JAMES 3.318 3.318 1
JOHN 3.271 6.589 2
ROBERT 3.143 9.732 3
MICHAEL 2.629 12.361 4
WILLIAM 2.451 14.812 5
DAVID 2.363 17.176 6
RICHARD 1.703 18.878 7
CHARLES 1.523 20.401 8
JOSEPH 1.404 21.805 9
THOMAS 1.380 23.185 10

So, the government is big on ALL CAPS. Also, there's no punctuation, so O'Brian is OBRIAN. I've done a bunch of massaging to the data - names are mostly in proper case, with apostrophes where it's fairly obvious, but I'm sure I missed some.

For nerds, the code is open source and available on github, so you can fork it and play around as much as you want. As I worked on this project, I developed certain goals:

  • Write a decent Ruby gem to generate random names -- this is the bulk of the project
  • Build a website which can use it -- see http://namey.muffinlabs.com/
  • Play with Twitter's bootstrap library -- I built the website with it. It's pretty cool!
  • Generate a Javascript API layer in between. If you wanted to, you could pull the JS onto your own site and generate random names. Still working on this part.

In short, by the time I'm done, I intend to have a ridiculously overbuilt system for generating random names.

Tags: 

A Simple WMECO Outage Page

Those of you who live in the Pioneer Valley know that we have a decent amount of power outages. Our power company WMECO has a nice outage map -- but that's a big page to load when you're looking on your phone -- obviously your computer isn't working in a power outage. Also, for me anyway, the map doesn't load on my android phone. But even if it did, I would prefer a light page -- a list of towns with outage information is enough for me.

WMECO's map uses jQuery to hit a couple ASP pages on their servers to pull the outage data. I reverse-engineered the calls, and re-did them in PHP. This was actually a pain, mostly because using curl in PHP is new to me, and ASP is really particular about the parameters it wants. Anyway, here's my short and concise outage page, and below is the code used to build it. function load_outage_data() { $url = "http://www.wmeco.com/outage/services/OutageData.asmx/AllOutageData"; //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch,CURLOPT_POST,true); curl_setopt($ch,CURLOPT_POSTFIELDS,"{}"); curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type: application/json')); //execute post $result = curl_exec($ch); //close connection curl_close($ch); $result = json_decode($result); return $result->d; } // load_outage_data $outages = load_outage_data(); print "<ul>\n"; foreach($outages as $outage) { print "<li>" . $outage->Name . ": " . $outage->CustomersAffected . "/" . $outage->NumberOfCustomersServed . " (" . $outage->PercentageCustomersAffected . "%)</li>\n"; } print "</ul>\n";

Tags: 

Rorschmap

rorschmap is pretty awesome:

Rorschmap is cartographic navel-gazing, a reframing of the map. It will not help you find anything. We are bored with your squares and your margins. We want new shapes and new dimensions, the unicode snowmen of visual representation. †‡†, as the man said.

The word “kaleidoscope” is derived from the Ancient Greek καλ(ός) (beauty, beautiful), είδο(ς) (form, shape) and -σκόπιο (tool for examination)—hence “observer of beautiful forms”. It was invented by Sir David Brewster in 1815-17. Brewster was also active in the development of the lighthouse; both things were byproducts of his researches into optics. The light, refracted, serves both beauty and safety, both aesthetics and cartography.

Read more on booktwo.org.

Rorschmap - Canyonlands National Park

Rorschmap - Canyonlands National Park
(view on rorschmap.com)

Rorschmap - Statue of Liberty

Rorschmap - Statue of Liberty
(view on rorschmap.com)

It's fun to put your home address in, look at landmarks, and get lost in the data. I highly recommend checking it out.

Tags: 

Pages

Subscribe to RSS - Code