On using mac instead of linux ...

This is a very common and constant discussion at my workplace. And don’t get me wrong, I love linux. But Jamie Zawinski says it in way that is very similar to what I feel about it:

I use a Mac instead of Linux on the desktop for a reason: because I think that the design and consistency that Apple’s UI brings is extremely valuable. I don’t buy computers based on how fast they are, I buy them based on how easy it is to get things done with them, and Apple is the hands-down winner on this pretty much across the board. (Oh, also because I want my audio card to work, but that’s neither here nor there.)

This quote is taken from a post in his blog where he talks about why he prefers to use Safari instead of Firefox on his mac, and you can read it entirely here.

Having fun developing useless apps

I always thought that the first time I got on the Hacker News and Proggit front-pages would be with some awesome and complex project. I was wrong.

Part I - Like A Boss

On 25th November, while browsing the web, I found a funny project developed by Zach Holman called Fuck Yeah. This was a simple API developed in Node.js that received a piece of text, searched Google Images for that piece of text, and added that text along with a “Fuck Yeah!” to the first image found.

I found the project to be pretty cool, and since I got a little rusty with nodejs, I decided to fork the code and make a new version of the API, this time called Like a Boss. You can pretty much guess what it does. You can check out the code at Github by the way.

Since I had some spare time, I decided to go further and build a website that presented the generated images in a more good looking way. And here’s the result.

Hack Like A Boss

I decided to post the “Like a Boss” website to Hacker News. It got upvoted somehow, and BAM! Hacker News front-page. In 2 hours the website had about 2000 pageviews. This was cool, but not without some problems showing up that had to be solved in order to keep the code from crashing the server. Still, Heroku, the cloud application platform I used to host my nodejs app, handled all the traffic pretty well with only one web worker (included with the free plan).

After about 3 hours, the Hacker News post dropped from the front-page, and traffic almost vanished.

Part II - HTTP Cats API

On December 14th, again, while browsing the web, someone posted on Hacker News an awesome Flickr set of cat pictures authored by Tomomi Imura with each cat posing accordingly to a HTTP Status Code. These pictures ended up being a huge success.

I instantly thought about how awesome would be to have those cat images show up when an error occured on a web-server. I fired up vim and hacked some nodejs code to serve those images through a simple API. After some minutes, the HTTP Cats API was born. I pushed it to Heroku, and it was rocking. I sent the link to a couple of friends, we all laughed for a while and I thought that was it.

HTTP Cat 404 Not Found

After a while, I posted the API link to Hacker News and Proggit. The Hacker News post never got voted, the Proggit one got allot of upvotes, and soon I was on Proggit front-page. An avalanche of traffic ensued.

The post got duplicated on Hacker News, and this time it got allot of upvotes (probably a user with more influence). This was when all hell broke loose. Not only it got on the first-page it was also ranked in 2nd place.

The results where: on the first day I got 19.412 unique visitors. The second day, 21.764 unique visitors. The two days together summed up 255.034 pageviews. These values are amazing for a simple app that serves cat images. Actually, while I write this post, which is 2 months later, it still has around 100 unique visitors a day. And I’m not even counting direct API calls, just the index page visits.

So what?

Yeah, I know these web applications are pretty much useless, but I had allot of fun hacking them and watching the traffic hit the sites. And of course, it doesn’t really matter the fact that they are useless, as long as you have fun, learn and make other people smile, that’s what really matters.

Nginx and the HTTP OPTIONS method

The current version of Nginx (1.0.x) doesn’t seem to support HTTP OPTIONS requests. It returns 405 "Method Not Allowed" whenever this request is sent.

Here’s an example using curl from the terminal:

$ curl -X OPTIONS busydudes.com

<html>
<head><title>405 Not Allowed</title></head>
<body bgcolor="white">
<center><h1>405 Not Allowed</h1></center>
<hr><center>nginx/1.0.11</center>
</body>
</html>

HTTP OPTIONS requests are essential if you’re doing cross-site HTTP requests and need to obtain the server authorization for the URI where the request originated from.

To solve this problem I found two solutions.

If you’re using another web server behind Nginx and want the request to be handled by that web server, you can trick Nginx into believing that the HTTP status 405 is actually a 200 OK status, so it will just delegate the request to your webserver using the proxy_pass directive. Just keep in mind that this is an ugly fix. Edit your nginx.conf file and add the following:

error_page 405 =200 @405;
location @405 {
    root /;
    proxy_pass http://localhost:8080;
}

Solution 2

If you’re just using Nginx as your main server, or just want to obtain the authorization response for the origin domain, then this is definitely the best solution. Edit your nginx.conf file and add the following:

location / {
    if ($request_method = OPTIONS ) {
        add_header Access-Control-Allow-Origin "http://example.com";
        add_header Access-Control-Allow-Methods "GET, OPTIONS";
        add_header Access-Control-Allow-Headers "Authorization";
        add_header Access-Control-Allow-Credentials "true";
        add_header Content-Length 0;
        add_header Content-Type text/plain;
        return 200;
    }
}

You should edit the http://example.com to match the origin URI you want to allow. If you want to allow any origin just use the * wildcard.

Fixing libdlna formula in Homebrew

Update: This fix has now been added to the Homebrew package.

Recently I got an XBox 360 for xmas, and started looking for ways to stream the music in my Macbook Air to it. I found some interesting commercial software to do it, but stumbled upon an open-source linux tool called uShare that was also available through the Homebrew package manager.

Doing a brew install ushare immediately stopped due to a make install error of the libdlna package, a dependency of uShare, that is required for compatibility with Playstation 3. Here’s the error I got:

profiles.c: In function 'av_profile_get_codecs':
profiles.c:208: error: 'CODEC_TYPE_AUDIO' undeclared (first use in this function)
profiles.c:208: error: (Each undeclared identifier is reported only once
profiles.c:208: error: for each function it appears in.)
profiles.c:214: error: 'CODEC_TYPE_VIDEO' undeclared (first use in this function)
make[1]: *** [profiles.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [install] Error 2

This error happens for newer versions of the libavformat that no longer have the symbols CODEC_TYPE_AUDIO and CODEC_TYPE_VIDEO.

So, in order to fix the formula you need to apply this patch to the source code of libdlna. You can find the content of this patch in a github gist. But to successfully install the Homebrew formula you have to edit the formula file and include this patch in the patches method:

$ brew edit libdnla

Then find the patches method (on line 10) and change the code inside to the following:

def patches
  [
    # fixes ffmpeg locations
    "https://gist.github.com/raw/356431/fbddfeee80d9224f6c67886b119fbd813f3c0ffa/libdlna.patch",
    # fixes missing symbols for newer versions of libavformat
    "https://gist.github.com/raw/1434147/293ec631536bc34a6e2dd49bb0f30c86f02b1107/libdlna023_fix_symbols.patch"
  ]
end

Basically, instead of returning just the patch that was already in the formula as a string, I’m now returning an array with that patch, and my patch.

Now just save the file and:

$ brew install libdlna

And then resume the ushare formula install:

$ brew install ushare

That’s it. It should now install without a hassle.

I submitted this change to the Homebrew project with a pull request, so anytime soon you won’t be needing this workaround :)

Hacker News Stack

Hacker News Stack logo

Hacker News Stack is a Chrome extension that improves the readability of the items in the Hacker News website, removing the items that were clicked (read).

This extension is a page action, that acts on the website. As the user clicks on an item link, the item ID is parsed and stored in the HTML5 storage database (localStorage). Automatically this item will be moved to the bottom of the website (marked as read).

This was a frustrating extension to build because of the fact that the HTML source in the Hacker News website is a total mess. Parsing it turned out to be an unreliable task, not only because the site layout is done with tables, but also because of the lack of semantics in the markup.

Anyway, it seems to be working fine (with some minor bugs being taken care off). I’m currently using it and it’s making a big difference making me focus only on the news that I didn’t clicked yet.

Hacker News Stack screenshot 1 Hacker News Stack screenshot 2

You can install it from the Chrome Webstore or check out the source code at Github.

hashr 1.0 for Firefox

The hashr Firefox extension has reached version 1.0 with the launch of Firefox 4.

This new version brings some UI improvements. Some users were complaining about the interface being clunky, it turns out that this was specially true in Firefox for Windows and Linux. I was only testing it on the Mac version, where it looked allot better. So I gave it a slightly better UI and made it consistent between all operating systems where Firefox runs.

There’s also a new toolbar button that is added by default on installation. It does the same thing as the addon-bar (aka old status-bar), it shows/hides the hashr toolbar. It makes hashr more visible to new users after instalation, but it can be removed if you only wish to use the addon-bar button.

A new version of the website is being (slowly) developed, and also a new version of the Google Chrome extension.

This new version is already available on the Mozilla Addons website.

Codebits 2010 Project - Chatstorm

Still recovering from Codebits 2010. Congratulations to Sapo for putting up another awesome edition of this event. Three exausting days of coding, talks, and all kinds of crazy events (yes I’m looking at you Nuclear Tacos)!

Just like last year, this year, along with my teammates, I had a mission. To create a project and get it ready by the end of the 48 hour hackathon (actually we spent the first 24 hours attending some talks, playing some video-games and trying to decide what to do).

Once more this mission was accomplished. The project is called “Chatstorm”.

Chatstorm is an online brainstorming web application that uses a real-time chat to share ideas and automatically fetch and suggest web-content related with those ideas. Technically speaking it was developed in Node.js (Server-side Javascript) and WebSockets (Client-side). It was allot of fun to work with these new technologies and to watch the final result.

Unfortunately, Chatstorm won’t be available online for now due to it’s very immature state regarding security, but I’ll leave you some screenshots and also I hope to post a video of the app in action in the next few days.

Chatstorm screenshot 1 Chatstorm screenshot 2 Chatstorm screenshot 3

Currently Chatstorm uses Sapo Fotos, Sapo Vídeos and Twitter as sources of information suggestion. But more sources can be easily added just like plugins.

In the end, we didn’t managed to get into the top 10 projects, but we got much more positive feedback than last year. Still it was worth it. Mission accomplished and now back to real life, counting the days to Codebits 2011.

Check my Codebits 2010 photos at Flickr: Gallery or Slideshow.

Top | More posts...