Thursday, December 27, 2007

The absolute crux of AJAX. A short, short tutorial.

I've been unbelievably busy this past month so I haven't had much time to post any of the things I've been doing. I did, however, have to learn a little AJAX in order to complete a side project of mine. Since I found it a little difficult to find exactly what I needed easily on the web I wanted to share what I learned with anyone who might be Google-searching for how to write AJAX web pages.

First, a quick motivation for the problem. I want to give my user an entry form to tell me which country they are from. Once filled in, I want to populate a selection box for the region they are from, which of course depends on which country they select. After that I wanted them to chose the city. One really simple way to accomplish this is just to write out a list of all the countries, regions, and cities into a Javascript data structure. The problem is that there are more that 36,000 cities in the database I was using. Writing this all out to the user at once would make their browser time out.

What I really want to do is give the user just the countries to chose from first. Once they have chosen a country, I get the regions for just that country out of the database. Javascript doesn't have any database bindings and I don't want to have the user submit the page and have a new one come up for UI reasons.

What I want is for Javascript to go and ask the server itself. This is what AJAX is for. After reading a tutorial or two and picking out the pieces I needed, I found that this little snippet of code is all I need to do:

var req = new XMLHttpRequest();"GET", "getregions?countryid=" + countryid, true);
req.onreadystatechange = function () {
if (req.readyState == 4 /*complete*/) {
var data = eval('(' + req.responseText + ')');
... do something with data ...
req.send(/*no params*/null);

I simply create an XMLHttpRequest object. XMLHttpRequest is the Firefox version of the object. Different browsers require different objects, sadly. You can find out more about how to handle this problem here. Next I call the open method to connect to a script that I wrote to get a list of regions given a countryid. This program can be written in any language you want and acts just like any other CGI program. Instead of printing out HTML it prints out JSON. Most modern languages have a library for printing JSON or you can simply print it out using your own string building. You can learn more about what JSON looks like at

On the third line I set up an anonymous function to handle the network connection. It is called whenever the state is updated, waits until it's done, and then evaluates the JSON text into internal Javascript data. The function is then ultimately responsible for actually doing something with the data.

The readyState of the XMLHttpRequest object of course has more possible states than just 'complete'. If you'd like to learn how to deal with other states for make a progress bar or handling errors, then you can read more about the XMLHttpRequest object at w3schools.

The last line uses the send method to set the whole process in motion.

That's it. That's how AJAX and JSON work. Hopefully this tutorial will act as a decent spring board for anyone who wants to learn AJAX. There's a lot more out there of course and I've only really glazed over it. But if you need to get something up and running quickly this should do just fine.

Thursday, November 22, 2007

I have ended world hunger

I'm a computer programmer by trade and more importantly I'm a problem solver by nature. When I am presented with a problem, however minor, I can't help but try to think of ways to solve it.

Two weeks ago I posted an entry called "You are the paramount computer technician without letup!", wherein I wrote a program, called PamFRI, to solve a problem that my friend, Pam, was having with her keyboard. I got a lot of comments from people claiming that the program was "useless". The program solved a problem that only one person had and she wouldn't even have the problem the on following day. Furthermore, it didn't even actually solve the problem since it's impossible to use the program if you have the problem. Alright, to be fair it was me that said all those things but I just can't handle criticism, regardless of how self-inflicted it may be.

Feeling like my reputation as a computer programmer was on the line I knew I had to rewrite the program. This time I decided to be a little more ambitious and end world hunger.

(planet "" ("neil" "csv.plt" 1 1))
(planet "" ("lizorkin" "sxml.plt" 1 4))
(planet "" ("neil" "htmlprag.plt" 1 3))
(planet "" ("schematics" "macro.plt" 1 0))
(only (lib "" "srfi") list-index)
(lib "" "net")
(lib "" "net")
(lib "")
(lib "")
(lib ""))

(define thesaurus
(let ([table (make-hash-table 'equal)]
(open-input-file "mobythes.aur")
'((separator-chars . (#\,))
(strip-leading-whitespace? . #t)
(strip-trailing-whitespace? . #t)))])
(let loop ([line (get-line)])
(unless (empty? line)
(let ([word (first line)])
(string-lowercase! word)
(hash-table-put! table word (rest line))
(loop (get-line)))))

(define (post url data)
(string->url url)
(string->bytes/utf-8 (alist->form-urlencoded data)))))

(define (check word options)
(lambda (synonym ans)
(if (member synonym options) synonym ans))
(hash-table-get thesaurus word (lambda () empty))))

(define ((sxpath/f path) sxml)
(first ((sxpath path) sxml)))

(define (answer page)
(let* ([words ((sxpath "//div/div/ol/li") page)]
[word ((sxpath/f "strong/text()") (first words))]
[choices (map (sxpath/f "a/text()") (rest words))]
(aif ans identity (check word choices)
(list-index (lambda (e) (string=? e ans))
(random 4))))])
(cons 'SELECTED answer)
(map (lambda (tag)
(cons (string->symbol
((sxpath/f "@name/text()") tag))
((sxpath/f "@value/text()") tag)))
"//input[@type='hidden' and @name!='SELECTED']")

(let loop ([data empty])
(let ([p (post "" data)])
(write ((sxpath "//p[@class='vocabLevel']/text()") p))
(sleep 10)
(loop (answer p))))

Inspiration for this program came last week, right after I wrote PamFRI. One of my coworkers, Fred Henle, sent out a nice, little time waster know as Free Rice to the developers' mailing list. Free Rice is a non-profit web site where users are given a vocabulary quiz. For every answer the user gets right, the organization donates ten grains of rice to third-world countries through the UN.

Moments after Fred's email, Ben Mathes responded with his solution to end world hunger: a link to As soon as I got Ben's mail it was pretty obvious to me what I had to do. "I can automate that!" I thought to myself. I had just written PamFRI, which uses a machine-readable thesaurus and PLT Scheme has a really nice web-scraping module on Planet. With only a few more lines of code I could modify my original program to grab the web page, read and answer the question, and then post it back. Calling such a program in a loop ought donate a lot of rice and would, at least in theory, end world hunger.

It's probably not advisable for me to encourage my readers to run this program since it generates a page hit to Free Rice once every ten seconds. If everyone one of my readers ran this program at the same time it could generate up to five page hits to Free Rice every ten seconds. On second thought, maybe that's not so bad. My friend, Trevor, points out that the real danger is when the OLPC project really takes off. We'll have ourselves a veritable DDoS attack if this program were to get into the hands of the kids who actually benefit from the rice donations.

On a serious note, the real reason I wrote this entry is to let people know about Free Rice and encourage them to play for real. I also wanted to show how darn cool the webscrape functionality is in PLT Scheme in case anyone has any need for it.

Monday, November 19, 2007

Six Degrees of Wikipedia is On Line

Last month I posted an entry called Six Degrees of Wikipedia, where in I started playing a game in which people try to find the shortest path between two given Wikipedia pages. My friend Colin made a random node generation script and yesterday we created a new web site where we will administer the game. Periodically a new challenge to connect two Wikipedia pages (by Wikipedia-internal links) will be issued. The first one is already up, so get cracking. The winners will be announced when the next challenge is release. Enjoy! Oh and hey, no editing the pages so that your path works.

Extra credit for people who write solvers or know how to use Google to find such things. :) I mean the Kevin Bacon game is still fun despite the existence of solvers, right?

Go to: to play.

Friday, November 9, 2007

"You are the paramount computer technician without letup!"

Have you ever you spilled water on your keyboard? Have you ever shorted out the F, R, and I keys on your iBook all at once? Have you ever had to chat under such circumstances because you couldn't get an appointment at the Apple Store until tomorrow? Is your name Pamela Worth? Are you chatting with me right now on instant messenger? Maybe it's time you tried the latest in useless technology. That's right, maybe PamFRI is perfect for you!

Earlier today I was talking to my friend, Pam, on line and she seemed to be speaking rather funny.

me: How are you?
Pamela: well, apart from not hav1ng some very important letters not working...
me: You're 'i' key is broken?
Pamela: 3 keys
f, r, i
Pam has app't 2moro to see Mac "gen1uses"
me: How did it break? Mysteriously?
Pamela: not so Mysteriously.
1 sp1lled a small amount of H20

Intermittently a few of her keys would not work so she was resorting to l33t speak, cutting and pasting my own words back to me, using chemical formula abbreviations, or simply referring to herself in the third person. So I did what any good, overly nerdy friend would do in that situation.

grep -vi "[fri]" /usr/dict/words | mutt -s "Here's a list of words that don't use F, R, or I" [Pam's email address]

But as you can probably imagine, a list of all of the words in the English language that don't use the letters F, R, or I isn't all that useful. For starters one would have to search the entire list of words and the definitions aren't even there.

I simply had to do more to help the poor girl, so I helped how any good, super geeky friend would help. I made a small program that uses a machine readable thesaurus from the Moby project to accept a sentence that you want to type, as well as a list of keys that are broken. The program searches the sentence for any uses of the broken keys and swaps them out for suitable synonyms that don't also use the broken keys. In the event there are no suitable synonmys, the word gets printed out with square brackets. I call it PamFRI.

If you're wondering what the above paragraph looks like without the letter's F, R, or I:

Ego absolutely had to do on and on to help the debased dame, so psyche helped how any good, hot geeky bosom buddy would help. Monad made a small agenda that uses a jalopy plumbable cache ex the Moby lay plans to accept a sentence that you want to type, as well as a levy about jolty keys. The keynote speech looks down the sentence so as to any uses about the wobbly keys and swaps them out because plenty good enough synonyms that don't also use the quelled keys. Gangplank the event no seasonable synonmys can be etch, the vow gets typeset out amongst yes-man [brackets]. One and only call the goods [PamFRI].

(planet "" ("neil" "csv.plt" 1 1))
(lib "")
(lib ""))

(define thesaurus
(let ([table (make-hash-table 'equal)]
(open-input-file "mobythes.aur")
'((separator-chars . (#\,))
(strip-leading-whitespace? . #t)
(strip-trailing-whitespace? . #t)))])
(let loop ([line (get-line)])
(unless (empty? line)
(let ([word (first line)])
(string-lowercase! word)
(hash-table-put! table word (rest line))
(loop (get-line)))))

(define (suggest badchars sentence)
(lambda (aword)
(string-lowercase! aword)
(if ((typeable? badchars) aword)
(replacement badchars aword)))))

(define ((typeable? badchars) aword)
(not (regexp-match
"(?i:[" (list->string badchars) "])"))

(define (replacement badchars aword)
(let* ([synonyms
thesaurus aword (lambda () empty))]
(filter (typeable? badchars) synonyms)])
(if (empty? replacements)
(string-append "[" aword "]")
(list-ref replacements
(random (length replacements))))))

You call the program like this:

> (suggest '(#\h) "hello my name is")
"salutation my name is"
> (suggest '(#\h #\n) "hello my name is")
"kiss my itemize is"
> (suggest '(#\i) "I like the program very much")
"superego respect the program very much"

So if you're a clumsy, water drinking, Apple computing, debased dame, fear not. Help is on the way. You can download the program here in a zip format complete with the thesaurus. The program requires Dr. Scheme to be opened which is availible for Linux, Mac, and Windows.

By the way, I fully intend to continue calling them 'yes-man brackets'.

Thursday, November 8, 2007

I'm a grown-up now

A little more than a year ago Randall Munroe, author of XKCD, posted a comic, called Grownups, about a girl filling her apartment with playpen balls. The girl in the comic offers no explanation as to why she's done this, other than the fact that she's a grow-up now and it's her turn to decide what being a grown-up means. The whimsical web comic has often portrayed a state of mind that hits very close to home for me and this strip wasn't an exception.

I'm impulsive so I started looking on line for playpen balls the following weekend and quickly learned the same thing Randall did. Filling one's apartment with playpen balls, for any reasonably sized apartment, or even a tiny dorm room, would cost well over a few thousand dollars. Determined to have a ball pit, I decided I would cordon off the bottom of my lofted bed and make a ball-pit underneath. The lofted bed is a nice big queen-sized bed so the pit would be about 5'x7' with about 5' head clearance.

Using an on-line playpen ball volume calculator (inspired by the XKCD comic itself) I found that making a 5'x7' ball pit 2' deep was a pretty tractable goal. With a little help from my friend Sue I was able to find two ebay auctions for 700 and 800 balls from the same seller. The orders totaled about $160 counting shipping, which by the way made up more than 40% of the cost.

I placed a bid and week or so later I received the largest delivery I'd ever received as well as an endearingly spastic but uninformative voice from my roommate attempting to describe exactly what had happened to our front porch while I was gone. "Hey! Mike! Oh my god there's, like... the porch is totally gone. They're huge. These all have your name... I can't... do want me to... Holy crap." Remembering my order from a week ago I figured that was probably what she was talking about so I went home to bring them in.

On the Saturday after the delivery arrived, Sue and I went to Home Depot, the toy store for grown-ups who think the word grown-up has been ill defined. After some careful consideration we decided to pick up a reel of plastic garden fencing, zip ties, and you guessed it, some PVC pipe.

The lofted bed was already up against two walls so I just needed to gate off the other two. One wall, the short one, I decided to completely cover with the garden fence. The long wall I made the entry way, so it has a short wall made of a PVC frame and garden fence which is easy to step over.

That Saturday night Sarah came over and Sue, Sarah, and I sat in the ball pit for nearly five hours talking and laughing uncontrollably while throwing balls at each others faces. It really is quite amazing how long throwing balls at your friends' faces can last without getting boring. When it did we just lounged around and chatted until someone decided it was again time to throw balls at each other's faces. As the night winded down Sarah took great joy in completely burying herself and Sue made sure that both of us had heard every possibly innuendo involving the word balls.

Later in the week my improv troupe came over to practice and we ended the night with a really loud and rowdy ball pit fight where in most people just threw balls at Tony while Tony scrambled to bury his face and anything else fragile under a thick enough covering of playpen balls. My more obsessive compulsive friends came over the following weekend and we shorted the ball pit in spectrum order. To be fair this project also started with throwing balls at each others faces when I decided that Mike could only throw blue balls and Trevor could only throw red. This created a really nice visual effect so we ran with it and Lisa took some pictures.

I guess what I've learned from all this is simply that if you are going to go through the trouble of making a ball pit in your apartment just realize that all your friends are going to want to do is throw plastic balls at your face. Recently I moved and decided to make a video of the reconstruction of the ball pit.


Wednesday, October 10, 2007

Six Degrees of Wikipedia

Last night, Sarah and I were watching an episode of Northern Exposure when I noticed that the door to the local radio station displayed "KBHR 57 AM". From what I knew of AM radio, the range used by commercial stations in the US was in the upper hundreds to thousands, nothing near 57. So I looked up Amplitude Modulation, AM, on Wikipedia and soon found I had to click on AM Radio to get the answer that I wanted.

I started thinking about all the long link chains I've followed in the pursuit of useless knowledge and about that XKCD comic about wikipedia surfing. So naturally my next inclination was "I wonder how many clicks it will take me to get to Kevin Bacon's wikipedia page. Honestly, I thought it would take longer than it did. Little did I know there was a link to the movie Titanic on the page for the United States. I never would have guessed. This is what we did:

Amplitude Modulation to AM broadcasting to United States to Titanic to Leonardo DiCaprio to Catch Me If You Can to Tom Hanks to Apollo 13 to Kevin Bacon

Can anyone do it in fewer moves? I bet there's a shorter route if you don't take the easy way out and go straight for the nearest link to a Hollywood movie. I think this game has some potential as a non-movie-centric version of it's namesake. Okay what you lazy readers need now is a challenge. Hang on.

Me: "Trevor, Brian, think of a topic that you could look up on Wikipeida, but don't say it."
Trevor: "Got one."
Brain: "Alright."
Me: "Okay, what are they?"
Brain: "King Arthur"
Trevor: "Sickle Cell Anemia"

King Arthur will be the starting point since this game isn't commutative like the Bacon game. Post your best answers to the comments.

Wednesday, September 26, 2007

How I Accidentally Joined a Bike Gang

Late last Saturday night Pascal and I were riding through Davis Square, heading to a party, when a fleet of intergalactic transport ships flanked us at a traffic light.
"Hey, nice bike!" said a Skunk, four feet above me.
"Thanks. You too!" I said as I looked up to admire his Cloudbuster.

"Now these are my people." I thought to myself as the light turned green and we all rode down Elm Street. We got to talking about bicycles, art, how to make PVC hinges, and the finer points of welding a disco ball to ones handlebars. They had plenty of questions for me and I for them.

I dropped back a little and met up with the fleet's tailgunner, Dozer, who explained to me a little bit about how the organization works. A lot of people know about or at least have seen SCUL around Somerville and Cambridge. They're a non-profit, artistic, bicycling, nerd gang based in Somerville, MA. They have missions once a week on Saturday nights which launch from a secret base and head off into the galaxy, blasting dance music from the fleets flag ship.

"The way it works is that you get invited to join by a member who's willing to sponsor you." Dozer explained while Pascal took notes. "You become their maggot for your first ride and your sponsor shows you the ropes dur... hang on." She banked quickly off to the right to pick up a set of brief, metacrapal connections at a high-five refueling station that materialized on the sidewalk near Porter Square's White Hen Pantry.

As we road on through Harvard Square collecting more high fives, cheers, and car horn blasts I learned about Operation Back in the Saddle Again and their objective for the night. The fleet was destined for Riverside subway station, the end of the Green Line's D branch, out in Newton, MA. The objective was to catch a glimpse of the stations planet Pluto model installed by the museum of science.

We road on through the night, out to Watertown, MA to a 7/11 to collect juice and candy bar rations for the mid-flight pit stop. We also had to make a few repairs. One of the maggots, Dishpan, altered the crew that her ship, War, had a wobbly wheel. Now, a little wobble never hurt anyone, but with a name like 'War' and three-foot ramrod mounted to your front, a wobbly back wheel can totally destroy your street cred. Threespeed, the fleet's resident mechanic aboard Starhustler, got out his tools and gave War a little once over. Dishpan then road three-quarter speed into a chain link fence head on with the ramrod repeatedly until she was satisfied that War had regained his original gusto. I went to talk to Skunk.

Skunk and I discussed hacking and the DIY community for a while and I was invited to next week's mission to a non-disclosed location which will be of particular interest to a hacker electronics geek like myself.

Now if you have good reading comprehension you've probably been think to yourself this whole time "Didn't he say he was headed to a party? How much time has passed since the beginning of this story?" Well yes, I was headed to a party, a party back in Davis Square no less. About an hour or two had gone by during our ride and pit stop and I was expected hours ago. So I bid my new friends good bye and wished them much luck on the remainder of their journey.

I've been instructed to send Skunk and email for more information and Dozer said she'd be happy to sponsor me on my first ride. I'm pretty excited and looking forward to exploring the galaxy in style next week; we'll see how it goes. The import thing to take away from this story is that I will soon be in a bike gang. One with secret meeting spots and all sorts of midnight shadiness. Needless to say I am certainly no longer someone to be trifled with.

Wednesday, September 12, 2007

Dr. Scheme, you complete me

My roommate, Amy, has been doing an indexing project for a company as a private contractor. The job involves a lot of data entry so I ask, as I always do, if there are applications for custom software in the project. Nothing bothers me more than seeing people doing work that a computer could be doing.

I wrote a program to aid in her data entry which included a quick, hundred-line hack to do auto-completion. I sent it to my friend Jacob for comments who sent it to his adviser Robby, who was my adviser when I worked full time as a research assistant for the PLT. Robby had a lot of suggestions to make it a lot prettier and lot more user-friendly, all of which Jacob has since implement.

After Jacob's handy work the code went into the core DrScheme framework. Auto-completion was one of the most requested features for Dr. Scheme so we're all pretty excited that it's finally in there. Robby posted a blog entry to the PLT Scheme Blog announcing the features and there was much rejoicing. A party was thrown, prizes have been awarded, two volcanoes erupted, and parade is planned for next Sunday.

Monday, September 10, 2007

How to Make Friends

This past weekend I went to Home Depot with a tape measure, some written measurements, and the intention of getting shelves for my closet. But as usual, I ended up wasting a lot more time than I should in the plumbing section. Literally four hours went by as I played with various PVC connectors like five-year-old at Toys R Us. I decided to take a break from setting up my new room and what better way to do this than to build a life-size stick figure out of PVC pipe to ride on the back of my tandem bicycle?

I walked around the aisle, measuring my arms, legs, and torso, drawing pictures, and laying pipes out on the floor in a roughly humanoid form.
"Do you need help?" one employee asked, choosing his words diplomatically.
"Yes", I said. "Do you have cross-joint for one-inch by half-inch by one-inch by two-inch PVC?"
"I doubt it, considering the way water flows. We don't carry every piece so it's hard to find things that aren't used for typical plumbing setups." He looked down at my head on a stick "And that is clearly not plumbing related."

I adjusted my plans accordingly, swapping out pieces in my drawings for the ones they actually carried in the store. Since I didn't know how big he'd need to be to fit properly on the bike I just modeled his sizes after my own. This is why his biceps are a half of an inch in diameter.

Later I went home to saw and cement together my new friend. After much deliberation with my roommate, Amy, we decided to call him Pascal Vanderbilt Chesterfield. I think it's a pretty fitting and dignified name.

Having a tandem copilot automaton around has a lot of benefits that you might not realize. I can finally ride in the carpool lane when I'm biking to work on i93. If none of my friends are around to go for a ride on the weekends I can still go without looking completely ridiculous. It's a lot less awkward if I meet a girl at a bar and she has a friend made of PVC. And best of all, he can wear the backpack instead of me. Now I just need to teach him how to signal.


Wednesday, September 5, 2007

I am the sixteenth silliest thing on the Internet

We've all heard the old saying in it's many variations. "That guy is so silly that if you looked up the word 'silly' in the dictionary you'd find his picture." Now I'm a pretty silly guy so people have certainly said such things about me, but if you look today in the OED you're still not very likely to find any reference to me. However, if you do a Google Image search for the world 'silly', you will, in fact, find my picture on the front page at number sixteen*.

My friend, Adam, recently had need for some silly images and stumbled upon a picture of our friend Char and I, picture number one on page two of the search results. After he sent us an email with this announcement of our new-found fame we moved five places onto the prestigious first page.

This silly picture was taken by Char's boyfriend, Owen, at a pool party I had and subsequently posted it to his apparently well-indexed, highly-linked photo blog. Google's page ranking being the infallible, acid test for Internet poplar opinion that it is, I think I can safely declare that Char and I are the number sixteen most silly thing on the Internet.

* Google page rankings being as fickle as they are, this number is likely to be changed both by the time this is posted and also as a result of it being posted.

Partial Evaluation

My friends Jacob Matthews and Dave Herman are working on a paper about a technique for compiler optimization. The following technique for partial evaluation came up last night while I was talking about it with our friend Ryan Culpepper. Ryan seems to think this wouldn't get excepted to POPL for some reason. Some silliness about needing to get a value back.
(define (partial-evaluator program)
(let ([t (thread (lambda () (eval program)))])
(sleep 1)
(kill-thread t)))

Wednesday, August 29, 2007

Trebuchet Part IV: Next Saturday in the Park

We've been flinging a lot of baseballs over the last couple of weeks so everyone is now well practiced in the art of catching baseballs. Coupling that with an abundant access to baseballs gloves, it's become pretty obvious that flinging baseballs no longer has the high probability of injury that it once did. To fix this we decided to fling some different things from the trebuchet this week. Brett was kind enough to donate some things from around the house: a tennis ball, a street-hockey ball, a golf ball, and a can of tuna fish. As it turns out, cans of tuna fish are nearly indestructible.


Later in the day a man walking through the park with his dog decided to stop off in our little corner of the park to outsource his dog-toy-throwing responsibilities. We placed Trevor next to the trebuchet to making a throwing motion with his arm. After the dog learned to follow Trevor's lead, and not run straight into the trebuchet after it was released, we played fetch for a little while. I'm not sure if the dog realized where the ball was coming from but I think the dog must have had some vague notion of "Gees, these guys throw much further than my master." Nothing tires a dog out like 300-foot fetch. We gave her some of the water that we had left and she and her master headed on their way.


Later on, we sent a bunch of people to the store to get Diet Coke and Mentos because we thought that would be a fun thing to fling up into the air. The idea was to put a ton of Mentos in the bottle, but seal it off before they touched the Coke. As it turns out, cans of tuna are not the only thing on the indestructible list.

You see all those videos on the Interwebs of Diet Coke and Mentos have a little hole cut in the top for the soda to shoot out. The amount of gas produced turns out not to be enough to actually rupture the bottle. Which is probably a good thing since we didn't realize that putting something as heavy as a Coke bottle in the trebuchet requires recalibration of the release nail if you don't want it to fly straight up and come right back down on you.


Discounting all of the failures I feel the day was a pretty big success. You're never a failure if you define success late enough.

Sunday, August 26, 2007

Trebuchet Part III: Saturday in the Park

On Saturday some friends and I went to the park for the first full day of trebuchet baseball flinging. For most of the morning it was Brain, Jackie, Jackie's dog, and I working out the kinks. Trevor, Sarah, Colin, Adriana, Lisa, and Brett all showed up at some point during the day too.

A good deal of the morning was spent taking video of the trebuchet from the side as it was firing and playing it back in slow motion to see exactly what was going on. When we started, the balls were mostly going line drive, 75 feet out. After watching some slow-motion video it was pretty apparent that the sling was releasing way to late. So we bent the nail way back until we got it just right. This actually accounted for about a 100-foot increase in distance.

Another really nice improvement we made was make a new sling. We cut a big square out of some stiff denim pants, also bound for Good Will. We attached the sling at four points to the rope, rather than just two. This turned out to be a lot more consistent than the design we found on the original trebuchet plans.

After all the mechanics where tweaked we added a giant rock that Brian went hunting for around the park. The rock added quite a bit of weight to the bucket. So much so that the bucket started scraping the ground whenever it came down, and eventually bent the rod so much that it broke off. Next time we'll have to reinforce the hanger better.


Trebuchet Part II: The Thursday Test Run

Thursday night I packed up my car full of trebuchet parts and projectiles only to find that the two A-frames are too big to fit in my little VW Golf. So I did what any reasonable person would do in that situation; I gave one to Colin, one to Trevor, and explained to them, in less detail than they would have liked, how to get to the park.

The rest of us got to the park early and scouted out a spot to test our brand-new, medieval siege toy. We decide on a quiet little spot next to a volleyball game at the corner of the park. We figured here we would be out of the way of the big soccer crowds who might get a little suspicious and call the park authorities. As it turns out, we were being a little more paranoid than was necessary. The volleyball crowd showed a lot of interest in our test runs and later, the park ranger walked right by us as we were setting up our ten-foot, projectile weapon of plasticness.

After the first few throws went backwards, sideways, straight into the ground, and nowhere at all we finally got the hang of it. We adjusted the string lengths, made a new sling, and added weight. We got the baseballs going 75 feet or so--a far cry from our goal yet enough to get us all really excited about the following Saturday. We'll spend next Saturday in the same place, tweaking, test, and seeing just how far we can get this thing to go.

After it got dark we all went out for dinner at Jose's. This was pretty lucky because just as it was getting dark, it began to rain pretty hard. We walked over to Jose's, parked our giant A-frames just outside the restaurant, and went in to wait out the pouring and thundering. As luck would have it, it ended just before our dinner, making for a much more comfortable trip home for Colin and Trevor.


Monday, August 20, 2007

Trebuchet Part I: Buying and Building

A month ago I was down in Pennsylvania with Jeff at our friend Sean's house. The combination of the wide-open corn fields and the access to a scrap metal yard always makes me want to build stuff and launch projectiles. So we were at a BBQ, a little drunk, and I stood up and announce "Let's build something." It wasn't long before the words 'trebuchet' and '16-foot-tall-I-beams' also came out of my mouth. We left the BBQ all excited and scrounged around the metal yard until we found all the perfect parts. It's amazing what you can find in a scrap-metal yard. One-ton counter weights for fork lift, a ten-foot-tall metal platform, and, indeed, 16-foot I-Beams.

Now I know what you're thinking: that introductory paragraph has all the makings of a post that will eventually describe my death. But fear not, dear reader, for there is a twist in this plot. In short time, Sean, Jeff, and I realized that a weekend isn't very much time to put together three tons of metal, assembled twenty feet high, and not one of us knew how to weld. This came as a bit of a downer, but Jeff and I decided that once I got back from my road trip we would we would build a small, PVC-pipe trebuchet up in Boston, modest in size but big enough to fling baseballs hundreds of feet.

A few weekends later Jeff and I went to Home Depot to get all the parts. We stacked up a wheely cart with four ten-foot PVC pipes, about twenty connectors, a PVC saw, a couple of eight-foot 2x2's, a few thick metal bolts, a whole ton of nuts and washers, and one big, orange bucket. We were set, we were psyched, and we rush home to do some math.

We loosely followed a set of plans we found on line for a smaller, wooden, tennis-ball trebuchet. We were able to use the ratio of the axle height to arm length and the counter weight to projectile weight ration as well. We also took inspiration from the base design but needed to make a lot of adjustments. Firstly we were making a much bigger trebuchet and secondly, you can only buy 45° and 90° PVC-pipe joints and Home Depot.

We spent Saturday and Sunday morning measuring, sawing, drilling, putting things together, and solving all the little unforeseen problems. Plenty of people showed up over the course of the two days to help out so I was never lonely or in lack of people to do the drilling.

When all was said and done, we tossed all the tools into the bucket for a counter weight and tossed a roll of tape over my car, just to make sure everything looked good. It was late by this point and everyone had Sunday night plans so we agreed to meet on Thursday out in the park to give the trebuchet its first real test run. Stay tuned for Trebuchet Part II: The Thursday Test Run.