Wednesday, December 19, 2007

Simple Echo Bot in Java

Google Talk now comes with translation bots. While translation is fun, even more fun is to build your own bot! And with the Smack library, it's also easy.

As an example, here's a simple echo bot implementation in 40 lines:

public class EchoBot {

private final XMPPConnection conn;

// Simple bot that echoes incoming messages.
private EchoBot() throws XMPPException {

// Login as my-bot@gmail.com with password "my-password".
conn = new XMPPConnection("gmail.com");
conn.connect();
conn.login("my-bot", "my-password");

// Become available.
conn.sendPacket(new Presence(Presence.Type.available));

// Auto-accept all friend requests.
conn.getRoster().setSubscriptionMode(SubscriptionMode.accept_all);

// Echo incoming messages.
final MessageListener messageListener = new MessageListener() {
public void processMessage(Chat chat, Message message) {
if ((message.getType() == Message.Type.chat
|| message.getType() == Message.Type.normal)
&& message.getBody()!= null) {
try {
chat.sendMessage(message.getBody());
} catch(XMPPException e) {
e.printStackTrace();
}
}
}
};
conn.getChatManager().addChatListener(
new ChatManagerListener() {
public void chatCreated(Chat chat, boolean createdLocally) {
chat.addMessageListener(messageListener);
}
});
}
}

Feel free to re-use the code and go build something awesome!

Saturday, December 15, 2007

Reader becomes more social

You can now share items in Reader with your Google Talk friends. Check out their blog post for more info.

Wednesday, November 21, 2007

Sodertalje, a Swedish city of 80000, is this year accepting more refugees from Iraq than the US and Canada together, according to a Swedish newspaper (http://www.dn.se/DNet/jsp/polopoly.jsp?d=147&a=717715)

Wednesday, July 18, 2007

Sicko

I recently watched Michael Moore's new movie. I don't have the patience to write a review, but this one is pretty good. In short, I thought this was the best Moore movie so far. The subject is important, the stories interesting, some parts funny, and Moore doesn't do too much of confronting and ridiculing individuals but instead focus on the problem and the alternative of socialized health care.

Seeing this movie made me take a second look at the Social Security Statement i received earlier this week. The statement is straight forward. In the "Work to build a secure future..." paragraph, it states that one should not rely on Social Security as an only source of income after retirement and in "About Social Security's future..." it further explains that "the Social Security system is facing serious financial problems".

The interesting part is "Your Estimated Benefits". Here it tell me that I have 8 credits of work and what this buys me. "To get benefits if you become disabled right now, you need 9 credits of work". Guess I'd better not become disabled before earning that 9th point. It also tells me that if I die now a spouse caring for my child may get some monthly benefit and "may be eligible for a one-time death benefit of $255".

I don't know the details of the American health care system or any other countries' system, but this doesn't seem very good to me. While on the phone with a Swedish friend today we started talking about Sicko. My friend and his wife recently had a child so I asked about this. In this case the mother had stopped working 5 weeks before birth and was going to stay at home with their child for another 8 months. After that my friend was going to be a home dad for another 8 months. Needless to say he had a hard time believing me when I told him how it works over here...

In the movie Moore also talks about various health insurance companies, including the one I use. The stories are pretty scary. Luckily, I don't have much personal experience with these sort of things, but a friend recently had a bad experience. In short, he lost two teeth when punched in the face by a random drunk guy, fixed it and got a $6000 bill just to discover that his dental insurance had a "life time maximum" of $2000. This is the dental insurance provided to employees of Seattle's largest software companies.

Since this post is already is mostly random remarks and comments, I figured I'd toss in this funny clip of CNN challenging facts in Sicko:

Moore later responded on his web site.

Saturday, April 21, 2007



Biking around Bainbridge Island
Bainbridge provides 33 miles of paved road and pathways, lots of hills (over 2,000 ft. climb) and beautiful scenery. We had a great ride and were lucky enough to stay dry the whole time. If you'd like to go but don't have a bike, Gregg's Greenlake Cycles have rental bikes for $25 per day.

Sunday, April 15, 2007

Last week the Google Maps launched My Maps which lets you annotate maps. I tried plotting down the route from today's bike ride and it turned out pretty good. Once I realized that it was better to use the keyboard arrows and pg up/down to move around things got a lot easier. I also noticed that there are now more detailed zooming and 3d models of Seattle buildings. Good job Maps!

Saturday, April 14, 2007

Another creation from the same course: Simulation of Tree Blowing in the Wind.
And then there are a few others variations of winds, for example "very strong" and "ridiculous"...
Just found that this old artifact is still around. It's from a UW CSE graphics course I took in 05. This was one of the most fun courses I've taken, especially the ray tracing part. If you'd like to experiment, the tracer skeleton code is still available on the old project page.

Friday, March 30, 2007

An interesting story about a Chinese couple that are refusing to abandon their house is spreading in the sphere, read the (translated) interview with house owner Wu Ping, comments and the nytimes article.

Monday, March 26, 2007

Mercer Island Loop
Yesterday I biked around Mercer Island for the first time. The sun was finally shining again and it turned out to be a very enjoyable easy ride with good views, interesting houses, smooth curvy roads and few cars. Much better than my attempt to commute Seattle-Kirkland by bike on Google's Alternative Transportation Day earlier the same week. That time it was raining and when I finally got home I realized I'd left the apartment keys at work... Anyway, the Mercer loop is about 15 miles and accessible from both Seattle and the Bellevue side thanks to the I-90 bike lanes. Directions here.

Saturday, March 24, 2007

Boten Anna
Several American friends independently mentioned a pop song called 'Boten Anna' to me in the last couple of weeks. Turns out this song was a really popular in Scandinavia last summer and apparently it's still being played in bars. The lyrics are hilarious and the video below has English subtitles.

If you want to know more there's a detailed wikipedia article here.

Tuesday, March 20, 2007

Finally a somewhat sunny weekend in Seattle!
After several rainy weekends and a very wet attempt to bike around Lake Washington on Saturday the nice weather on Sunday was a great surprise. Some friends and I spent the whole day outdoors, running around Green lake, hiking up the Rattlesnake trail and playing soccer in Gasworks park. Not bad.

Mount SiThe hiking turned out to be the highlight of the day. I had never hiked this trail before but it was very rewarding considering the short drive and quick hike. From the top of the trail one gets a good view of the lake, Mount Si and North Bend.

The Rattlesnake trail is about 35 minutes from Seattle (I-90 exit 32, see map). The hike is easy and takes about 1 hour round-trip.
Go Gadget, Go! Last week we launced the Google Talk Gadget. Try it out here! Update: check out the cool firefox sidebar hack!

Sunday, February 18, 2007

Stevens Pass in January
A quick replay from the Stevens Pass public web cam in January. One second in the video represents one day (86400x speed-up).

Did you notice the tree branches bending up and down as snow accumulates and melts? The jump that is built and torn down? The snow falling off the fast moving clock? About half the days being cloudy? The night-time groomers?

Here's how the video was created:
  • Download images. A scheduled cron job downloaded the web cam image once every minute throughout January.

  • Select a subset of images. For 1s/day and 30fps I only need 1/48th of the images.

  • Remove duplicates. The web cam sometimes seemed to get stuck and not update the web image. I have filtered out images that are identical to the previous image to avoid having the video appear frozen at moments.

  • Stitch images into video. There are several tools for doing this, some better than others. The important thing is to use one that does not try to load all image data in memory up front. I found that RAD Video Tools worked quite well. The UI is not very polished but it's reasonably fast.

  • Add audio track. Something Windows Movie Maker can actually do :)

Sunday, February 11, 2007

NPEs and Static Analysis
Some days ago I was happily coding away when I stumbled over a bug in some Java code that I was using. More specifically I was getting a so called Null Pointer Exception, which is fairly common problem type. The funny thing this time was how long I had to stare at the one line of code before I saw the problem. The line contained several potential problems, but even a simplified example might look non-obvious...

  public void printWinner(String name) {
    System.out.println("The winner is: "
      + name != null ? name : "n/a");
  }


Do you see the problem? A quick code search shows that this bug exists elsewhere too. Now, if it's that easy to find a bunch of bugs like this, shouldn't there be a whole class of problems that can be detected automatically? Of course! Check out the Google engEdu tech talk on Static Analysis.

Monday, February 05, 2007


Visitor Stats for my Google Videos
4th of July fireworks254
Whistler ski action...249
Whistler Couloir Extreme128
Zero Gravity83
Bears in Bern II70
Night Riders63
Traffic49
Mt Rainer17
Adium 1.0A New Duck!
Last week Adium 1.0 was released (screenshots) - it's a really slick Mac client that handles a number of services: AIM, MSN, Yahoo!, ICQ, Google Talk and more. Love at first sight. You can download it from their webpage, where you also find help videos, a blog and xtras.

Monday, January 29, 2007

Photos from Corbet’s Couloir
A few of my photos from the famous and scary(!) Corbet's - closed at this time, probably because there's a big rock sticking up in the middle of the drop-in area. Click on a photo to enlarge it.

Wednesday, January 24, 2007

Corbet’s Couloir
Having just arrived in Jackson Hole, we started talking about tomorrow's skiing and looking at the trail map. Soon we got into talking about Corbet's Couloir - a very challenging and famous run on the Rendezvous Mountain. None of us had skied it, and most maybe none of us will, but the legendary run made us curios. Being geeks, we fired up the laptops and started searching for information and photos.

Unfortunately, we didn't find that many good photos, but the ones we did find were impressive and a press release about this year's opening of Corbet’s Couloir described it like this:
Corbet's degree of steepness is nearly vertical at the top, thus creating the need to jump into the couloir. The slope then “flattens” to 50 degrees. The overall average steepness is 40 degrees. The width of Corbet's is 40-50 feet within the chute, widening toward the bottom. The vertical drop of Corbet's is 500 feet.

Flattens to 50 degrees??!

Searching youtube showed that there's even a short movie: "Someday, Somebody Will Ski That" by Peter Pilafian (2006). The trailer shows a few clips from the drop-in.


Tomorrow's plan is to go to the edge, look down and turn around.

Sunday, January 21, 2007

My beloved iPod
...and what I don't like about it.

The most irritating "feature" is how difficult Apple makes it to recover purchased music after a hard drive crash. They could easily fix this by allowing users to download purchased media multiple times - that's how Google Video works. Another option would be to make it easy for users to copy music from the iPod to the new hard drive.

Some people might say that the solution is for users keep backups on separate hard drive (i.e. keeping a 3rd copy of the music), but that's more hazzle than most people want. Last time a hard drive crashed for me I had been out of the country for a few months and because of that I did not have a backup of my most recently purchased music. Since then I have not bought anything from the iTunes Store.

Another thing that irritates me is how the iPod displays music by Artist. Some artists' albums feature many other artists, and for these the iPod will display one line per unique combination of artists. I have for example row displaying "Jay-Z" and 19(!) rows that start with "Jay-Z Feat.". If I choose the plain "Jay-Z" option and then an album, the iPod plays the songs in the album that are "only" by Jay-Z, i.e. no featuring artist. When choosing "The Dynasty..." I get 4 songs, even though the album really contains 16. The only way I can play all songs is to go back to the top menu, display music by album and then choose this album.

This is bad user experience because many people think about their music in terms of artists, don't care much about who's featured on the different songs and don't know all album names by heart. Also, there's no easy way for me to play all my Jay-Z albums in a row.
Zero Gravity

Today's adventure with my visiting little sister was to go flying. I've recently gained interest in aviation and thought she should try it so I had her take an intro flight lesson. That means flying around with an instructor for an hour and learning a few things about the plane, a Cessna 172.

I brought my camera jumped in the back. The whole thing reminded me very much of my own intro lesson. The instructor very quickly went over checklists and explained the various instruments. I could see that my nodding sister couldn't make much sense out of this, as one would expect from someone who's never been in a cockpit before.

Once we got off the ground she got to take the flight controls and fly most of the time while the instructor handled the radio communication and made sure we stayed free of the sea-tac airspace and other planes. During the one hour of flying, we got a good view of Snoqualmie Falls and Seattle's surroundings.

The highlight of the flight was when the instructor took the flight controls and showed what zero gravity feels like. Below is a short video of it. You can see how the pen my sister is holding, and other things, start flying around. The beeping sound just before the dive is the stall warning horn going off.

Friday, January 19, 2007

Weekend in Whistler
My sister is visiting so we spent the weekend in Whistler with some friends. Here's a short clip from Blackcomb's Couloir Extreme.
Funny note: Couloir Extreme was originally called "Saudan Couloir" by locals, but extreme skier Sylvain Saudan complained about the unauthorized use of his name so the company simply changed it. (source: wikipedia)

Wednesday, January 10, 2007

Snowy Seattle...

...almost 3 hours to get home...
iPhone announced at Macworld 2007

- Recording of Steve Jobs keynote speach (quicktime mov).
- Minute-by-minute coverage.

Wednesday, January 03, 2007

Tuesday, January 02, 2007

BitTyrant
"A selfish BitTorrent client that improves performance"

Modified version of the java Azureus BitTorrent client. Downloads for Win, OS X and Linux.
http://bittyrant.cs.washington.edu/
Spaghetti Accident?
When setting up this blog I created a Google Analytics account as a simple way to track traffic. Today I looked at it for the first time and as expected there's not much traffic. In fact, there's so little traffic that my misspelling 'fettucino alfredo' are among the top five search terms of all time. This spelling seems to appear rarely on the web - my blog currently turn up as result #6 on google - but people obviously search for it. Maybe misspelling some word is a good idea if you're looking for traffic? (...how do you spell it anyway? fettucini? fettucine?)

2006-02-05. Breaking news! Google's webmaster tool now reports that cokementhos is even more popular!