Fixing libdlna formula in Homebrew

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.

PHP mcrypt in Snow Leopard with Homebrew

Update: This also works on OS X Lion as it is. But just for the sake of correctness you can replace every occurrence of 10.6 to 10.7 in MACOSX_DEPLOYMENT_TARGET.

If you are using Homebrew as your OSX package manager, chances are that you are using the default PHP that comes with Snow Leopard. This PHP installation does not have the mcrypt extension, so if you are trying to use something like PHPMyAdmin, you’ll get an error message saying that mcrypt is not enabled in php.ini.

I googled the answer and found little info about it. I found this post that it’s pretty complete but it compiles mcrypt manually, which is not Homebrew way of doing it. So the purpose of this post is to gather the info for those who are using Homebrew and the default PHP.

First you have to install mcrypt with Homebrew, but the current Formula for mcrypt is not suitable for those on Snow Leopard, so let’s change it. Open the Formula in your favorite code editor:

$ sudo vim /usr/local/Library/Formula/mcrypt.rb 

Note that you only need the sudo if you did not chown your /usr/local directory.

Now lets change the install method to this:

def install
  system "MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --disable-dependency-tracking --prefix=#{prefix} --mandir=#{man}"
  system "make -j6"
  system "make install"
end

Save and run it:

$ brew install mcrypt 

Just wait some seconds and you’re done with this step. After this you might want to undo the changes in the Formula file to avoid git conflicts when updating Homebrew.

Second, you have to download the PHP 5.3 source to compile the mcrypt PHP extension and install it. You can download the source from this link.

Extract the tarball to a directory of your choice, it can be ~/Desktop and then:

$ cd ~/Desktop/php-5.3.0/ext/mcrypt 

And type:

$ phpize 

Again wait some seconds and when its complete type:

$ MACOSX_DEPLOYMENT_TARGET=10.6 CFLAGS='-O3 -fno-common -arch i386 -arch x86_64' LDFLAGS='-O3 -arch i386 -arch x86_64' CXXFLAGS='-O3 -fno-common -arch i386 -arch x86_64' ./configure --with-php-config=/Developer/SDKs/MacOSX10.6.sdk/usr/bin/php-config; make -j6;sudo make install 

Allot will happen and hopefully you won’t see any errors.

Now finally you just need to edit the /etc/php.ini file to enable the extension you just compiled and installed. If you don’t have a /etc/php.ini file you need to copy the default config file:

$ sudo cp /etc/php.ini.default /etc/php.ini 

And let’s edit it:

$ sudo vim /etc/php.ini 

Find the enable_dl setting and remove the ; in front of the line (if any) and change it to On. It should look like this:

enable_dl = On 

Now find the Dynamic Extensions section of the file and add this line at the end of that section:

extension=mcrypt.so 

Restart the Apache server and you’re done. Happy coding!

Test Driven Development with PHP

This week I had the oportunity to give an introduction talk about Test Driven Development with PHP at DRI Code Sessions. I’m no TDD expert, but I’ve been using this methodology on some of my personal projects, and this was a great way to consolidate what I’ve been learning and also share and discuss it with other programmers.

The slides are very concise, as they had the sole purpose of guiding my speech. But I believe that they give, along with the code examples, a good notion of what TDD is about.

You can find the code examples on Github and also the slides in PDF and ODP formats.

Moved from Wordpress to Jekyll

I’ve been wanting to leave the Wordpress platform for a while now, and last week I finally managed to start rebuilding this blog with Jekyll - a blog-aware, static site generator in Ruby.

Don’t get me wrong, I still think that Wordpress is a great blogging/CMS platform. But for me and the purpose of this blog, it has become a little overkill.

Jekyll is my ideal way to maintain a blog. I get to use my favorite daily work tools (Git and Textmate) and in terms of performance, static files are just great, no need to spend precious VPS resources. Oh, did I mention that this blog is now running on a VPS? That’s right, prgmr.com powered. I’m gradually moving all content in the Dreamhost account to the VPS.

Regarding the migration, it went almost perfect except for the feed. Feed subscribers may notice some weird behavior, like sudden unread posts showing up that aren’t new at all and stuff like that. Things will get stable with new posts.

The blog design has also changed from a modified Wordpress template to something built from scratch. This new design keeps things simple and readable, just the way I like. So no fancy stuff, just plain focus on content. And it’s still being improved along with the markup, so there will be some changes in the next few days.

Update: I’m now using the Google Webfonts API to serve the some beautiful fonts. The header title font is Lobster, the body font is Droid Sans and the code font is Droid Sans Mono. If your browser does not support Webfonts the CSS will fallback to Georgia, the original font of this blog.

Top | More posts...