The Problem with Nickel Creek

So you’re coding along to your favourite type of productivity music [this week mine is country/folk/bluegrass] and turn shuffle off.

You listen to lovely stuff like this [youtube link].

What’s the problem with listening to Nickel Creek? Without fail Nickleback comes on after and it takes about three tracks to realise what’s going on..

Admit it, you’re one of them huff duffers aren’t you?

Today I huffduffed for the first time. I’ve planned to for a while…

The word Huffduffer derives from a technology called Huff-Duff [HF/DF] that was used to triangulate the position of radio transmissions. Huffduffing on the web is a way of pin-pointing interesting MP3 files.

Jeremy Keith spoke to Refresh Belfast in December and while I gave up on producing the video because it was so dark in the venue I simply forgot that I’d taken a HQ line out of the sound desk with the recording.

So here in all it’s glory is “Jeremy Keith talking about Huffduffer on Huffduffer about Huffduffer.”

Enjoy.

Band of Brothers followup: The Pacific

Seriously excited to hear recently (announced eight months ago) that HBO have been filming a follow-up mini series to Band of Brothers based in the Far East, the Pacific theatre, apparently Sky have bought the UK rights.

Can’t wait to see this: [youtube trailer]

I’ve always said that if I ever lost one of my B.O.B DVDs I would replace the set, and now that Blu-ray has come along… I probably will!

The Sky Mobile App: Review & How to cancel!

In early November O2 iPhone and BSkyB announced that they were releasing a limited free trial of the Sky News & Sports Mobile App [iTMS link] for the iPhone.

Pretty cool? Yes, three months of free small-screen Premiership Football, NHL Ice Hockey and…. wrestling. Pretty lame? Well, craning your neck to watch a three inch screen while sitting or in bed really there isn’t a comfortable way to do it without some form of scaffolding in front of your face. Regardless you can’t look a gift horse in the mouth, and so I enjoyed the ability to flick on or off during a big game to see the score and maybe a highlight or two.

The service costs £6 per month and auto subscribes after the trial ends and I believe it’s on a rolling monthly basis.

I signed up on 11 November, the week the offer was released with an iCal event scheduled for the week before the free offer expired, so that Mr Mastercard didn’t come into play.

According to the offer’s FAQs page you can cancel by going to this SkyID website – I didn’t see that before I cancelled my subscription, so I can’t vouch for whether it works or not.

How to cancel

The MySky site claims that as a non residential Sky Subscriber I’m a ‘guest user’ and not able to view or manipulate my account – so [unless the above link works] you need to call Sky Mobile enquires, the number for which is 08442 411 531 in the UK (& ROI it seems). All you need to do is enter your home number, then confirm your username and email address and tell them you wish to cancel the contract. Quite easy.

Verdict

Good application well executed, but without a TV-out (does the iPhone have one?) or some form of phone stand to relieve your neck muscles it’s a bit of a pain to use.

Lent 2010

Every year since I was very young I’ve been coerced into giving up something for Lent. If you don’t know what that is check out the Wikipedia article for loads of information — perhaps more than you need.

Basically Lent is a Christian festival bookended by Shrove Tuesday & Ash Wednesday (that’s Today) on the Winter side and Palm Sunday / Holy Week / Easter Sunday on the other. The period of forty days reflects the forty days that Jesus spent in the desert being tempted, before his final journey to Jerusalem before being tried, sentenced and crucified.

We are told in the Bible that after being baptised by John (the Baptist), Jesus fasted for forty days in the desert. During this time, the devil appeared to Jesus and tempted him. Jesus having refused each temptation, the devil departed and angels came and brought nourishment to Jesus. [source]

Any lenten sacrifice we make is a pale imitation of Jesus’ trials in the desert, but it is part of the journey of a Christian to become more like Christ and as long as what you “give up” isn’t genuinely trivial it can be of benefit.

When I was younger it was chocolate, or sweets, or both which from the perspective of a child was difficult; this year I’ve decided to forsake my Facebook and Twitter accounts from Today until Easter. This is neither equivalent to fasting forty nor a single day, but I do believe it will improve my lifestyle, productivity in work, and encourage me to just turn off the computer instead of wasting time. I’ve decided that instead of consuming so much social media I will instead read more, and write more, hence this first personal blog post in well over a year.

Hopefully I’ll have something to write about.

Are you giving up something/anything for lent?

Love Tennis?

My old friend Chris has just launched a tennis related blog at http://lovetennisblog.com/

If that’s your sort of thing, check it out!

Ruby on Rails: Get some random records

EDIT AGAIN: Much better..

To get a ‘num_reqd’ array of random objects, you can use something like this.

  named_scope :large, :conditions => ['image_file_name IS NOT ?', nil]
  named_scope :small, :conditions => ['small_image_file_name IS NOT ?', nil] 

  def self.get(num_reqd,features_arr=[],size="large")
    if size=="small"
      collection = Feature.small
    elsif size=="large"
      collection = Feature.large
    end

    return collection if collection.size <= num_reqd

    # num_reqd.times{feature=self.random(collection); features_arr.push(feature) unless features_arr.include?(feature)}
    features_arr = collection.find(:all, :limit => num_reqd, :o rder => 'rand()')

    if features_arr.size < num_reqd
      return Feature.get(num_reqd, features_arr, size)
    else
      return features_arr
    end
  end

EDIT: It's much cleaner and easier to use something in the form below, though the following is probably useful in some cases and is possibly interesting as a code snippet.

User.find(:all, :o rder => 'rand()')


---- end edit.

Working from a baseline of the code found here at almosteffortless.com I've extended a 'random record grabber' to get a specific number of unique records from a Rails data table.

Basically - the random method makes a database call to get the ids of a table, and sends back a random entry. self.get is a recursive method which provides a 'total number required' and a base array to start from (if you wish to specify entries to appear in the otherwise 'random' list). First year computer science should help get your head around the rest!

def self.random
    ids = connection.select_all("SELECT id FROM features")
    find(ids[rand(ids.length)]["id"].to_i) unless ids.blank?
  end

  def self.get(num_reqd,features_arr=[])
    num_reqd.times{feature=self.random; features_arr.push(feature) unless features_arr.include?(feature)}

    if features_arr.size < num_reqd
      return Feature.get(num_reqd, features_arr)
    else
      return features_arr
    end
  end

Be aware, there is more efficiency to be found in the database call (i.e. it should be cached). Also, you'll want to be sure there are at least 'num_reqd' items in the database.

Using another computer for your heroku app

Quite easy, but without knowing how would you know… (the docs!)

The Collaborator Quick Start guide is the place to be.

[sudo] gem install heroku
# then
heroku keys:add
#your login details are taken and ssh key uploaded automatically
git clone git@heroku.com:APPNAME.git -o production
#using the proper git repo name.git

if git push heroku fails then do this:

git remote -v
#Hopefully you will see an origin or heroku

#If not, find out your git url:
heroku list
heroku info --app your-app-name

git remote add heroku git-url
(this bit from google groups)

Leopard Mac Refuses to Stay Asleep…

The last week or so my Leopard iMac has been waking up in the middle of the night… it’s quite annoying.

Finally found the answer here:
macrumors – leopard imac waking from sleep issue.

It turns out the problem is caused by having Screen Sharing enabled, and the 5900 port (VNC) being exposed to the outside world through my router. While this allows me to remote connect from another Mac ….

The problem lies in the fact that the screen comes to life whenever ANYTHING connects to this port, be it another Mac, or a port scanner… before even authentication takes place. Tested this by trying to SSH to that port – bang, my monitors come to life.

Fixed it by removing the external port forward, and just using SSH into the Mac. Apple needs to stop waking up the screens until authentication has taken place.

Basically this means that the really awesome TouchPad app that got Fireballed a few weeks ago is only really useful if you turn off your computer (completely) at night or are willing to manually turn off port 5900 (the VNC port).

The weird thing is that this worked fine on Tiger.

So perhaps with Snow Leopard this won’t be a problem… ?

Simple Thinking Sphinx on Dreamhost

*** Please note – this will probably not work (at all) (for more than a day of light use) without Cron use. And isn’t at all authorised by Dreamhost!! ***

For a recent client project I’ve used a Dreamhost unlimited account, which for value compared with the resources available and the fact that you don’t have to do any building or setting up of the server environment makes it an easy win for a site that’s not going to have a huge amount of traffic or a large amount of processing.

Post-launch I got to work putting together a basic search engine and here’s a quick run through of the steps it took to get a very simple Sphinx instance working on Dreamhost, and a few hurdles thrown in the way by various googled articles.

Development Environment

Using the guide from FG install Sphinx locally:

curl -O http://sphinxsearch.com/downloads/sphinx-0.9.8-rc2.tar.gz
tar zxvf sphinx-0.9.8-rc2.tar.gz
cd sphinx-0.9.8-rc2
./configure
make
sudo make install

then install the TS plugin into your application

script/plugin install git://github.com/freelancing-god/thinking-sphinx.git

Any problems with that, check out the FG page linked.

Getting a basic search going

Following tutorials such as the Sphinx Railscast will get you there pretty quick.

In your searchable model you need to define an index


class Page < ActiveRecord::Base
  define_index do
    indexes :title
    indexes :long
    indexes :short
  end ...

Run the indexer and start the Sphinx instance:


rake thinking_sphinx:index
rake thinking_sphinx:start

After this you'll be able to search on your object. So using script/console

@searched_pages = Page.search("query")

will return what you're looking for!

Setting up Dreamhost

First things first you need to install Sphinx in your local area, as posted by Hugh Evans:

cd ~/
mkdir -p local
wget http://sphinxsearch.com/downloads/sphinx-0.9.8.1.tar.gz
tar -xzf sphinx-0.9.8.1.tar.gz
cd sphinx-0.9.8.1/
./configure --prefix=$HOME/local/ --exec-prefix=$HOME/local/
make
make install

then set up the PATHs

echo "export PATH=\"$PATH:~/local/bin\"" >> ~/.bash_profile
source ~/.bash_profile

You can choose to set up a CRON task at this point too, but I'm not going into that.

Also at this point in the there's talk of using Sphinx being anti TOS in DH's eyes... but we'll see does the process get killed or not!

Configuring Sphinx for DH

Create a file called sphinx.yml in the RAILS_ROOT/config/ folder.

Because Dreamhost uses an externally referenced MySQL server instead of localhost you need to set up the sql_* parameters:


  sql_host: "mysql.YOURDOMAIN"
  sql_port: 3306
  sql_user: "USER"
  sql_password: "PASSWORD"
  sql_database: "DATABASE"

And because you installed Sphinx in your local area:


  bin_path: '/home/YOURUSERNAME/local/bin'

Finally, after setting whatever memory/fine tuning settings you wish/require set up the locations for the Sphinx files:


  config_file: "/home/YOURUSERNAME/DOMAIN.co.uk/shared/production.sphinx.conf"
  searchd_log_file: "/home/YOURUSERNAME/DOMAIN.co.uk/shared/log/searchd.log"
  query_log_file: "/home/YOURUSERNAME/DOMAIN.co.uk/shared/log/searchd.query.log"
  pid_file: "/home/YOURUSERNAME/DOMAIN.co.uk/shared/log/searchd.production.pid"
  searchd_file_path: "/home/YOURUSERNAME/DOMAIN.co.uk/shared/db/sphinx"

That should be you ready to start deploying.

Deploying

Using Git + Capistrano for deployment (and Passenger for the http server) my deploy.rb's namespace area looks like this:


namespace :deploy do
  task :restart do
    after_symlink
    restart_sphinx
    run "touch #{deploy_to}/current/tmp/restart.txt"
  end

  task :start do
    # nothing  (this avoids the 'spin' script issue)
  end

  desc "Re-establish symlinks"
  task :after_symlink do
    run <<-CMD
      rm -fr #{release_path}/db/sphinx &&
      ln -nfs #{shared_path}/db/sphinx #{release_path}/db/sphinx
    CMD
  end

  desc "Stop the sphinx server"
  task :stop_sphinx , :roles => :app do
    run "cd #{current_path} && rake thinking_sphinx:stop RAILS_ENV=production"
  end

  desc "Start the sphinx server"
  task :start_sphinx, :roles => :app do
    run "cd #{current_path} && rake thinking_sphinx:configure RAILS_ENV=production && rake thinking_sphinx:index RAILS_ENV=production && rake thinking_sphinx:start RAILS_ENV=production"
  end

  desc "Restart the sphinx server"
  task :restart_sphinx, :roles => :app do
    stop_sphinx
    start_sphinx
  end

end

There's probably a neater way to do this, but basically this makes sure Sphinx's indexes and conf files live in the shared deployment folder.

I recommend you try all this in a staging area first, obviously... and you can use Dreamhost's control panel to set up a staging subdomain with a new database in whatever fashion you prefer.

Any problems with this script flag them up, please! This is as much for my future reference as you googlies out there.