Global hotkeys for 8tracks on Mac

A few days ago I started using the 8tracks service, it's a really cool music streaming service.
The only thing I was missing was a global hotkey for play/pause, so I implemented it using a combination of Fluid, AppleScript and Alfred.

First, install Fluid (the free download is enough) and create a standalone application for 8tracks:

Then, download the 8tracks workflow and install it in Alfred.

Now you can use "Command+F8" to toggle play/pause in 8tracks (you can change it in Alfred's workflow settings).

If you use a different launcher, here's the applescript that actually does the work:

ActiveRecord+PostgreSQL mass-insertion benchmarks

In the past couple of weeks I've been researching databases and optimization techniques and I just wanted to share something I discovered.

I'm using:

Linux Mint 13PostgreSQL 9.1 (default settings)Ruby 1.9.3p194ActiveRecord 3.2.6an i5 760 with 4GB of RAM
I have an "items" table with 15 columns (5 string, 5 integer, 1 text, 2 date and 2 float) and I'm trying to add 100,000 items to the table.

Here are 4 different methods I've tried:

1. Plain ActiveRecord.create
Takes 262 seconds (2.62ms per item)

2. Using the activerecord-import gem (using models)
Create an array with 100,000 items created using "Item.new" and then run "Item.import items":
items = [] 100_000.times { items << Item.new(...) } Item.import items This technique takes 144 seconds (1.44ms per item) where the "Item.new" part takes 43.3 seconds and the "Item.import" part takes 100.7 seconds.

Improvement: ~55% compared to plain activerecord

3. Using the acti…

Writing hebrew text using Vim

Usually when you write hebrew in Vim, you have to write from left to right, which is a little annoying. Vim has two settings that allow typing hebrew easier: set rightleft (or set rl) display the entire buffer from right to leftset keymap=hebrew - changes the keyboard mapping to hebrew (doesn't effect the OS mapping) I wrote a simple function that toggles between hebrew mode (right-to-left and hebrew mapping) and normal mode (left-to-right and english mapping): I'm binding this function to the key so I can easily switch between english and hebrew modes.

How I learned TDD

I first heard about unit tests at an open source developer conference in 2006 and since then I've been trying to understand this concept.The first tests I wrote were with PyUnit, I don't remember what the project was, I just remember that it was horribly implemented, I didn't have any notion of the SOLID principles, so it was very difficult to write the tests and eventually I gave it up.A couple of years later I started to develop a large enterprise application in .NET which forced me to improve my software architecture skills, I started reading a lot of books on the subject:Patterns of Enterprise Application Architecture by Martin FowlerAgile Principles, Patterns, and Practices in C# by Robert C. Martin and Micah MartinProgramming .NET Components, 2nd Edition by Juval LowyArchitecting Applications for the Enterprise by Dino Esposito and Andrea SaltarelloAs I was reading the books I began to realize how little I understand about software craftsmanship and how much more the…

Exporting (hebrew) contacts from a Motorola i876 phone

On Windows:
Install iDEN PhoneBook Manager (if you have hebrew contacts, you MUST select "Hebrew" when installing it, otherwise it will mess up your contacts).If you're using the Hebrew interface and it looks like gibberish, you need to go to "Region and Language" in the control panel, and under the "Administrative" tab select "Change system locale" and change it to Hebrew (you'll have to restart).On your phone enter:Main Menu (תפריט ראשי)Settings (הגדרות)Connections (חיבורים)USBCheck Data Modem (מודם)Launch the iDEN PhoneBook managerConnect the phone to the computer using the USB cableSelect "Load from Phone"It will load the contacts from the phone (the phone will reboot)If you wish you can print the contacts by pressing "Print"Press "Continue"Press "Save to File", it will ask you were to store the mdb file (access database).
On Linux (I'm using Ubuntu):
In a terminal run: sudo apt-get insta…

Why I love Ruby on Rails

About four months ago I started writing a couple of projects in Ruby on Rails, and the more I used it, the more amazed I was at how easy it was and how fast I was advancing.

How do I ??? with Git?

The purpose of this post is to quickly go over some of the basic things most developers would require from source control software.I highly recommend reading either Pro Git or Git Community Book.Undoing a commitIf you committed some code by accident you have the following options:Undo option #1: AmendIf you just forgot a file or wrote the wrong comment, stage your changes and run "git commit --amend". This will merge the new commit with the previous commit (overriding the old comment).Undo option #2: RevertRevert will create new commit which is the opposite of the commit you wish to remove, for example: $ git log dfdd917 added file2.txt fbe043e added file1.txt $ git revert dfdd917 $ git log 7bdd793 Revert "added file2.txt" dfdd917 added file2.txt fbe043e added file1.txt If you already pushed the commit you wish to remove, this would be the best option.