Apr 29
I’ve been working on a project recently that’s needed me to generate human readable (and Google readable) permalinks to pages. As a default these permalinks are generated from the title of the associated object. This was all working until I realised that I had words like ‘café’ in the title. Using my existing algorithm any letters other than A-Z, a-z were removed, thus turning ‘café’ into ‘caf’. Not very human or Google readable.
I found an excellent article on Obie Fernandez’s blog showing how he tackled this problem for a job he was working on and all is now wonderful again!!!
Image credit
Apr 24
I’ve been looking into collision algorithms for a game of Pong I am going to be writing. I found a really good guide to circle to circle collisons.
I was looking for libraries to do vector manipulation and stumbled across GNU GSL - a scientific library, written in C, that includes vector and matrix manipulation classes.
I love the Ruby language as readers of my other blog would know. I found Ruby bindings to GSL. To install this on OS X Leopard with MacPorts installed you download the Ruby GSL bindings then:
% sudo port install gsl plotutils
% tar zxf rb-gsl-1.10.3.tar.gz
% cd rb-gsl-1.10.3
% ruby setup.rb config
% ruby setup.rb setup
% sudo ruby setup.rb install
And your good to go!
Apr 04
A really easy way of beta testing your Ruby on Rails application is to use Basic HTTP Authentication. There are methods built into Rails to do this in your application controller just put
before_filter :http_authenticate
def http_authenticate
authenticate_or_request_with_http_basic do |username, password|
username == 'my_username' && password == 'my_password'
end
end
Every request will put through this filter and users will not be able to use your site without this username and password.
Apr 04
I’m currently working on an app that we’re going to be deploying on Brightbox. However, I ran into a couple of problems when deploying with their gem.
First, my app’s Subversion repository isn’t on the Brightbox server. This was simple, in the config/deploy.rb file, change the address of the repository to the address of the server. Create a SSH key on the Brightbox box (mouthful!) and add the public key to the .ssh/authorized_keys on my Subversion server and away we go!
Second, I don’t have my
config/database.yml in the svn repository. The reasons for this are
# Security – if someone checks out my code they end up knowing my passwords.
# there are several people working on the project so every time a commit/update was performed, it would reset your
config/database.yml file to whatever the last checked in version was, annoying.
In the
config/deploy.rb file I added:
task :after_update_code do
run( "cp $HOME/database.yml #{release_path}/config/")
end
to the config file and put the database.yml file in my home directory. Now, after the code’s been checked out the
database.yml file is copied into the correct place. Hurrah!
The third thing was really my fault. I’d put a - in my database name. The Brightbox gem doesn’t escape the CREATE DATABASE database_name database name (it should really be CREATE DATABASE `database_name`). MySQL was interpreting my - as subtraction, oops. I changed the name of the database to only use underscores and it worked fine.
The final thing was as far as I can tell the
gem is running the
Capistrano setup task. This sets up the
shared directory in your application deployment and will not run without it. I added
task :before_cold_deploy do
setup
end
to
config/deploy.rb to run the
Capistrano setup task.
Then… HURRRAH! It works!!!