lixo.org letting the problem solve itself 2008-05-15T23:44:52Z WordPress http://www.lixo.org/feed/atom/ Carlos Villela http://www.lixo.org <![CDATA[Making OpenCV prettier]]> http://www.lixo.org/archives/2008/05/15/making-opencv-prettier/ 2008-05-15T23:44:52Z 2008-05-15T23:44:52Z

So while I’m on what ThoughtWorks calls the beach, which is the really nice place to go when you’re not assigned to a project, I’ve been playing with OpenCV, a lovely opensource library originally developed by Intel. It’s got a gigantic set of really interesting features related to real-time image manipulation and especially around real-time motion detection and face, hand and body recognition. If you’ve never played with computer vision, I highly suggest giving it a try. It’s tons of fun – and you get to brag about actually knowing what the hell a cascade of boosted classifiers working with Haar-like features means.

While I’m at it, I’ve been building a very small set of wrappers to make it all look a bit more OO (and probably a lot easier to read and write). As the README says:

This project has been set up only as a way of representing the knowledge the authors have gathered about OpenCV and is not intended to be a complete set of OO wrappers for the library – but contributions of any kind are definitely welcome.

Still, I’d much rather see code like:

currentFrame.sub(initialFrame).threshold(thresholdAmount)

than…

sub = cvCreateImage(...)
cvSub(currentFrame, initialFrame, sub)
result = cvCreateImage(…)
cvThreshold(sub, result, thresholdAmount, 255, CV_THRESH_BINARY)

But then maybe that’s just me.

Oh, while I’ve got your attention – doesn’t Apple make or sell those external Firewire iSights anymore? I managed to get ahold of one, and they’re lovely. Now that pretty much every Mac laptop has a built-in camera, maybe there’s no point, but they’re still incredibly useful in these kinds of setups.


]]>
3
Carlos Villela http://www.lixo.org <![CDATA[Go for a walk]]> http://www.lixo.org/archives/2008/04/25/go-for-a-walk/ 2008-04-25T09:21:15Z 2008-04-25T09:21:15Z

How many times have you had a conversation that started with “so while I was in the shower last night, I figured out how to…”, or something to that effect?

I naturally set out some time to think and daydream a little – about 10 minutes every two hours or so, while I have a cigarette (unfortunately, the nazi smoking ban hasn’t been enough to force me to quit just yet): most smokers will tell you that the hardest thing to give up are the ad-hoc social interactions you get with other people who wouldn’t otherwise only chat with or even meet.

But you don’t need to cover your lungs in filth just so you can have an excuse to think. When faced with a problem you want to solve, or even to find out where the real problems are in the first place, try what the native americans called the Medicine Walk:

The medicine walk is a day’s journey upon the face of the earth. It is also a mirror. In it, signs and symbols of your inward journey are reflected. The walk is a distilled form of the vision quest.

It doesn’t need to last a day, and it doesn’t need to sound like such an epic spiritual crusade either. Just get up and walk to place that’s about 10 or 20 minutes away, and that’s it. Take no distractions with you – no iPods, no phone, just about enough change to buy a cup of coffee once you get there, and then head back. Pay attention to the sounds, other people going about their lives, cars and buses passing by, the architecture of buildings, the colours and shapes and symbols around you. Look out for patterns, coincidences, and most importantly, pay attention to the internal dialogue going on in your head: it’ll be trying to pick apart the problem at hand, and you can follow some basic retrospective techniques to work some of it out once you’re in that state of mind.

After doing that on purpose for a bit, I noticed that going out for a walk works even better with a pair. You might need to take a longer break – I found that 20 to 30 minutes of walk time is ideal. That’ll give you about an hour to think, talk and socialise the ideas and problems at hand. Also, notice how easy it is to work out disagreements and suggest new things to try out; promenading has very different brainwave generating patterns, and is probably one of the best tools I have to stimulate creative thinking.


]]>
2
Carlos Villela http://www.lixo.org <![CDATA[Binary Guitar]]> http://www.lixo.org/archives/2008/04/20/binary-guitar/ 2008-04-20T03:26:30Z 2008-04-20T02:45:27Z

The Binary Guitar is a little experiment (took about a day or two to put together) I played with a couple of months ago, and I thought it was fun enough to share.

Installation is seriously clunky – I have never tried it on anything but MacOS X Leopard running on a MacBook Pro so far, and even then there are lots of moving parts, but if you go through the pain of setting it all up, you should have some pretty decent sounds coming out of a USB Guitar Hero Controller (mine’s the X-Plorer, which comes with Guitar Hero II for the Xbox 360).

You’ll need:

Running:

  1. Install everything
  2. Open PD to MIDI.mipi in MidiPipe
  3. Open Binary Guitar.pd in PureData
  4. Go to Pure Data / Preferences / MIDI settings… and point the MIDI inputs and outputs to MidiPipe
  5. Open Binary Guitar.qtz in Quartz Composer
  6. Connect the X-Plorer Guitar. If everything’s working correctly, the Quartz Composer viewer should be black (rather
    than a checkered pattern)
  7. Open GarageBand, select your favourite virual instrument.
  8. Rock on!

Grab it in my github repository.


]]>
1
Carlos Villela http://www.lixo.org <![CDATA[JavaScript: Put everything in a namespace]]> http://www.lixo.org/archives/2007/09/14/javascript-put-everything-in-a-namespace/ 2007-09-14T16:22:49Z 2007-09-14T16:02:01Z

Yes, everything. Put it in a namespace. Everything. No exceptions and no excuses, unless yours is “I have just been thawed.” In this case, I want to be the first to warmly welcome you to the 21st century.

Here’s a simple and reasonably OK way to do it and be nice to your friends, other libraries and the world at large:

var Article = Article ? Article : new Object();
Article.title = “Report: School Shootings Help Prepare Students For Being Shot In Real World”;
Article.save = function() {
  alert(”Saving ” + this.title);
}

You could save a few keystrokes, though. Just use the object literal notation directly:

var Article = Article ? Article : {
  title: “Report: School Shootings Help Prepare Students For Being Shot In Real World”,
  save: function() {
    alert(”Saving ” + this.title) 
  }
}

These two last examples are great if you’re not that concerned about exposing the ‘title’ attribute to the rest of the world. If there is a chance that problems could arise if some other piece of code changed it directly, there is a solution:

var Article = Article ? Article : function() {
  var private = {
    title: “Report: School Shootings Help Prepare Students For Being Shot In Real World”
  };

  var public = {
    getTitle: function() {
      return private.title;
    },

    save: function() {
      alert(”Saving ” + this.getTitle());
    }  
  }

  return public;
}();

I find this a bit hard to get used to, after so many years of developing in languages that explicitly allow me to set access control. It makes sense, though: by creating an anonymous function that returns the object I want to define, and then immediately calling it (note the ‘()’ at the last line), I can hide whatever I don’t want other parts of the code to see - it’s all tucked away in the local context of that anonymous function.

]]>
14
Carlos Villela http://www.lixo.org <![CDATA[The Project Game]]> http://www.lixo.org/archives/2007/06/13/the-project-game/ 2007-06-13T20:35:37Z 2007-06-13T20:33:17Z

After reading A Theory Of Fun, I started seeing projects (and many other human activities) modelled as a game. In the book, Raph Koster describes a series of game development rules, and I found that they can be mapped to the software development project domain with some interesting results:

  • A project, just like a game, has roles. In projects, they’re specific to each role. These rules define the possible actions for each of them. (This one isn’t described in the book, but I added it just to contextualise.)
  • Role-specific rules should be unambiguous, intelligible and apply to all people in that role.
  • No project can be developed without the meaningful interaction of the people in all roles.
  • The outcome of a project has to be uncertain, otherwise it loses its appeal.
  • Rules and representation of a project are not independent but interact with each other.
  • People require clear and immediate feedback to understand the relationship between action and outcome.
  • People require a clear goal so they can perform meaningful actions within the project world.
  • Conflict and competition against time, budget and scope are essential for everyone’s motivation.
  • The challenges of a project should match the skills of the people involved: neither too easy (boring) nor too difficult (frustrating).
  • Projects can be developed without the need for even skill sets among the team. Instead the people learn through interaction, and this should be allowed and encouraged to happen.
  • People perform actions within the project world and observe how these actions change the state of the project.
  • People form a hypothesis about the meaning of a deliverable or action on the basis of their studies.
  • People recognise and learn fundamental patterns within the project and can apply these to different situations (and, of course, other projects).

The more I look at these, the more this matches the way I see people working in agile projects. I’m sure there’s a lesson to be learned here…


]]>
0
Carlos Villela http://www.lixo.org <![CDATA[Tip: get your TODOs out of the comments]]> http://www.lixo.org/archives/2007/06/06/tip-get-your-todos-out-of-the-comments/ 2007-06-06T13:20:19Z 2007-06-06T13:16:47Z

Developers in most projects I have seen try to establish some sort of convention around leaving TODOs in the code. The most common seems to be “if you see something funny, try to fix it immediately, but if it’d take too long and you’ve got something else to worry about, leave a comment next to it starting with TODO, your initials and maybe a date”.

You know what? Using comments for that is not as cool in Ruby, Python or Java, which has had static imports for a while now. How about creating a TODO method that takes in the initials, date and comment text, or whatever else you might find useful?

import static my.project.DevelopmentUtils.TODO;

…

public void doStuffThatSmellsFunny() {
   TODO(”CV, 21/jan”, “Clean this mess up after fixing #3849″);
   …
}

There are some advantages to this: you can actually put some code inside that method to do, say, logging. Another good thing is that now the TODOs can be tracked using the same refactoring tools and features of modern IDEs as just any other code in the project.

It may seem a bit cumbersome, but I’ve been trying that for a few days now and it feels quite pleasant to use. I got my TODO method to just spit out the message to the console so when I run tests, I can quickly get an idea of what areas of the code touch stinky or incomplete ones.

]]>
12
Carlos Villela http://www.lixo.org <![CDATA[Viral software (and in a good way)]]> http://www.lixo.org/archives/2007/05/29/viral-software-and-in-a-good-way/ 2007-05-29T22:54:57Z 2007-05-29T22:48:18Z

I’ve been hanging out with friends in São Paulo over the last few days, getting unreasonably drunk, eating too much and attending the Google Developer Day, not necessarily in that order, so I missed the announcements that Facebook had opened up their API.

As a software developer with a healthy affection for all things related to network effects and emergent behaviours, this is brilliant.

The applications provided get added to a central registry inside Facebook, from where you can pick and choose the ones you want added to your profile. They still have to be deployed separately (as Facebook doesn’t host them for you), but the user doesn’t see any of that - all of it is a very simple and well-designed UI, so “installing” an application to your profile is a hell of a lot easier than installing a desktop application to your machine, and gives the user instant feedback.

Leaving important considerations on data ownership and privacy aside, which I won’t comment on since I haven’t read the agreements in much detail, I can see this thing eating a huge chunk of what we nowadays use disconnected internet applications for. Instant, mobile and email-like messaging, discussion groups, photo sharing and some other basic kinds of applications are already there, as are little data aggregation tools, like the del.icio.us and Magnolia importers. If this API is successful (and so far, nothing suggests otherwise), other social networks could as well be dragged inside Facebook if they support any kind of external API. And, if not, there are always screen scraping tools like Hpricot.

Something to watch out for, definitely. Ten years ago, we were wondering what kinds of applications could be made to run on the internet. Facebook is making us wonder what kinds of applications can be made to run on top of a social network. Which ones would you try?

]]>
1
Carlos Villela http://www.lixo.org <![CDATA[Thanks, Oracle]]> http://www.lixo.org/archives/2007/04/23/thanks-oracle/ 2007-05-29T22:55:08Z 2007-04-23T13:28:17Z

We’re using Oracle at my current project. I wanted to run some reporting scripts on the database to do some nice graphs with Graphviz and yEd. “Well, that’s been done before, should be pretty easy to hook up ActiveRecord to Oracle”, I thought.

It turns out that’s nearly impossible to do on an Intel Mac running the x86 version of Ruby, since the Oracle Instant Client SDK only ships with PowerPC binaries so far (hence the title). Unless you recompile your whole Ruby install to PPC, something that to me sits somewhere between unspeakable and atrocious, you can’t link to its libraries, as far as I can tell.

But you can get SQLPlus to run on Rosetta. And you can get SQLPlus to spit out reasonably parseable HTML. And it’ll run slow - but for a quick-n-dirty report that you want to generate once every couple of months or so, it’s… ok.

def select_all(sql)
  html = `echo “#{sql};” | sqlplus -r 3 -l -s -m “html on entmap on” #{@user}/#{@password}@#{@host}`
  doc = Hpricot(html)
  (doc/’tr’).collect do |tr| 
    (tr/’td’).collect do |td|
      td.innerText.strip if td.innerText 
    end if (tr/’td’).size == (doc/’tr/th’).collect do |th|
      th.innerText.strip if th.innerText
    end.uniq.size
  end.compact
end

Look what you made me do, Oracle. You should be ashamed. As you can see, though, I’m not that easily embarrassed. Some people wouldn’t ever show this code to anyone, and deny its existence at all possible cost. I think it’s worth the shock value, though. :)

]]>
8
Carlos Villela http://www.lixo.org <![CDATA[I love the OSA]]> http://www.lixo.org/archives/2007/04/05/i-love-the-osa/ 2007-04-05T18:50:52Z 2007-04-05T14:32:34Z

Inspired by Nat Pryce’s recent scrapheap challenge idea for a Name That Tune style game, and given I’ve been having so much fun with the Ruby OSA lately, I decided to implement my own solution using it to drive iTunes and I had a lot of fun in the process.

I started by grabbing a reference to iTunes:

%w(rubygems rbosa).each {|lib| require lib }

itunes = OSA.app(”iTunes”)

And then playing about with it until I found the right properties to look at and methods to call. As the game requires a constant stream of random tracks, I thought using the Party Shuffle feature of iTunes to would fit just right. The Party Shuffle is a special playlist that sits inside your library:

library = itunes.sources.find {|s| s.kind == OSA::ITunes::ESRC::LIBRARY }
party_shuffle = library.playlists.find {|p| p.special_kind == OSA::ITunes::ESPK::PARTY_SHUFFLE }

With that party_shuffle (an OSA::ITunes::Playlist object) at hand, it’s pretty easy to do the rest: playing, changing tracks and figuring out how to score each guess.

If you can grab the complete solution and make it into a nice little dashboard widget, I’ll be forever in debt!


BONUS UPDATE: I just finished refactoring a couple of things (namely, moving the monkey patching of OSA::ITunes away - it’s now in itunes.rb) and, in the process of doing so, Tune Fight was born!

]]>
2
Carlos Villela http://www.lixo.org <![CDATA[How would you improve this page?]]> http://www.lixo.org/archives/2007/02/08/how-would-you-improve-this-page/ 2007-02-08T00:32:35Z 2007-02-08T00:24:50Z

On an application I’ve been working during my spare time, I had the need to ask my loyal friends and guinea pigs to give me some feedback, in order to help me fill in the gaps between what I think they want to do and what they really want to do in this application.

A quick, cheap and really useful solution I came up with was adding a feedback form right there, on every page the application renders. This can certainly be improved by people more knowledgeable in Rails than myself, as for now it doesn’t even use AJAX to post the data back (shame, shock and horror!)

After running scaffold_resource Comment body:text uri:string created_by:integer created_at:timestamp, you should be pretty much set to go. Now, on your application.rhtml, you can do something like:

<%= render :partial => “comment”, :collection =>
Comment.find_all_by_uri(request.request_uri) %> <% form_for :comment, Comment.new, :url => comments_path do |f| %> <%= f.hidden_field :uri, :value => request.request_uri %> How would you improve this page? <%= f.text_area :body, :rows => 5 %> <%= submit_tag ‘Add comment’ %> <% end %>

The _comment.rhtml partial is something like this:

<%= comment.body %>
Created by <%= if comment.created_by.nil?
    ‘unknown’
else
    link_to(comment.created_by.name,
      profile_url(comment.created_by.profile))
end %>

<%= time_ago_in_words comment.created_at %> ago

[<%= link_to ‘Destroy’, comment_path(comment.id), :method => :delete %>]

Customize the Comment controller slightly, and that’s it — instant feedback forms everywhere! :)

]]>
2