Bibletech Presentation March 16, 2013

Yesterday I gave a talk at this year’s Bibletech Conference, here in Seattle. I talked about a project I’ve worked on for a good part of the past year relating to using NoSQL (we’re using DynmamoDB) for storing user Bible annotations. The talk went OK. The content was interesting to me, and I hope for some of the conference attendees. Here are my slides for the presentation.

Comments

Funny Little Server March 4, 2013

I’m not going say to much about it yet, but I was really itching to have a small server in my house. I started looking into really small form factor computers, then used computers on ebay, but they all seemed way to big and I thought “My old iPhone is faster than that.” That’s when I had a realization. Originally I wanted to install Debian on my iPhone, but that didn’t seem possible. But I found that if I jailbroke it I could actually do quite a bit. So here’s my new server and some stats about it.

  • ~1GHz Arm processor

  • 64GB Solid State Drive

  • Nginx proxying to:

    • Lighttpd with PHP 5.4
    • Sinatra running on Ruby 1.9.2 and Thin
    • Node.JS v0.6.14
  • MySQL 5.1.66

iPhone4 Server

I might post more about this once I start using it more. For now though it was just a fun experiment.

Comments

2012 Favorite Albums December 15, 2012

My Top 10 Favorites

  1. Jherek Bischoff - Composed

    I have a lot of reasons to love Jherek Bischoff’s album, Composed. First, he’s a Seattle musician, and I enjoy finding great local music. Kate and I saw him live recently, and I find seeing a musician live really does help me appreciate their recorded music. It’s a beautifully composed album with lots of great talent on it like Zac Pennington from Parenthetical Girls, Mirah, David freaking Byrne from The Talking Heads, and a bunch of mostly Northwest musicians. But one of the biggest reasons I love this album is because of the story of how it was made. Jherek was a ukulele playing musician who wanted to compose songs for a full orchestra. He didn’t know how to though, so with some help from a few talented friends, he learned. But he didn’t have an orchestra to perform his pieces. So he visited a bunch of his friends, recorded them in their living rooms, and layered them all together. The result was Composed.

  2. Sharon Van Etten - Tramp

    There are also lots of great musicians on Sharon Van Etten’s Tramp. There are 2 tracks with some vocals by Beirut’s Zach Condon. Also on the album is Wye Oak’s Jenn Wasner, Julianna Barwick, Walkmen’s Matt Barrick, and it was produced by Aaron Dessner (from The National) and recored in his garage. Here’s a connection that I kind of love, Justin Vernon (Bon Iver) performed the song “Love More” off Sharon’s previous album at the 2010 MusicNOW festival in Cincinnati, which Aaron and his brother started and curate. I know, because I was there :) Then the next year Aaron produced and records Sharon’s next album.

  3. Twin Shadow - Confess

    Chris Taylor from Grizzly Bear produced George Lewis Jr’s 2010 debut album which was really good, but his new album is better. Produced by himself, you really get a sense of his style. Lewis was born in the Dominican Republic, raised in Florida, and is now living in Brooklyn. This album sounds like it came from the 80s. And it’s great! My favorite song is the 3rd track, “Five Seconds.”

  4. Saint Etienne - Words And Music

    Words and Music is a British pop treat. The first track’s spoken word is a great intro to the album and its theme. If you enjoy this album, check out some of their older stuff, like their 1991 album Foxbase Alpha.

  5. Cat Power - Sun

    This is Chan Marshall’s first album of original songs since her 2006 album, The Greatest. I’ve read a bunch of interviews and articles about the making of this album but to be honest I don’t really understand it all. There are a lot of details about how she recorded the songs and didn’t like them and ran out of money and rerecorded and did another album… I don’t really understand what became of the songs and recordings she was working on for the past 6 years, how much of this album she wrote right after The Greatest, and how much stuff she wrote but never used. All I really understand about it all is that this was an album that took a long time to make and the result is a really great album by a great musician of our time.

  6. Moonface - With Siinai: Heartbreaking Bravery

    Moonface is Spencer Krug (Wolf Parade, Sunset Rubdown, Swan Lake) most recent indie rock project.

  7. Mirel Wagner - Mirel Wagner

    Mirel is a 23 year old indie folk musician, born in Ethiopia and raised in Finland.

  8. Dark Dark Dark - Who Needs Who

    Dark Dark Dark is a jazzy folk band. My favorite fun fact about them is their website is brightbrightbright.com.

  9. Chairlift - Something

    Chairlift is probably most significant for their song “Bruises” from their 2008 album Does You Inspire You, which was featured on an Apple commercial. It was certainly the strongest song on that album. This album is strong all the way through. Different but similar to Twin Shadow, it has a very 80’s feel to it.

  10. Jens Lekman - I Know What Love Isn’t

    Another stellar album from an amazing Swedish indie pop musician. I don’t think it’s quite as good as his 2007 album (and my favorite album that year) Night Falls Over Kortedala, but it’s still really great.

Honorable Mentions

All these albums are really great too.

Comments

My Javascript Pattern comes from Coffeescript - December 12, 2012

Despite the title, this is mostly about Coffeescript. I read a post a while ago about how an author’s Javascript has improved because he was using Coffeescript. I can’t currently find the post, but I found many similar sentiments and I would also agree with the thought. Recently I was working on a somewhat larger project for me in Coffeescript and it actually help me discover a new pattern to program in.

My preferred way to program in Javascript is to use objects heavily, using object literals and prototypical inheritance. I think trying to make it look like a pseudo classically inheritance language is fine, but I really like expressing my code in an object literal instead of a constructor function and calling the “new” operator on it to create an object. Coffeescript does have some nice stuff to make this prettier, but I still prefer to avoid the “new” operator.

Here’s a quick example of how I might choose to write something simple in JS.

var person = {
  name: "Keller",
  greet: function() {
    console.log("Hello " + this.name + "!");
  }
};
person.greet(); // Hello Keller!

I’ve frequently used the what I’ve seen called the “reveal” Javascript pattern for organizing Javascript and hiding “private” attributes and methods. It looks something like this:

var person = (function() {
  var name;

  var greet = function() {
    console.log("Hello " + name + "!");
  };

  var set_name = function(new_name) {
    name = new_name;
    update_db(new_name);
  };

  var update_db = function(new_name) {
    //ajax call to db
  };

  return {
    greet: function() {
      greet();
    },
    set_name: function(new_name) {
      set_name(new_name);
    }
  }
})();

person.set_name("Keller");
person.greet(); // Hello Keller!
person.name; // undefined
person.update_db('evil'); //error "person has no method 'update_db'"

If you haven’t seen this before, what’s happening is person is being set to a self-calling function. The function immediately calls itself and returns an object with 2 methods. These methods access functions in the self-calling function. This method is nice because the variables and functions defined in the function lose their scope outside of the function, but the object returned by it has access to them, so you sorta can have private attributes and methods in an object.

Here’s what it looks like though in CoffeeScript:

person = (() ->
  name = ''

  greet = () ->
    console.log("Hello #{name}!")

  set_name = (new_name) ->
    name = new_name
    update_db(new_name)

  update_db = (new_name) ->
    #ajax call to db

  {
    greet: () ->
      greet()
    set_name: (new_name) ->
      set_name(new_name)
  }
)()

person.set_name("Keller")
person.greet() # Hello Keller!

So, that’s not bad looking. It’s arguable not any worse looking than the Javascript equivalent. But I feel like one of the great things about Coffeescript is that it makes your JS beautiful. There were a couple of things that I thought were a little ugly. First was the person = (() -> line. I like how CS does functions, but in this case, it looks a little confusing to me. The next thing that was a little ugly, was the name = '' line. I need to declare it outside of the functions that use it, but there really is no way (correct me if I’m wrong), to simply declare a variable in CS. I have to set or use it. And that can get really ugly if you have a lot of variables like this. In JS I can do something like var name, age, sex, state, country; all in one line. CS makes that longer and more tedious. One last thing that kind of bugged me is the “private” variables and methods aren’t really object attributes and methods at all. That’s ok with me in JS, but in CS, it means I can’t use the handy @ shortcut for this. :(

However, I discovered a different way to do something very similar that is much prettier in Coffeescript. I’ll show it in Javascript first.

(function() {
  var person = {
    greet: function() {
      console.log("Hello " + this.name + "!");
    },
    set_name: function(name) {
      this.name = name;
      this.update_db(name);
    },
    update_db: function(name) {
      //ajax call to db
    }
  }

  this.person = {
    greet: function() {
      person.greet();
    },
    set_name: function(name) {
      person.set_name(name);
    }
  }
}).call(this);

person.set_name("Keller");
person.greet(); // Hello Keller!

This works essentially the same way, except rather than returning an object from inside a closure and setting it to variable outside of the self-executing function’s scope, it sets the object to the an object that already exists outside the function, which in this case is this. One thing that may be confusing is the this that this.person is referring to is the same this that is being used in the last line’s .call(this) which is the window object. All other uses of this are for the person object.

So here’s the nice part about how Coffeescript works. By default, it wraps everything in a self-executing function to protect the variables scope. So you don’t need to write that part of it. Here’s what it looks like in Coffeescript.

person =
  greet: () ->
    console.log "Hello #{@name}!"
  set_name: (name) ->
    @name = name;
    @update_db(name);
  update_db: (name) ->
    #ajax call to db

@person =
  greet: () ->
    person.greet();
  set_name: (name) ->
    person.set_name(name);

In another file or in the HTML:

person.set_name "Keller"
person.greet() # Hello Keller!

Beautiful, right?! Maybe it looks a little funny because it looks like I’m creating two versions of the person object, and that’s kind of true. One is a private version, and the other is a public version. The public version shouldn’t really do anything but expose parts of the private version of the object. It’s a lot like the “reveal” pattern. This is what I ended up using as my design pattern recently and I think it worked and looked great.

One last thing. I did “discover” this on my own. But, it’s really not that much different than what is out there, and I’m pretty sure others have discovered and used this before too. I’m probably not that original. But it was fun to think of something new (to me).

Comments