Racc Apr 1

I just came across Racc – a ruby implementation of Yacc. This is bringing back memories of my compiler course in college. I’m geeking out!

In college, I built a compiler for Pascal with Lex and Yacc. The project converted Pascal code to Lisp code and ran on Sun machines. It was pretty awesome. Sadly, I don’t have the code anymore, but I loved building it!

I started building a Mysql client in the web (think phpmyadmin but without the suck) and I have a need to parse SQL. Racc + SQL Parsing? Can there be anymore joy? Also, Racc’s runtime modules come with the Ruby standard library. How did I miss this?

Time to build a simple SQL parser in Ruby.

ActiveSupport's Array#sum Mar 3

I found a great use for ActiveSupport’s Enumerable#sum while browsing through the Rails source code.

Ever write code where you need to gather a flattened array of child objects from the current array of ActiveRecord objects? For example:

  class Post < ActiveRecord::Base
    has_many :categories

  class Category < ActiveRecord::Base
    belongs_to :post

  posts = Post.includes(:categories).all

  # Gather all the categories into one array using #collect
  all_categories = posts.collect { |post| post.categories }

  # Another way to do it with inject - no need for the #flatten call
  all_categories = posts.inject([]) { |sum, post| sum += post.categories }

The code is verbose. If you use Enumberable#sum you don’t have to write the inject or the flatten line:

  post = Post.includes(:categories).all

  # Gathers all categories into one array
  all_categories = post.sum { |post| post.categories }

You could also use the shortcut form of that block:

  all_categories = post.sum(&:categories)

My favorite part of the code is the use of the + operator and applying that to Arrays. Array + Array = Bigger Array.

rsync git modified files with awk and sed Feb 15

Need to rsync modified files to a server? Try the following:

All you need to do is ensure that the base path set properly and modify the user@remote.server.com portion of the script and you’re all set!

Explanation after the break.

Here’s the breakdown:

Display modified files the same way svn status does – line by line with a symbol in front to designate type of change.

  git status -s

This prints out the following:

 M www/path/to/file
 M www/another/path/to/file

Piped with the git call above, this will strip out everything fron the line except for the file path.

  awk '{print $2}'

This prints out the following:


With the file paths piped in via the awk command, add the rsync around it with sed.

  sed 's/\(.*\)/rsync -cav \1 user@remote.server.com:~\/\1/'

This prints out the following:

  rsync -cav www/path/to/file user@remote.server.com:~/www/path/to/file
  rsync -cav www/another/path/to/file user@remote.server.com:~/www/another/path/to/file

Finally, we pipe the sed call into sh which executes it.


Why 3D doesn't work and never will. Case closed. Jan 24


“But their eyes must converge at perhaps 10 feet away, then 60 feet, then 120 feet, and so on, depending on what the illusion is. So 3D films require us to focus at one distance and converge at another. And 600 million years of evolution has never presented this problem before. All living things with eyes have always focussed and converged at the same point.”

I strongly dislike 3D films but never knew why. Now I know.

The Last Leg Dec 16

Last I left off, I talked about bad fish and chips and Harry Potter. At the end of my London stay, I needed a break from traveling. I decided to head over to Dublin to visit a friend and hang out. After Dublin, I flew over to Edinburgh since it’s only an hour away. Both cities were very low key for me.

I took a train from London to Dublin. Rather, I took a train and a ferry. It took most of the day, but I arrived in Dublin and stayed in a hotel for my first two nights. My friend booked a hotel so that we could check out the downtown area without commuting 30-40 minutes from her house.

I told her I wanted to chill out, and she thought I was weird for taking a break while on a break. To be honest, I thought I was weird as well. But as any long time traveler will confess, site seeing and tour guides will tire you out. After six weeks of this, I was pretty beat. So, I don’t have much to tell you about Dublin. My friend mentioned significant buildings and different historic facts, but I didn’t pay attention. I just followed her to the next restaurant.

Speaking of food, Dublin food was mediocre like London. Although, I do love black and white pudding. The pudding is not what you’re thinking of. It’s similar to an American sausage patty in that it’s ground up patty of stuff. White pudding is made out of pork meat, bread, and oatmeal. Black pudding is made out of animal blood. They’re both delicious, but it seems everyone I’ve mentioned black pudding to found it disgusting. Maybe growing up with Vietnamese food made it easier for me to try the different types of food. Then again, I didn’t know that black pudding was made of blood until after I ate it and liked it.

Of course, while in Dublin, I tried the Guiness and it was good! I normally hate Guiness, but the Guiness I had here was different to the ones I’ve had in the U.S. Although, I was talking to a friend back in California, and he mentioned that it tasted the same. He had been to Ireland a month or two before I was. To test his theories, after he finished his vacation, he went around to local bars to try Guiness to see if there really was any difference. His conclusion was that they tasted the same. I could be wrong of course since the last time I’ve had Guiness was in college.

Oh, and yes, I went to the Guiness Storehouse. Here’s proof:

After a few nights in a hotel with my friend, she went back to her place and I stayed another three nights in Dublin in a hostel. During my stay in the hostel, Dublin snowed over. Walking on the streets of Dublin was dangerous after the snow. It was very icy and slippery. It was horrible after having a huge pint of Guiness on an empty stomach, but I made it back to the hostel just fine. It does look really funny when someone is about to slip though. I couldn’t help but laugh.

After Dublin, I flew over to Edinburgh, or tried to. I had an afternoon flight from Dublin to Edinburgh, but the weather in Edinburgh was worse than Dublin. It was snowing and was bad enough that my flight was cancelled. Instead, I switched to a flight to Glasgow and caught a train to Edinburgh afterwards. I really love trains. They’re the best way to travel. If the U.S. had a train network like Europe, I’d be all over it.

In Edinburgh, like Dublin, I took it easy. On the first day, I walked around the city and went to the castle. The castle was amazing and also free! Well, for the day I went it was free. It was a holiday and all visitors entered for no cost. I paid for the audio guide tour with my savings. The audio guide was extremely well done. Other than ancient Roman history, my next favorite topic was anything that related to the King Arthur and the Knights of the Round Table. Yes, I’m a dork. Anyways, the audio guide tour had great stories of the different battles at Edinburgh Castle. There were more stopping points in this castle than any other audio guide tour I’ve been on. I stood in the first area of the castle for at least 30 minutes before moving because there was so much content.

I also saw the Scottish Crown Jewels! No pictures of course, but the experience was wonderful. I entered a building housing the crown jewels and walked through a maze of different rooms before reaching them. Each room was painted with stories of about the crown jewels, who used them, when they were hidden, and when they were found.

The castle was definitely worth the visit. This was the only tourist site in my entire trip where I bought souvenirs. It was that good.

Just like London and Dublin, Scottish food was mediocre. Maybe it’s due to the weather, but British/Irish food tasted plain to me. Nothing to be excited about, but nothing to hate. It’s in the middle. I did eat haggish though. Just like black pudding, I ate it, liked it, and then found out what it was. You should look it up. I thought it was delicious.

Finally, I want to mention one thing that I thought was genius. I mentioned that it snowed in Endinburgh before I arrived. Well, it snowed most of the days I was there as well. Snow was all over the streets. On sunny days, it became slush. Now, as I mentioned, I stayed in Edinburgh for a week. And as I mentioned in a previous post from Italy, I hate wet socks. How did I overcome wet socks with the slush so prevalent? Well, I had extra grocery bags that I’ve kept on my travels. So, instead of buying some new shoes, I just wore the grocery bags around my socks. It was genius! It worked for half of the first day. It stopped working because the bags shifted under my feet, but I made adjustments and suceeded!

Finally, Edinburgh is pronounced Edinbra, Glasgow is Glasga, and Cockburn is Co-burn. Get it right Americans, otherwise you get laughed at.

I don’t have much to say other than that. So, here’s some pictures!

A fake bagpiper. Not annoying.

A real bagpiper. Very annoying.

Edinburgh castle near the entrance.

Edinburgh from the top of the castle.

The Royal Mile … the sign. This is the street that leads into the castle.

Cool room in the castle

That’s it for my trip to Europe! After Edinburgh, I went back to London, and flew back to the U.S. I plan on writing another post in regards to the cost of the trip, gear, and tips if you plan on making a similar trip.