Posted by ant
February 13th, 2009
Filed in Sysadmin
sed 's/searchstring/replacedstr/g' <infile.txt >outfile.txt
Which performs a substitute (s) globally (g). Don’t forget to escape necessary regular expression characters such as / and . So in the above context
sed 's/sub\.testdomain\.com/www\.realdomain\.com/g' <dump.sql >outdump.sql
Posted by ant
January 9th, 2009
Filed in Rails, Sysadmin
Setup Phusion Passenger (mod_rails) Apache module
sudo gem install passenger- copy the snippet from the terminal and into a file called
/etc/apache2/other/passenger.conf - Restart Apache –
sudo apachectl restart
Install Passenger PreferencePane
This makes it really easy to create hosts for your Rails applications and configure mod_rails in System Preferences.- Download Passenger PreferencePane
- Double click to install, have a play in System Preferences.
Install Upload Progress Apache module
git clone http://github.com/drogus/apache-upload-progress-module.gitcd apache-upload-progress-modulesudo apxs -c -Wc,-arch -Wc,i386 -Wl,-arch -Wl,i386 -i -a mod_upload_progress.c- Change the architecture string (i386) if yours is different
- This installs and enables the module in
/etc/apache2/httpd.conf
/etc/apache2/passenger_pane_vhosts. To enable upload progress for a site edit the .conf file appropriate for your site and insert the below snippet just before the </VirtualHost> line.
<IfModule upload_progress_module>
<Location />
# enable the tracking of uploads anywhere down from /
TrackUploads On
</Location>
<Location /progress>
# progress JSON will appear at /progress
ReportUploads On
</Location>
</IfModule>
Reconfigure Passenger PreferencePane to insert upload_module configuration
The application I’m currently developing requires upload progress and Apache needs to be able to follow symbolic links as I have certain assets stored outside of the main Rails application. The default Passenger PreferencePane configuration does not include these options.
I’ve updated the file that creates this configuration in a forked github repository. Dependent on where you installed the PreferencePane this file will either be in
~/Library/PreferencePanes/Passenger.prefPane/Contents/Resources– Installed only for your user- or
/Library/PreferencePanes/Passenger.prefPane/Contents/Resources– Installed for all users
Download PassengerApplication.rb and copy this file and the above configuration will be created.
Thoughtbot Paperclip
Paperclip is a fantastic file attachment plugin. It just uses ImageMagick to do it’s image processing. As long as the executables are in your path image scaling just works. It’s a whole load easier than configuring RMagick.
However, none of my images were rescaling and were dumping a strange error saying that Paperclip couldn’t determine the type of my file. I spent an hour trying to work out what the problem was, then I realised… The ImageMagick commands weren’t in the path for Apache. I tried various things to get this working, but tracked it down to a setting that can be put in one of your environment files.
Paperclip.options[:command_path] = "/opt/local/bin"
A quick restart of Rails later and it’s all working. This is what Paperclip was chucking out to my the development log:
[paperclip] An error was received while processing: #<Paperclip::NotIdentifiedByImageMagickError: /tmp/stream.637.0 is not recognized by the 'identify' command.>
Posted by ant
October 24th, 2008
Filed in Rails, Sysadmin
sudo apt-get install imagemagick sudo apt-get install libmagick9-dev sudo gem install rmagick
Posted by ant
October 7th, 2008
Filed in Rails, Sysadmin
.git/config .gitmodulesThese references need removing. The cached local copy can be removed with
git rm --cached path/to/submodule rm -r path/to/submoduleNote the lack of the trailing slash!
Posted by ant
October 1st, 2008
Filed in Rails, Sysadmin
I’ve been working with Git for my source control recently. It seems to work more appropriately for me than Subversion. This is primarily because you don’t have to be connected to the Internet to perform commits to the versioning system, it keeps the whole versioning database in a subdirectory called .git.
I did however, have some problems getting a remote repository setup stored on my Dreamhost account, but luckily I found some instructions on autopragmatic.com. Here I want to record the way to create a new repository
On your local machine
mkdir repo.git
cd repo.git
git init
touch .gitignore
git add .
git commit -m "added .gitignore"
# Down to here creates the local git repository and does first commit
git remote add origin ssh://user@example.com/home/user/git/repo.git
git config branch.master.remote origin
git config branch.master.merge refs/heads/master
# Configure the Git repository
git push --all
# push the changes to the remote Git repository.
Posted by ant
June 18th, 2008
Filed in Sysadmin, Thoughts
Ever since I installed Adobe Creative Suite I’ve been annoyed by the fact it installs an Acrobat plugin for Safari that overwrites the default Apple Preview view of PDFs. I hate it! It takes ages to start up, it’s generally slow once it’s started, it looks pretty ugly, it has far too many features for what I want in a browser, the list goes on…
However, I’ve just found where the little bugger lives! Just quit Safari, delete /library/Internet Plug-Ins/AdobePDFViewer.plugin, restart Safari and hey presto, it’s gone, fantastic!
Posted by ant
May 13th, 2008
Filed in Sysadmin
I’ve been installing the LAMP stack on an Ubuntu based server for a client. They rely on the version of LibGD that’s bundled with PHP5. This version includes certain functions including imagerotate() and others.
It seems that the people who build Ubuntu (and Debian) distribution do not want to compile PHP5 with the version of GD that comes bundled with PHP5. As far as I can tell the guys at Ubuntu (and Debian) consider this to be a fork of the original GD library and think that this could be a security risk. Their stance on it is that if PHP want to use this version then they should contribute the changes that have been made to the original GD library back to the core project. This seems fair enough, but unfortunately I can’t immediately change the direction of an open source project this big – or probably any project, come to think about it!
After a bit of rummaging around on the Internet I found nothing to do with actually compiling in this support, so I tried to work out how to do this… In theory! I found a link on Ubuntu forums about including the GMP library I roughly followed this through.
To install the required packages and download the source code for PHP5:
# Install build tools, debian helpers and fakeroot
apt-get install build-essential debhelper fakeroot
# source code should reside in /usr/src
cd /usr/src
# Download PHP source
apt-get source php5
# Install all packages required to build PHP5
apt-get build-dep php5
cd php5-5.2.3
How a package is compiled is set within the files contained in the debian directory of a package. Rules for configuring the compile process can be found in debian/rules. In this file there is a line that reads --with-gd=shared,/usr --enable-gd-native-ttf \. This links to the Ubuntu distributed version of LibGD as a shared library. It is part of the autoconf script that customises the compilation of PHP. I replaced this line with --with-gd=shared --enable-gd-native-ttf \. This causes the compilation process to use the bundled version of GD and make a shared library.
# build the php5-* packages
dpkg-buildpackage -rfakeroot
cd ..
# Install the new php5-gd package
dpkg -i php5-gd_5.2.3-1ubuntu6.3_i386.deb
A quick /etc/init.d/apache2 restart and hey presto, you should be using the bundled version of LibGD for PHP. Hurrah!
Posted by ant
April 4th, 2008
Filed in Rails, Sysadmin
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.
Posted by ant
April 4th, 2008
Filed in Rails, Sysadmin
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!
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.
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!!!
Posted by ant
March 4th, 2008
Filed in Sysadmin

Today whilst trying to pack our Zope database I couldn’t connect to the server on the port I needed to because of a firewall issue. I went searching to see if I could tunnel into the server using an already open port.
I was unaware that you can forward ports if you have SSH access to the server, for example
ssh -L 3001:server.example.com:3000 -N user@server.example.com
would forward all local requests to port 3001 on the local machine to port 3000 on server.example.com. The traffic bound for the remote machine is encrypted and sent over port 22 like a normal SSH connection… Brilliant!
Blog uses Mephisto
Design from OSWD
by dreamLogic
