• For a personal project I’m working on, I need to find out the smallest time period with more than 5 records. I essentially wrote this code:

    period = [1.week, 1.month, 1.year].select_first do |period|
      Record.where("published_at >= ?", period.ago).count >= 5
    end
    

    only to find out that the select_first method doesn’t exist. So I wrote it:

    module Enumerable
      def select_first(&predicate)
        self.each do |item|
          if yield(item)
            return item
          end
        end
        return nil
      end
    end
    

    and then of course, I tested it:

    require "test_helper"
    
    require "enumerable_extensions"
    
    class EnumerableTest  2 }
      end
    
      should "select_first the first one" do
        assert_equal 1, [1, 2, 3, 4].select_first { |i| i >= 1 }
      end
    
      should "select_first the last one" do
        assert_equal 4, [1, 2, 3, 4].select_first { |i| i >= 4 }
      end
    
      should "select_first none" do
        assert_equal nil, [1, 2, 3, 4].select_first { |i| i >= 100 }
      end
    end
    
  • I’ve just released another gem, this one extends Hash to contain another method called hmap. This solves a problem I face ofter: how to run a map in a hash that returns another hash, for example:

    {:a => 1, :b => 2, :c => 3}
    

    being converted into

    {:a => 2, :b => 3, :c => 4}
    

    With hmap it’s easy:

    hash.hmap { |a,b| {a => b + 1} }
    

    It also works with arrays, but you must make sure the array you return always contains two and only two elements:

    hash.hmap { |a,b| [a, b + 1] }
    

    And that’s all, quite a simple piece of code, but now it’s re-usable and well tested.

  • Some time ago I had an idea for a web application. That idea was essentially Gist. I couldn’t convince people to go after it, thankfully because I wouldn’t like to compete with a Brad Feld backed company. It’s nice to see that the idea was good, as Gist got bought by RIM. Congratulations Gist!

  • I think this partnership with Microsoft was a mistake for Nokia. It was great for Microsoft though.

    Every time you show an old Nokia phone you get the same comment: “Oh, those phones were built to last, I went through 3 iPhones and the Nokia still works…” or “That is the only phone that will not blend”.

    But Nokia’s obsolete software is killing it. They need to provide truly smartphones. They had three options:

    • build their own
    • use Android
    • use Windows

    I think they already tried to build their own and failed. That’s very hard. A giant like Microsoft tried to build their own and failed. It’s very hard to build a software platform.

    Apple did it by being the first ones and providing the coolest product ever. Google did it by doing it for free. They are both a success because they have thousands and thousands of applications on their platform by now.

    Microsoft haven’t done it. As powerful as Microsoft is, they still haven’t cracked the smartphone market, and it’s very likely they’ll never do. They are up against Apple and Google and both of them have years of advantage now (previous efforts by Microsoft are useless today).

    Now Microsoft has a chance to do it because of the deal with Nokia. Nokia is likely going to put Windows 7 Phone whatever on the hands of many people. Those people will get use to Windows, but not to Nokia and may switch to HTC or another provider in a blink of an eye. Microsoft wins, Nokia loses.

    I think Nokia should have done with Android. I know it’s hard to differentiate yourself with Android (what’s the different between a Samsung and a Sony/Ericson phone these days? They both run Angry Birds), but Nokia could have done it by making a tough phone. There’s a lot of people today not using smartphones because they won’t last in their pockets. Nokia could build a smartphone for them.

    Maybe Nokia decided against Android because of their past mistakes with Open Source projects and companies. At any rate, I think they are making a mistake right now.

  • I was born in Buenos Aires, Argentina. And like most of the rest of the world, it’s a place full of small shops that is being invaded by huge chains from abroad. People complain about Walmart killing the neighborhood mini-market -almacen in spanish-. They said big shops are un-personal, hire the lowest wage people they can find and take all the money abroad.

    That might be true, but I always liked big shops, and while Christmas-shopping recently I was reminded why. I don’t normally consume mainstream products. If a shop is carrying 5 different products of one kind, let’s say, 5 different calculators, they are not likely to carry the one I want (an HP with reverse polish notation of course). How many calculators does a shop need to carry to start having the one I want? Probably 40 or so, because it doesn’t sell much. The big international chain that carries 70 is likely to have it.

    Now, one may imagine that there would be a small shop serving my niche, but there isn’t, because it’s not a very profitable niche. Every shop needs to carry the products that sell the most. Instead of having one shop with 70 calculators we have 14 shops, each with 5 calculators, exactly the same 5 models.

  • Seth Godin writes:

    If someone asks you that, are you excited to tell them the answer?

    in his post What are you working on? saying that you should be excited, even if it’s just your weekend project. I’m not that demanding, but I open all my interviews asking the candidate: “What’s the most exciting project you ever worked on?”. It can be years ago, I understand that sometimes we get stuck in shitty projects, but if you never managed to work in an exciting project I really worried.

    How exciting? You should start talking, moving your hands around and forget you are in an interview. That exciting should be. Bonus points if I have to stop you because you just keep talking about the project and I have to do an interview.

  • Did you watch Tron: Legacy? If not, stop reading now, this post has spoilers, go watch it, and then come back. I’ll wait.

    No, really, I’ll wait, I’m not going anywhere.

    Still here? Ok. Visually, Tron: Legacy is amazing. I’m not going to do an in-depth review, I’m just going to say how I think it should have ended.

    When Kevin, Sam and Quorra are fleeing, Tron and Clu should get close to their airplane, side by side, ready for the final blow. Clu’s airplane is on the left, next to Quorra, Tron’s airplane is on the right, next to Kevin. The end is near and Kevin mutters “Tron”. Tron then opens his helmet revealing a young Bruce Boxleitner that sais in his wonderful voice: “I’m Tron, I fight for the users”. Tron then does a barrel roll as his suit and airplane turn blue and crashes hard on Clu’s airplane.

    Maybe my ending is more Hollywoodish, but with it they could then make Tron: return to the grid.

  • I’ve heard or read that Hugh Laurie is having some problems in his leg by having to fake a gimp all the time by acting as House. I think I’ve got a solution, it’s not cheap but it’s cheaper than having the actor not being able to perform anymore:

    Build a set that is a mirror of the current sets down to the text in the doors, then have Hugh Laurie gimp with the other leg, film everything like than and then mirror the result, so that Hugh Laurie can balance out which side he’s straining.

    I bet that it would also be a very interesting acting challenge.

  • Picture by Horia Varlan

    I was studying impro with a great teacher, the lessons ended late at night and at that time I was still driving and had a car, so I would take everyone who wanted to go in the same direction as me after the lesson. It was lot of fun.

    One day, one of the women that rode in my car left a bottle. I mean a water bottle of those that you throw away to pollute the environment once you are done drinking the contents… or spilling it. I’ve found it on the car the next day.

    I decided to use it as a well intentioned joke and tell her that she forgot the bottle in my car. I was expecting her to just throw it away, but that isn’t what happened. Instead she hugged me and thanked me deeply about returning the bottle.

    Obviously I was surprised about her reaction, so she explained:

    Whenever I travel, I buy local bottles of water and I keep them, I collect them. This one you’ve returned it’s from Chile, see, it’s not a brand you can get here.

    What I assumed was garbage was actually something very valuable for her. I’m so glad that I didn’t act on my assumption and I was able to return the collection item. The moral of the story is: never assume.