Can’t install PIL on Mavericks (unknown argument: -mno-fused-madd)

I tried installing PIL (Python Imaging Library) on Mavericks recently and ran into a few problems. Normally this should be enough:

sudo pip install pil

However, it failed on the "cc" command. It turns out I didn't have the compiler installed. This is provided with the Xcode command line tools which I was missing. Some articles I found recommended doing just:

xcode-select --install

This didn't work for me, I got a message saying that the software wasn't available in the update servers. Here's what you have to do:

Continue reading →

Evernote crashes or freezes at startup on Mac

I use Evernote on a daily basis for note taking at work. However, recently it started to freeze completely when opening it. It would start syncing and then just stay there until I would force close it.

After searching a little while I found a solution for this in the evernote forums, so if you run into the same problem here's what you can try:

  • Go to /Users/[your-username]/Library/Containers/com.evernote.Evernote
  • Delete all contents of this folder, or even the folder itself (it will be automatically recreated when starting up Evernote)

The Library folder is hidden by default but in Finder you can show it easily by going to View > Show View Options and then checking "Show Library Folder".

After doing this just start up Evernote and it will start syncing all your notes again (which might take a while).

I hope that helps!

How to use iTerm2 keyboard shortcuts with linux screen

Screen is a great tool if you spend a lot of time in the terminal and need to keep a bunch of connections open (here's a good screen tutorial). However, it can be quite hard to master and some people prefer tmux for some more advanced and user-friendly features (go here for a tmux primer). For my own purposes screen is enough so I'll stick with it. I use it in combination with iTerm2 which is a great terminal app replacement for Mac OS X and since I like to make my life easier I decided to some of the keyboard shortcuts.

One of the main purposes of screen is to allow you to create "virtual" windows that can remain connected even if you close your terminal and shutdown your computer (they live in the remote server). If you know screen you must also know how annoying it sometimes is to switch between windows using the escape sequence Ctrl+A+n (next) or +p (previous), especially if you want to do it fast. The alternative Control + a + " to see a list of all open windows is not always very handy either.

iTerm2 allows you to customize keyboard shortcuts to do whatever you want, so let's dig into it. I wanted to have a very easy keyboard sequence that would allow me to jump between windows quickly so I chose Command + Option + →/←.

Continue reading →

Can’t play video with Xbian / Xbmc on Raspberry Pi – gpu_mem = 256 fixes the problem

A few months ago I decided to get a Raspberry Pi and make a media center out of it using XBMC. I had heard great things about this kind of setup and after many hours trying to get everything up and running I must say it really is amazing. I'm using Xbian 1.0 Beta 1 on a 512mb RPI (together with Sickbeard and Transmission for true automation). I will write another post with more details about the setup and some tips to get it running smoothly but for now I just want to present a solution for a problem I recently had with Xbian.

The problem was that Xbian was refusing to play some episodes of a certain TV series. It would show the spinning "loading" icon for a little while but then a few seconds later nothing happened. I enabled debugging (System/Settings/System/Debugging > Enable debug logging) and checked the xbian log (under ~/.xbmc/temp/xbmc.log). There's a lot of information there so it's not easy to see what really matters. You can try the following to make it easier though: in your terminal, tail the log (tail -f xbmc.log). Then prepare to hit play on the problematic file but just before doing it press enter a few times in your terminal to create a bunch of empty lines. Right after doing that hit play. This will serve as a kind of marker so you know where to start looking. When the loading icon disappears (and the video doesn't play) do the same thing so that you have another marker. After that you can just scroll back and copy paste the relevant part of the log if you want.

In the log, the most interesting parts will be those that have ERROR since they'll normally indicate that something went wrong (even though not necessarily related to this problem). In my case I saw some error lines that looked suspicious:

20:42:34 T:3042451456 ERROR: COMXCoreComponent::AllocOutputBuffers component(OMX.broadcom.resize) - OMX_UseBuffer failed with omx_err(0x80001000)
20:42:34 T:3042451456 ERROR: COMXImage::HandlePortSettingChange m_omx_resize.AllocOutputBuffers result(0x80001000)
20:42:34 T:3042451456 ERROR: COMXImage::Decode HandlePortSettingChange() failed
20:42:34 T:3042451456 ERROR: COMXCoreComponent::SetStateForComponent - OMX.broadcom.resize failed with omx_err(0x80001000)
(...)
20:42:34 T:2574251072 ERROR: COMXCoreComponent::AllocInputBuffers component(OMX.broadcom.audio_decode) - OMX_UseBuffer failed with omx_err(0x80001000)
20:42:34 T:2574251072 ERROR: COMXAudio::Initialize - Error alloc buffers 0x80001000
20:42:34 T:2574251072 ERROR: OMXPlayerAudio : Error open audio output

To be honest I have no clue about what those messages actually mean. So I tried my luck in the #xbian IRC channel on freenode.net and a very nice guy pointed out that this was probably a memory issue and suggested I changed the gpu_mem setting in the config.txt (which can be found under /boot/config.txt). I checked and I had 2 lines for this setting:

gpu_mem_256=128
gpu_mem_512=128

This setting specifies the amount of memory that can be used by the gpu. I guess there are two because this is a generic file and the right one will be used depending on which RPI version you have. Both were set to 128 so I changed gpu_mem_512=128 to gpu_mem_512=256 and rebooted the pi. When it came back I tried playing the files again and voilá, pure joy, it just worked.

I hope this can help out someone with a similar issue. Post your findings in the comment section.

Sublime Text 2 opens files in new window

A small annoyance of Sublime Text 2 for me was the fact that it always opened files in new windows instead of reusing the existing ones (OS X only). It turns out it's quite easy to change this behavior. Here's how:

Sublime Text 2 menu > Preferences > Settings - Default

Now search for the following: open_files_in_new_window

The line will look like this:

// OS X only: When files are opened from finder, or by dragging onto the
// dock icon, this controls if a new window is created or not.
"open_files_in_new_window": true,

Just change "true" to "false" and you're done!
Now whenever you open a file it will reuse any existing window you already have.

Bash script to check server load and notify by email

Lately I have been dealing with high server load problems, both at work and on my own server so I've been reading about it and trying to understand what it means and how to debug such issues. I don't mean to lecture you on the subject on this post but I will point you to a great article that explains it in a very simple way: Understanding Linux CPU Load - when should you be worried?

After reading that you'll know a lot more about what load means and the its different types. So how do you know if your server has a sudden spike of traffic causing high load for example? You surely can't be logged in all day typing 'uptime'. You could, however, have some sort of monitoring tool that will alert you automatically. If you're dealing with a high traffic production server you most certainly have a "real" monitoring tool such as Nagios or Zabbix. If you're like me and host a small website on a small VPS then some of those solutions might be overkill.

Continue reading →

Samba shares and SELinux – how to fix “Invalid key 0 given to dptr_close”

I recently had the need to configure a samba share on a linux box running Scientific Linux and I ran into a very annoying problem. I'm not going to explain all the details about how to configure the samba server and configure it (there are quite a few tutorials around for that, and I actually used Webmin which makes it very easy).

So after configuring everything, setting permissions and creating a user with simple password authentication, I was able mount the share on my mac but no contents were shown, not a single file.

Continue reading →

Formatting XML in Sublime Text 2 (xmllint)


I'm always looking for the best tools to make my life easier. In this constant search for the best text editor for coding and general text work (mainly XML) I decided to try the amazing Sublime Text 2.

I was using TextWrangler for a while and had finally manage to get XML pretty formatting to work on it again but I was struggling to get the same experience out of Sublime Text 2. My ideal workflow is to paste some unformatted XML, press some hotkey combination and end up something pretty. Because there's always someone with with the same problem, a quick google search took me to this page where there are a couple of scripts to do just this. Read that first to get a grip on how to implement these simple scripts.

While this seemed to work pretty well I was still having some trouble with some files that weren't being formatted exactly as I expected. These scripts use the open source tidy command, which is pretty cool. However, for some reason my XMLs (which included some CDATA elements) were not being formatted properly. So I decided to use xmllint instead, just like I had done before in TextWrangler.

Continue reading →