Complete XCode 4 keyboard shortcuts reference

XCode has had a major redesign starting in version 4. Not only the UI and Compiler have changed, but many keyboard shortcuts did too, and for those used to develop using XCode 3 the transition is a bit hairy. While Apple does not provide a complete reference guide for all the shortcuts (none that I know), some handy developers out there do.

The XCode 4 Keyboard Shortcut Reference Guide has a very complete and extremely useful list of all shortcuts, organized in a pretty PDF file. The download links are:

Manually restoring a WordPress theme after a crash

WordPress is a great blog engine, used by millions of people around the globe, and one of the best things (and probably also one of the main reasons for its success) is an easy to use and huge database of plugins and themes. With just some clicks, you can change the theme or install a cool new plugin to enhance your blog.

However, sometimes not everything works well, and you may end with a non-working blog if you installed a problematic (or old) theme. You see, my girlfriend loooooves themes, so much that she tries a new one every day. But sometimes one of those themes doesn’t work, thus trashing hers blog, including the admin area.

There is a way to manually fix it, but you will need access to the database (be it via a terminal, or something like phpmyadmin). Open the database where wordpress in installed in, and find the values you’ll have to change:

select * from wp_options where option_name like '%current%' or option_name = 'template' or option_name = 'stylesheet';

It should return something like this:

| option_id | blog_id | option_name   | option_value | autoload |
|        45 |       0 | template      | Ledgy        | yes      |
|        46 |       0 | stylesheet    | Ledgy        | yes      |
|      5810 |       0 | current_theme | Ledgy        | yes      |

In this case, “Ledgy” is my problematic theme, and I want to change to another one that I know that works (like the Default theme, or the previous one, if you remember the name). In order to find the available themes you have, go to the wp-content/themes of your wordpress installation. Each of the directories there represents the theme’s name you’ll use to update the options table. In my case, I know that the “SP142″ works fine. 

In order to update the table, execute the following statement:

update wp_options set option_value = 'SP142' where option_id in (45, 46, 5810);

Just make sure to use the correct IDs, and you are done!

Setting up Git colors in the terminal

I am adding this here so I won’t have to try to remember once again which colors I’m used to use with Git. If you already didn’t know, it is possible to set up git so that it colorizes the statuses, logs and so on when working via a terminal, which is much better than the plain old monochromatic scheme.

Add the following to your file ~/.gitconfig:

branch = auto
diff = auto
status = auto

[color “branch”]
current = yellow reverse
local = yellow
remote = green

[color “diff”]
meta = yellow bold
frag = magenta bold
old = red bold
new = green bold

[color “status”]
added = yellow
changed = green
untracked = cyan

Now, when you use a command like git status, it will use colors to differentiate the information.

Easy, reliable and free SMTP with SendGrid

It is a problem as old as the web itself: which server or service to use when we need to send emails from our website or local computer? It may sound an easy answer, but if your hosting provider does not offer an out-of-the-box service with fair usage rules, setup a SMTP server yourself is a task that can get messy really fast – either to setup and to maintain it.

What would you use? sendmail, postfix, postmaster, procmail, qmail? Damn, probably half of these options even aren’t smtp servers. And after you find one that looks good, there are so many configuration options and terms to deal with that you will want to swear. Not to mention spammers trying to flood your server.

So, instead of going through this deep, dark and painful way, I found out that using a third party SMTP service is one of the best decisions one can make. For the last months I have been using SendGrid and I am totally happy with it: easy and intuitive panel, simple and clear setup instructions, good prices and – the better – they have a FREE account, which you can use to send up to 200 emails per day. If you think for a while, 200 emails per day is A LOT, if you have a small website or small delivery of emails. It is also perfect when you are developing at your local machine and need to test the email delivering of something (like a registration or recover password form).

To integrate you only need to change three SMTP settings in your application:

  1. SMTP Server:
  2. Username: your account username (the same you use to login in the website)
  3. Password: your account password (the same for the website)
As usual, the SMTP port is 25.
Besides that, even has a REST API and plenty of documentation. So, if you are looking for a reliable, easy to use and hassle-free SMTP service, check out SendGrid

Tip – Formatting a FAT32 Hard Drive of up to 2 TB in Windows 7

To have to format an huge hard drive using FAT32 as filesystem is a quite unusual requirement, unless you own a Sony Blu-Ray player (and possible others). While my TV is able to read a NTFS filesystem just fine, it does not reproduce DTS audio, and reencoding the video can take hours depending of your source file. Also, sometimes the TV (an LG 47″ Full HD TimeMachine model) drops frames if the video is very high-res (say, a 1920×1080 .MKV file with an high bitrate), which leds me to use the Blu-Ray player.

The only problem is that it does not read NTFS, only FAT32, so I had to convert my 1 TB hard drive first. In order to do that in Windows 7 (and possible other versions of Windows), it is necessary to appeal to third party tools due to the HD’s size. One of the simplest and fastest that I have found is fat32format, which does a pretty good job, handling drivers of up to 2 TB.

Note: Please bare in mind that while you can format a hard drive of up to 2 TB, FAT32 has a 4GB limit per file, and there is nothing you can to about it. If your files are bigger than 4GB, you will need to slipt them or move to NTFS.

fa32format is a free tool, available at

How to synchronize your iPhone or iPad in more than one computer

For a long time I struggled around the possibility of synchronizing any given iDevice, be it an iPhone, iPad or iPod Touch, in more than one computer. There were uncountable times that I received a client’s device to troubleshoot (for example, to see why he wasn’t being able to successfully install an AdHoc build), and  when I tried to synchronize it with my iTunes, there would be a message saying that all applications would be deleted. Heck, that’s not why I wanted to do.

Maybe I was looking at the wrong place or doing the wrong searches on Google, but it took me some time to figure out the correct approach to handle this problem. There are two possible situations you may face, which are:

1) Synchronize your own device in more than one computer

This is the simplest of the cases: you have an iPhone, iPad or iPod Touch, and want to sync it at your home’s computer and at your company’s computer. Please bear in mind that you are allowed to do such thing up to 5 computers. Connect your device via an usb cable and fire up iTunes, then go to the Store menu and choose Authorize This Computer. Enter your credentials, and after that go to the File menu and choose Transfer purchases from ….. Wait until it finishes, and you are good to go.

2) Synchronize more than one device in the same computer

This is a bit more elaborated, and handles the situation where you have multiple devices that you need to sync in the same computer – note that it’s a different need than the previous, where it states out to sync the device in different computers. The question here is how not to mess with your own library when someone else’s device is sync’d at your iTunes.

To correctly perform this task, you will need to think about multiple iTunes libraries (or multiple accounts), and then perform the steps previously described at (1). Do the following:

Quit iTunes, and before opening it again, hold down the Option key (Mac) or Shit key (Windows), and without releasing it, fire up iTunes. A dialog window saying that you should “Choose iTunes Library” will open, as shown in the image below:

Select “Create Library” and place it wherever you want. That would be the location where the files will be stored, so if you want to use it other than for temporary purposes, please make sure you choose a good directory.

One you do that, do the steps at (1). To switch between libraries, to the same Option or Shift trick again, but then select “Choose Library” instead.

Converting multiple PDF files into JPG using ImageMagick

ImageMagick is an extremely powerful program, which can do amazing things even with very simple arguments. One of the things I have been using ImageMagick recently was to convert PDF files into image files (JPG, PNG, GIF, you name it), that is a task that many think that only can be achieved using some comercial (and expensive) tool. The basic usage is effortless:

convert input.pdf output.jpg

ImageMagick’s convert command will take the PDF as input and create a JPG file as output. Note that the type of the output file is determined by its extension, so if you wanted to create a PNG file, just use output.png. More advanced results include specifying the pixel density, quality, resize, scale, colorspace, alpha channel etc.. the list goes on beyond you could imagine. For a complete and detailed set of commands, check

A more detailed example:

convert -alpha off -density 150 -quality 80 -resize 768 -unsharp 1.5 input.pdf output.jpg

The previous command will convert a PDF to JPG of quality 80, with 150 DPI and as last step, apply a 1.5 radius unsharp filter. Doing that with any programming language would require literally dozens of line of code.

One interesting option to note about is -alpha off, which prevents the JPG to be created with a black background. However, please note that may not be the case all the times, and you probably will have to adjust the arguments to fit your needs.

Batch processing

As a final example, the convert command requires either an input and an output names, but sometimes you want to the filename to be the same, just with a different extension (like Presentation_123.pdf => Presentation_123.jpg). This is very common when we have a set of pages in a given directory and want to convert them all. One easy way to accomplish that is by using the command mogrify instead of convert. mogrify works much like convert, but allows us to do some batch processing. For example:

mogrify -format jpg -alpha off -density 150 -quality 80 -resize 768 -unsharp 1.5 *.pdf

There are two different arguments: the first is the format we want to convert to, and the other is the format we are converting from. The form is mogrify -format <output type desired> [other arguments] *.<input type>, so if you want to convert all JPG files to PNG without changing the filename (only the extension), you’d execute

mogrify -format png *.jpg

Easy as eating chocolate.

Handling the “open() 11 resource temporarily unavailable” error with Nginx

While developing a website, I started receiving the error “open() 11 resource temporarily unavailable” after we migrated from Apache to Nginx. The symptom was that, after any change to a CSS or JS file (in fact, to any file directly served by Nginx) the first request would crash, but any subsequent request did work. However, after performing any kind of change in one of those files, the problem happened again.

One important thing to notice is that I was developing through Samba – more specifically, I had the Nginx server running on a local Linux box, and the files were being manipulated in a text editor in Windows.

What I found out is that, if I edited the files directly in the Linux box, the problem didn’t happen. Going a little bit further, it was clear that changing to another text editor in Windows would not trigger the problem. After some Googleing, a post in the Nginx users list mentioned that this issue may arrive due to the fact that some text editors perform some kind of temporary lock at Samba in the files being edited (although I couldn’t find anything visually, at least), which caused Nginx to not being able to open the file even for reading.

So, if you have an environment like mine and are running into this issue, try swapping to another editor. You may have luck.