Archive for the 'Rails' Category

Installing git from source ubuntu

May 14th, 2009 by pyrat

When you have an old version of ubuntu but want a new version of git. And potentially have it already installed.

sudo apt-get update
sudo apt-get remove git-core
sudo apt-get install tcl8.4 tk8.4
sudo apt-get build-dep git-core
 
wget http://kernel.org/pub/software/scm/git/git-1.6.3.1.tar.gz
tar -zxvf git-1.6.3.1.tar.gz
cd git-1.6.3.1
./configure
make
sudo make install
 
 
sudo ln -s /usr/local/bin/git /usr/bin/git

Installing ImageMagick / Rmagick on Ubuntu Hardy

May 14th, 2009 by pyrat

Mainly to help me remember in the future. Might be useful to you also..

  sudo apt-get update
  sudo apt-get install imagemagick
  sudo apt-get install libmagick9-dev
  sudo gem install rmagick

Introducing Daily Photo – Scheduled Uploads to Flickr

May 9th, 2009 by pyrat

Daily Photo Scheduled Flickr Uploads
Daily Photo

Introducing daily photo a wee web application which lets you upload photos to flickr on a daily basis. This allows you to make the most of RSS feeds and social applications that link to your flickr account.

Daily photo will also be useful if you run a photo blog which is powered off flickr. The ability to decide when photos appear is functionality which flickr is sorely missing.

Daily photo is a wee app, written in hours rather than days. Functionality is as minimal as possible while getting the job done. Steps to getting your flickr uploads scheduled are as follows:

  • Go to daily photo
  • Sign up for an account
  • Check your email and confirm your email address
  • You will be redirected to flickr where you confirm that daily photo can have access to your account for uploading of photos.
  • Upload photos to daily photo with names, descriptions and tags. Define on what day you want the photo to be uploaded to flickr.
  • Sit back watch your flickr account update automagically!

Front page
Front page

Your Photos upload queue
Your Photos upload queue

So if you have a need for daily photo, your welcome! Fill your boots.

libxml-ruby on ubuntu

May 7th, 2009 by pyrat

  sudo apt-get install libxml2 libxml2-dev
  sudo gem install libxml-ruby

Testing your subdomain based rails application

April 14th, 2009 by pyrat

no www
(Courtesy: flickr)

I was looking for a way to set the request host when testing an application I am currently working on. It has ‘basecamp-style’ subdomains; I wanted to test these.

Insert the following snippet at the bottom of test_helper.rb to set the host to ‘test.local.host’

  # This is a hack on rails to allow testing of subdomain based systems.
  require 'active_support/test_case'
  module ActionController
    class TestCase < ActiveSupport::TestCase
      def setup_controller_request_and_response
        @controller = self.class.controller_class.new
        @controller.request = @request = TestRequest.new
        @response = TestResponse.new
        @request.host = "test.local.host"
        @controller.params = {}
        @controller.send(:initialize_current_url)
      end
    end
  end

Going Live with Rails

March 27th, 2009 by pyrat

Once an application gets to the production stage, people get all excited. The project is coming to fruition. Is it all over? No, its just the beginning. Ideally, you want your application to run trouble-free while you sit back and relax.

In this short article I will describe the steps that I go through when setting up a production environment. If you are interested in this subject and want a better guide please refer to deploying rails applications

Monit

This will keep everything running, I use this rather than god as it seems more stable and less memory hungry. I have used god a bit; the name also puts me off.

We still run ubuntu not cool enough for CentOS yet so.

aptitude install monit

Example monit config for rails app server with passenger.

Logrotate

You dont want massive logs slowing your app down after its been running 6 months, remember to configure this as it is often overlooked.

Passenger

Passenger or mod_rails is in active development and is used by a lot of the big ruby on rails companies and on the big sites. Deployment of production level apps used to be about packs of mongrels and frontend lightweight webservers. No longer.

Capistrano-ext

Deployment with capistrano is standard within the community, with the capistrano-ext gem you can run multistage deployments.

So

cap production deploy

Will deploy to production.

A list of my capistrano bash aliases are as follows. I find them very useful.

alias cpd="cap deploy"
alias cpdm="cap deploy:migrations"
alias cpsd="cap staging deploy"
alias cpsdm="cap staging deploy:migrations"
alias cppd="cap production deploy"
alias cppdm="cap production deploy:migrations"
alias cptd="cap testing deploy"
alias cptdm="cap testing deploy:migrations"

Backups

You need to be covered if something goes wrong. You need to backup static assets and database. I will not go into this here. Ideally, backup to an offsite location. eg. Amazon S3.

Exception notification

Make sure you have the exception notification plugin on the go, so you get emails when things break.

New Relic

The new relic performance monitoring service is great for keeping an eye on things within your production application. And there is a free version!

Version Control

Create a production branch in your version control and deploy from that. Then as you work for bugfixes and new features on master you then merge with the production branch for deployment.

eg.

To merge master with production.

git checkout production
git merge master

You can then also do critical changes to the production branch. And to get this back into master.

git checkout master
git merge production

Thats all for now. Any comments?

Autotest Growl Notifications

March 23rd, 2009 by pyrat

growlers

I recently have had to set this up on another machine so here is a little guide which might help you if you want to setup growl notification of autotest results.

  • Make sure growl is installed
  • Make sure growlnotify is installed you will find it in the Extras directory of the Growl dmg (copy growlnotify to /usr/local/bin to test this open a terminal and type growlnotify)
  • Add the following to a file called ~/.autotest

  require 'autotest/redgreen'
  require 'autotest/timestamp'
 
  module Autotest::Growl
 
    def self.growl(title, msg, img, pri=0, sticky="")
      system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}" 
    end
 
    Autotest.add_hook :ran_command do |at|
      image_root = "~/.autotest_images" 
      results = [at.results].flatten.join("\n")
      output = results.slice(/(\d+)\stests,\s(\d+)\sassertions,\s(\d+)\sfailures,\s(\d+)\serrors/)
      if output
        if $~[3].to_i > 0 || $~[4].to_i > 0
          growl "FAIL", "#{output}", "#{image_root}/fail.png", 2
        else
          growl "Pass", "#{output}", "#{image_root}/pass.png" 
        end
      end
    end
 
  end

Extract this file to ~/.autotest_images directory.

You are now good to go!

Deploy when github goes down

November 27th, 2008 by pyrat


You are not screwed

As git is distributed, the repository on your local machine is good enough to deploy from.

First start a git server on your local machine.

  git daemon --base-path=/projects/rails_apps/ --export-all

Then change your capistrano recipe to deploy with the copy command and change the repo to point to your local machine.

  set :deploy_via, :copy
  set :repository 'git://127.0.0.1/proj_name'

Where in this example the code resides at */projects/rails_apps/proj_name*

Now capistrano will deploy from your local repository, thus avoiding the currently melted github

There are other options which have been listed by chris wanstrath in the following article

Example ubuntu hardy slicehost monit config

November 18th, 2008 by pyrat

pastie day

I am using mod_rails aka passenger more and more in production server setups. This pastie shows a common setup for a standard ubuntu slice. You can almost cut n paste this config.

Web interface for monit is disabled.

wee_lightbox rails plugin

August 6th, 2008 by pyrat

Overview

This is a packaged version of lightbox for viewing images on the screen in the popular lightbox design pattern. The plugin includes some view helpers and an automatic install script to make life easier.

Please refer to the lightbox docs for more info. Included are some rails helpers for easy integration into your site. The lightbox javascript is slightly tweaked to configure the location of images and increase the speed of resize.

You can edit lightbox.js to further tweak these if you wish.

Install

If you install from github with rails 2.1+ it will install the files into your public directory. If you install with another method, you may need to issue a recursive copy command manually.

Also this install script is untested on windows.

Usage Example

In your layout add the following in the head section.

<%= javascript_include_tag :defaults %> 
<%= yield :page_includes %>

In your template:

<%= load_lightbox %>

For each image that you would like to make a lightbox to

<%= lightbox_to('/images/small.gif', '/images/large.gif', "Tasty image caption")

If you want to have more than one lightbox on a page and have the lightbox operate with a slideshow between images..

<%= lightbox_to('/images/small.gif', '/images/large.gif', "Tasty image caption", "group_name")

Where group name needs to be the same for all images in the slideshow.

Github project page