Nicholas' Adventures

programming, politics, food, life

LSRC 2011 Summary

Opening Keynote

James Edward Gray II gave this year’s keynote. As expected it was a great presentation. (I have seen two other presentations of his in the past and they were both excellent.) James has a unique way of taking his own personal experiences and turning them into general life lessons. Two lessons presented in his keynote were: what is a keynote, and why do women put cabbage leaves on their breasts?

While James had nearly everyone’s attention talking about breasts and showing images of cabbage, we get an introduction (or re-introduction) to the scientific method and critical thinking. “Question, think critically and search for evidence,” James explained. He ends his presentation asking that we bring the science back into comptuer science.

A Dickens of a Keynote

Be Skeptical, Not Cynical

A skeptic doesn’t believe anything simply because someone declairs something true, or it’s popular, etc. However, unlike a cynic (who will always disbelieve something), skeptics form beliefs based on evidence. Cynics are those chronic complainers, you know the people who say “woes me the world is against me.” They rashly judge, are quick to complain and never offer solutions of their own.

Chad Fowler in the closing address set forth cyniscim as lazy, cowardly and weak. He spoke about the idea that everyone has customers (people you serve) and that we should all strive to providing the best customer experiences.

My personal war against cynicism can be found in my long-running Gmail signature:

“I always wondered why somebody doesn’t do something about that. Then I realized I was somebody.” –Lily Tomlin

Summary and Trends

This LSRC I enjoyed more the an the one last year. I think the topics were more relavent and fresh. There were also some really good presenters, many of them local Austinites. I noticed a few trends…

More Women

I think this is the first LSRC where I’ve actually noticed women. Now if you personally know me I probably just made your chuckle. What I mean by this though is that traditionally in the IT and programming space women are scarcely seen. Female programmers especially are a very rare breed. So it was really refreshing to see more women this year.

Women and minorities, in general, are poorly represented in our industry I think. It’s good to see this trend slowly changing, but it still has a long way to go.

Linux Laptops

At any Ruby related conference you’re pretty much going to see Macbook Pros. If you bring a Windows PC you’re going to be the brunt of jokes at the table, just be ready. This year I saw a few more PC laptops than in the past, but they weren’t running Windows. Instead they were running Ubuntu Linux. While I didn’t actually walk up to people and ask, they were running them on metal not VMs. (I decided this because many were using compbiz animation features which typically are not possible inside a VM.) So this is a trend to pay attnetion to, maybe.

Javascript

You go to a Ruby conference to talk about Ruby right? Well JavaScript had quite a few talks. Why? I think everyone is coming to the conclusion that you can’t ignore JavaScript.

There was a lot of debate about CoffeeScript and pure JavaScript. Should I bother to learn JavaScript, it’s so clunky, when I can just learn CoffeeScript? CoffeeScript is so much nicer to write, more elegant to read, etc.

Until CoffeeScript is more widely adopted we’re all going to have to know JavaScript. JavaScript libraries are not written in CoffeeScript, so if you want to know how they work – you’re going to need to know how JavaScript works. Same with debugging. Since CoffeeScript writes JavaScript, debugging code in your browser means you’re doing it by reading the JavaScript CoffeeScript produced.

I agree in a perfect world we should just learn CoffeeScript and be happy. The world isn’t perfect.

Ruby

Lastly, Ruby is an amazing language. Going to a Ruby conference you’d expect to come away with this, right? The one thing that particuarlly impressed upon me was the pervasiveness of Ruby in the Cloud. Rackspace, CloudFoundry, Engine Yard and Heroku are very Ruby centric. Marc Benioff tweeted “Ruby is the language of the cloud.” I’m starting to understand why he said that.

Pardon the Dust

With the economy being what it is, etc. I decided hosting with Joyent just wasn’t really worth it. They’re a great cloud provider, but for small time stuff – like my blog – it just didn’t make sense. I started with them a while back but I think they’ve out-grown me.

So I looked around for an alternative hosting provider. I like Heroku, but its read-only file system provides for some unique challenges. AWS (Amazon Web Services) are okay but can be expensive, although the first year is free. I’m already paying for a GitHub account and realized that I could just host a Jekyll website on my GitHub Pages. So that’s what I’ve done.

I’m using Octopress, and I’m pretty happy. I was going to write my own blogging software but then realized I really don’t have the time to do that. And why, since other smart people have done it! Expect more to come in the future. I’ve copied my most popular articles over. It’s hard to beleive I’ve been writing this blog since 2008! So I’ve heavily culled the article set.

Installing Sun (Oracle) Java 6 JRE/JDK on Ubuntu 11

In Ubuntu 11 it’s really easy to install Sun’s version of Java JDK (or JRE). Why would you want to do this?  Well, personally, I have found that the OpenJDK doesn’t always work quite exactly right with a lot of Java programs, so I prefer to use the Sun JDK (I guess it’s Oracle now).

To install simply do the following from your console:

sudo add-apt-repository ppa:ferramroberto/java
sudo apt-get update
sudo apt-get install sun-java6-jdk sun-java6-jre
sudo update-alternatives --config java

Then you’ll want to pick the Sun version of Java.  Now you’ll be using Sun Java whenever you execute the ‘java’ command.  You can also verify this by typing ‘java –version’ and you should see the HotSpot mentioned, instead of the IcedTea.

Blurry Fonts on External Monitor With MacBook Pro

I don’t know if you have the same problem as me, but when I plug my MacBook Pro into my HP w2338h monitor the fonts are not as crisp as on the laptop itself.  I found out that there’s a bug in how Mac OS X detects whether it should use font smoothing or not for certain external monitors. It’s not a problem if you’re using an Apple monitor (obviously their stuff works perfectly with their own stuff), but not all of us as so fortunate to shell out that kind of cash.

You can easily fix this by typing the following into your command line:

defaults -currentHost write -globalDomain AppleFontSmoothing -int 2

You can try int 1 to 3 (to play with various levels of font smoothing, I found 2 to work best for me).  To remove the setting just open the Appearance app (inside the Control Panel) and at the bottom you’ll see LCD font smoothing with a [-] inside, click it off and back on and it’ll show up as an [x] (and you’ll be back to where you started).

You may have to quit and restart your application before you see the effect.  I tested it out using my terminal application since that’s something I use quite a lot and not having nice smooth fonts in it makes me cry.

Nokogiri - Cut With Precision

Many times we as developers have to deal with complex data, be it an ActiveResource result set or a HTML/XML document.  Trying to parse data out of these using for each and nesting loops within loops can be cumbersome.  A more elegant solution is to use nokogiri and xpath.

Nokogiri is a type of Japanese saw, it also is a gem in Ruby that you can use to easily deal with XML or HTML documents.  (hint, ActiveRecord and ActiveResource objects both have to_xml methods).  You can easily install nokogiri (make sure you have libxml2 development packages installed, as the gem requires these to be properly built).

$ sudo gem install nokogiri

Now consider the following XML document: foods.xml

Before we can work with our data we need to read XML into Nokogiri. This is easy to accomplish:

> require 'rubygems'
> require 'nokogiri'
> doc = Nokogiri::XML.parse(File.read('foods.xml'))
=> #<Nokogiri::XML::Document:0x3f930c9db884 ...

What we are returned is a Nokogiri document which is a collection of Nokogiri elements and text objects. The document supports seaching (selecting a subset of nodes, or nokogiri nodeset) by both CSS selectors or XPath notation. These are returned as an array of elements and text objects.

So for example if we wanted to know all the names of the food items in our document we simply say:

> doc.xpath("//name").collect(&:text)
=> ["carrot", "tomato", "corn", "grapes", "orange", "pear", "apple"]

If we were interested in the entire node we could leave off the .collect(&:text). What if we wanted to select all the names of food items that were best baked?  This requires us to use what’s called an axis - we will first need to find the element “baked” but then go back up our XML elements to find which food the item is inside.

> doc.xpath("//tag[text()='baked']/ancestor::node()/name").collect(&:text)
=> ["pear", "apple"]

What if we were only interested in vegetables that were good for roasting?  Just add //veggies:

> doc.xpath("//veggies//tag[text()='roasted']/ancestor::node()/name").collect(&:text)
=> ["carrot", "tomato"]

What about if we wanted to know all the tags ‘corn’ had?  Again this is very easy:

> doc.xpath("//name[text()='corn']/../tags/tag").collect(&:text)
=> ["raw", "boiled", "grilled"]

We can even do searches matching the first character.  Let’s say we wanted to know all the food items that started with the letter ‘c’:

> doc.xpath("//name[starts-with(text(),'c')]").collect(&:text)
=> ["carrot", "corn"]

You have to admit this is pretty cool stuff.  You could also use [contains(text(),’rot’] and get back just carrot, useful when you want to do a partial match.  Axis combined with selectors give you a wide variety of options for parsing your dataset.  You can also match using operations.  See the links below for resources on the variety of options available.

Xpath is Powerful

Xpath lets us select XML elements, attributes and text without having to write cumbersome recursive, nested loops. Below are  links to online resources and tutorials.  The next time you have to dig through an XML document or ActiveResource result, don’t use recursive, nested loops; instead, consider a Japanese saw - nokogiri.

Learn More