Bowtie doesn’t scrobble to last.fm, solution

Schermata 2009-08-29 a 21.10.32
Apparently there are some issues with Bowtie when using the last.fm integration.
Remember I’m using Snow Leopard.

Bowtie is a valid freeware alternative to CoverSutra for managing iTunes, showing cover art, current song, etc.

Using version 1.0b2 I found out two things:

  • if you open the preference pane, Last.fm and check “Enabled”, the checkbox goes automatically away
  • it doesn’t scrobble

A workaround to fix the first problem is to leave the checkbox alone and instead enable last.fm integration by right clicking the icon in the upper tray and selecting “Enable Last.fm”.

The solution to the fact that isn’t scrobbling is to capitalize your last.fm username in preferences, so for example if my username is “kain82″ I will write “Kain82″.

With those settings in place it does seem working, however I’ll keep this post as reference for future updates on the matter.

Oh, and if you’re into metal, add me to your friends over last.fm ;)

Install Passenger (mod_rails) in Snow Leopard 64 bit

Update: passenger 2.2.5 release notes states that there are know issues with Snow Leopard, but developers didn’t had chance to test them out yet. I personally found no problems on 2.2.4. To upgrade simply run:

sudo gem install passenger
sudo passenger-install-apache2-module

and change apache config according to new version. Follow me on twitter for up to date info.


The installation works out as usual and it’s pretty straightforward, version 2.2.4 2.2.5 and using stock Apache which comes with Snow Leopard as default.

Install Xcode from Snow Leopard DVD, and it would be also wise to upgrade rubygems before doing this operation, search older posts.

Install the gem:

sudo gem install passenger
sudo passenger-install-apache2-module
sudo mate /etc/apache2/other/passenger.conf

passenger.conf doesn’t exists on a vanilla installation (of course), therefore create it or look below. I’m also using the “mate” command, which fires up TextMate, replace “mate ” with your preferred text editor, like vi, nano, etc.

If you want to use your personal configuration file instead of passenger.conf:

sudo mate /etc/apache2/users/username.conf

Replace username with your username in Snow Leopard.

Paste those lines in:

LoadModule passenger_module /Library/Ruby/Gems/1.8/gems/passenger-2.2.5/ext/apache2/mod_passenger.so
PassengerRoot /Library/Ruby/Gems/1.8/gems/passenger-2.2.5
PassengerRuby /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
 
RailsEnv development # or production, but anyway production it's the default value if you don't specify.

Now edit the main file:

sudo mate /etc/apache2/httpd.conf

Around line 465 you will find the commented line:

465
#Include /private/etc/apache2/extra/httpd-vhosts.conf

Remove the # and save the file, this will make Apache pickup extra vhost configuration file.

Open up your Control Panel, go into Shares (Condivisione in Italian), Web share, toggle the checkbox and leave it enabled to reboot Apache and let it pickup those changes.

I’m refraining from installing the complementary PassengerPane at this time since it still uses RubyCocoa instead of MacRuby and its last update is dated 2008, therefore open up:

sudo mate /etc/apache2/extra/httpd-vhosts.conf

and paste a similar code to deploy your rails application:

<Virtualhost *:80>
   ServerName www.yourhost.com
   DocumentRoot /somewhere/public    # < -- be sure to point to 'public'!
</VirtualHost>

Reboot again Apache as described above, as an extra as usual you can edit /etc/hosts to add your ServerName mapped to 0.0.0.0 or 127.0.0.1 or what you prefer by writing a simple line:

127.0.0.1 www.yourhost.com

There’s another method of adding custom hostnames by not tampering with /etc/hosts, but I’ll leave it for another blog post.

Glimmerblocker: block ads in Safari 64 bit mode on Snow Leopard

GlimmerBlocker
Safari AdBlock worked quite well, however since Input Managers are finally totally discontinued in Snow Leopard we can’t use it in Safari running 64 bit mode.

In fact, as the developer states, a new version of Safari Adblock is out in the wild but requires you to run Safari in 32 bit mode, by checking the appropriate flag in Get Info window of Safari.

But since I’m running a 64 bit operating system, kernel and application, I took a step further and began hunting for the appropriate tool and seems that I found it.

GlimmerBlocker doesn’t hack Safari, instead it runs a local proxy to filter ads, pretty neat if you ask me.

And for this reason after the installation you won’t find preferences directly in Safari, instead you’ll find them in your Control Panel, directly in 64 bit mode (PrefPanels that are still 32 bit requires you to reopen the whole Control Panel in 32 bit mode).

The only thing is that when blocking an ads, Adblock removed visually the ads, without leaving empty spaces, meanwhile GlimmerBlocker does (depends on the site you are visiting); however this doesn’t change the fact that it’s an excellent replacement.

There are also other solid features, ranging from creating your own lists, hacking with javascript to let a page behave like you want and showing youtube download links. By running a customizable proxy transparently like this possibilities are infinite, like using it with other browsers and other native applications which uses http. You can even setup your iPod or iPhone to filter ads when over WiFi.

Thumbs up for this software.

Ruby ordered hash tip with Rails

This is quite old, as many of you ruby coders knows that ruby 1.8 doesn’t keep a Hash ordered, while 1.9 does.

This is seldom necessary however, there are bit of codes where it’s important to have the Hash keep the order:

# ruby 1.8.7
>> {:a => "a", :c => "c", :b => "b"}
=> {:b => "b", :c => "c", :a => "a"}
# ruby 1.9.1
>> {:a => "a", :c => "c", :b => "b"}
=> {:a => "a", :c => "c", :b => "b"}

If then you’re using Rails and Ruby 1.8, instead of relying on some kind of black magic sorting by keys or values you can access directly the namespaced ActiveSupport::OrderedHash like this:

1
2
3
4
5
  def build_recurring_hash
    returning(ActiveSupport::OrderedHash.new) do |map|
      (1..5).each{ |n| map[n] = n }
    end
  end

Install Git from source on Snow Leopard 64 bit

There are many methods to get git running on Snow Leopard, this is the source approach.

Go to http://git-scm.com/ and download the latest package (1.6.4.3 as of writing).

Decompress it in a directory, and run this command:

make prefix=/usr/local all
kain-osx:git-1.6.4.3 kain$ lipo -detailed_info git
input file git is not a fat file
Non-fat file: git is architecture: x86_64

seems good, issue:

sudo make prefix=/usr/local install

to install.

test:

kain-osx:~ kain$ git --version
git version 1.6.4.3
kain-osx:~ kain$ which git
/usr/local/bin/git

Of course be sure that /usr/local/bin is in your $PATH.

My Rails .gitignore

config/database.yml
config/*.sphinx.conf
config/s3_credentials.yml
*~
*.cache
*.log
*.pid
tmp/**/*
.DS_Store
db/cstore/**
db/sphinx/**
doc/api
doc/app
doc/plugins
doc/*.dot
coverage/*
db/*.sqlite3
*.tmproj
*.sw?

To always ignore those files system-wide:

git config --global core.excludesfile /path/to/.gitignore

How to install pg (postgresql) gem on Snow Leopard, 64 bit

Install PostgreSQL from source/port for this, does not currently build against binary package.
PATH should be /usr/local/pgsql.

export PATH=/usr/local/pgsql/bin:${PATH}
env ARCHFLAGS="-arch x86_64" gem install pg

Or if you are using macports:

export PATH=/opt/local/lib/postgresql83/bin:${PATH}
env ARCHFLAGS="-arch x86_64" gem install pg

How to mirror a SVN repository on GitHub

Start by creating a project on github.
In this example we will mirror Sphinx search engine.

On your server or local machine create a new git repository, with the same name of the github repo.

mkdir ~/src
mkdir ~/src/sphinx
cd ~/src/sphinx
git init

Now setup the SVN repository as a remote source to track.
It should be noted that the ‘-T’ switch points git directly to the trunk, which is fine for our purposes.

git svn init -T http://sphinxsearch.googlecode.com/svn/trunk

Perform the initial pull.

git svn fetch

This will take some time, based on the size of the remote repository.

After the first pull is finished, go ahead and run the garbage collector, this will help to speed up things and reduce size.

git gc

I’m going to use a different public key for pushing to github, with no passphrase.

ssh-keygen -t dsa -f ~/.ssh/id_dsa_github_for_mirroring

Now, edit ‘.ssh/config’ and add

Host githubmirror
User git
Hostname github.com
IdentityFile /home/yourusername/.ssh/id_dsa_github_for_mirroring

Now, copy and paste your public key into your github account.

cat ~/.ssh/id_dsa_github_for_mirroring.pub

Add the origin, do the first push.

git remote add origin git@githubmirror:yourgitusername/sphinx.git
git push origin master

To keep stuff in sync we need to do

git svn rebase
git push origin master

This is an operation you should do every X minutes or so.
Better setup a cronjob to handle that.

mkdir scripts
cd scripts
nano mirror.sh

and add the following:

#!/bin/sh
cd /home/yourusername/src/$1
git svn rebase
git push origin master

Save and close the file.

Now edit a crontab entry:

crontab -e

Press ‘i’ and start pasting this line:

*/15 * * * * /home/yourusername/scripts/mirror.sh sphinx >/dev/null 2>&1

Press ‘ESC’ and digit ‘:wq!’ to exit.

This is the actual result.