Archive for the ‘Code’ Category
Like a brown bird nesting in a Texaco sign I’ve got a point of view
I’ve been doing Rails for a while now and have developed a more complex relationship with the framework. My perspective has been tempered by having to actually build complex stuff. But Rails still has the habit of surprising me as I was reminded recently with the acts_as_list plugin. Building sortable lists (like Netflix has with their movie priority queue) has always been a hassle. If you want to move an entry from the bottom to the middle you have to bump the surrounding articles up and down, no fun. With acts_as_list I can do something like my_obj.move_higher or my_obj.move_to_bottom. Forget about it.
In other news I biked to the tip of Manhattan, Inwood to be exact, to check out Matt and Liza’s new place. It’s the end of the A line, pushing into the fictional grid where the Tenenbaums lived. It’s a different scene up there. I took Broadway all the back, all 200+ streets with all the different New Yorks whizzing by. Reminded me of the M5 bus ride from two years back.
Twistori
A while back I was working on developing a mobile component for Jonathan Harris’ influential We Feel Fine service, which mines the web for blog entries with specific words that could be correlated to feelings. Love, hate, wish, etc. I was going to couple We Feel Fine data with location information so that, using your mobile device, you could see in real time how a particular location ‘feels’. That project was on shaky conceptual ground as it wasn’t clear whether I was authentically providing the feel of a location. Possibly I was just presenting how a specific blogger feels who happens to be blogging from that location.
I found Twistori today, which is yet another iteration of the We Feel Fine idea. Twistori pulls content from the hugely popular Twitter service via the Summize API, keying in off the same types of words as We Feel Fine. Love, Hate, etc. It has a much more ‘real time’ feel than We Feel Fine, as the question Twitter users are answering is ‘what are you doing right now?’ As Twitter is interfaced with location data via services such as FireEagle, Twistori could get localized so that users could potentially see feelings in their neighborhood.
One day these types of services will be ’something’. That is less gimmicky, not something you just show your friends or blog about, but instead a service you use to inform your decisions.
Google Charts API
Has anyone played with this thing? It’s awesome. Of course your charts are at the whim of Google’s servers, but this by far beats anything out there if you want a quick and dirty chart. Zero startup costs, just generate a URL.
If you don’t want to deal with deciphering the query string parameters, here’s a chart generator to get you started. I’m sure there are others out there. This is one of the enumerable Google projects that might be old news but that I haven’t had a chance to try — another of which is the Ajax Libraries API.
Otherwise, it’s summer here. We still don’t have our air conditioners, they’re in Boston, but I don’t mind so much. Seawinkle’s offices are moving to Dumbo on Monday. All hail the Brooklyn to Brooklyn commute. Hanging out with Sasha, eating meat pies, things are good.
Update: I also like Open Flash Charts and check out the slightly non-nonsensical, slightly spam-y comment regarding Silverlight charts.
Quick and Dirty Associative Arrays in ActionScript
One of the most basic data structures that I use frequently is an associative array — also known as a hash, map, or dictionary. Associative arrays allow for non-integer indexes. For example:
pup['stick'] = delicious
ActionScript 3 provides a dictionary object which isn’t very pleasant to use. You want to use a associative array for terseness but the native dictionary object has you write so much code that using it defeats the original purpose. I ended up rolling my own hash class which supports some basic functions (add, remove, key_exists, etc.) and that ended up being 77 lines of code. But using my associative array code was pretty dissatisfying, I still found myself traversing nested arrays to find my values.
Enter dynamic ActionScript. My old associative array class was 77 lines of code, here’s my new one:
dynamic public class map {}
By making a dynamic class, I can assign arbitrary properties to my class and treat those properties as keys in an associative array. So how does this work? Well to add a key I do
public var entries:map = new map();
entries['foo'] = bar;
That’s all there is to it. To retrieve the value I just do
myval = entries['foo'];
But wait a minute you say, how do I figure out if a value is set in my associative array? Well that’s easy too. Anything that isn’t set will have a value of undefined
if (entries['bar'] == undefined) { ... }
Finally, there’s even a way to iterate over all the keys when you don’t know them in advance
for each (var entry:* in entries) { ... }
These small code snippets cover all of my needed functionality for associative arrays. Nesting dynamic classes are really readable. You can even use dot notation, namely
entries.foo = bar
but I prefer to use [] because then I can use numbers as keys.
entries.1 = bar // won't work
entries[1] = bar // will work
Gotham Ruby Conference
I got to attend GoRuCon today, a conference for Ruby/Rails hackers held at Pace University. I do so much Rails work on my own so it’s nice to get out and talk to other developers, see what they are up to and catch up on the current state of the art. The talks had a surprising relevancy to some of my current work, from new gems to check out to actual code that I can apply to my codebase. Highlights include Giles Bowkett refering to venture capitalists as ‘Muppet fuckers’ (i’m not even sure what that means) and someone doing a presentation using the scrollbar in TextMate.
On the technical side I was excited to learn about Seattle.rb’s ruby2ruby gem as well as hear Paul Dix’s talk on collective intelligence, where we learned that people who saw the Matrix would love the Lord of the Rings Trilogy and Miss Congeniality is the most reviewed movie on Netflix. Paul has developed Basset, a Ruby gem for machine learning.
With ruby2ruby, you can do cool stuff like have methods discover themselves and implement dmap(), a version of Ruby’s map distributed amongst many servers. This is done by passing around code that is evaled on the distributed server.
All in all Ruby developers are good people, passionate about what they do and really open to learning from others. In no particular order, interesting things I want to keep an eye on:
- Giles Bowkett’s Blog
- WebRat, browser based testing
- Seattle.rb projects including ruby2ruby, RingyDingy and dmap (aka Bonjour for Ruby)
- Vlad the Deployer, a lightweight Capistrano
- Paul Dix’s Blog and Basset
- Linalg for Ruby
- Ruby/GSL
- Weka through JRuby
- Merb and Rubinius
- Cinema Redux
- Utility Belt which lets you do a history and an editor straight from irb
Update: Cory’s notes.












