Archive for August, 2009

Manage Fixtures with Yaml DB Plugin for Rails

Posted 22 Aug 2009 — by admin
Category Ruby on Rails

Get the plugin like so…

script/plugin install git://github.com/adamwiggins/yaml_db.git

This command will dump your data

rake db:data:dump

And load it back

rake db:data:load

Beautiful :) More info here

http://blog.heroku.com/archives/2007/11/23/yamldb_for_databaseindependent_data_dumps/

and

http://stackoverflow.com/questions/490507/best-way-to-export-a-database-table-to-a-yaml-file

Send Mail in Ruby with a Pony

Posted 19 Aug 2009 — by admin
Category Programming

Great little gem that let’s you quickly and easily send out mail from your ruby scripts.

gem install pony

require 'rubygems'
require 'pony'

Pony.mail :from=>"me@example.com", :to=>"you@example.com", :subject=>"hello", :body=>"world"

Install do_mysql Ruby Gem on Mac OS X

Posted 19 Aug 2009 — by admin
Category Databases

I ran into the same problem when installing mysql gem for Rails development. This fix worked for me http://seanbehan.com/programming/fixing-mysql-for-rails-2-2-development-on-mac-os-x/

The same thing works with the data objects gem. Just specify the path the mysql config that it’s using and the gem should install just fine.

gem install do_mysql -- --with-mysql-config=/opt/local/lib/mysql5/bin/mysql_config

Installing Redis Server and Client on Mac OS X and Ubuntu

Posted 16 Aug 2009 — by admin
Category Databases
wget http://redis.googlecode.com/files/redis-0.900_2.tar.gz
tar xzvf redis-0.900_2.tar.gz
cd redis-0.900
make
mv redis-server /usr/bin/
mv redis-cli /usr/bin/

Installing Monk on Ubuntu with Ruby Gems

Posted 16 Aug 2009 — by admin
Category Monk

Installing monk like this will fail

gem install monk

You’ll need to install the wycats-thor gem first with this command

gem install wycats-thor -s http://gems.github.com

Manage Sinatra Server in Development Mode with Shotgun

Posted 12 Aug 2009 — by admin
Category Sinatra

Sinatra won’t reload your files. So if you’re developing your app and want to see any changes made in the browser, install the shotgun gem.

gem install shotgun

You can then use shotgun to run your server

shotgun your_sinatra_ditty.rb

Presto, your ditty will never be out of key :)

Deploy Sintra App on Ubuntu Using Apache2 and Phusion Passenger Module

Posted 12 Aug 2009 — by admin
Category Sinatra

Check it out http://sinatra.seanbehan.com/
This assumes Apache2 and the Phusion Passenger module have already been installed. If not you can get up to speed w/ this resource http://seanbehan.com/ruby-on-rails/new-ubuntu-slice-apache-mysql-php-ruby-on-rails-git-and/

First you need Sinatra, so install the gem

gem install sinatra

We need a home for Frank, so create the minimum number of directories in our web directory. The public directory is where we’ll server images, stylesheets, javascript etc. The tmp directory will be where we control Passenger.

cd /var/www/sinatra
mkdir myapp
mkdir myapp/tmp
mkdir myapp/public

cd myapp
vim index.rb
#in index.rb
get '/' do
  "Fly me to the moon..."
end

Next we need a configuration file for Rack, important the file extension is “.ru” not .rb!

vim config.ru
require 'rubygems'
require 'sinatra'

Sinatra::Application.default_options.merge!(
  :run => false,
  :env => ENV['RACK_ENV']
)

require 'index'
run Sinatra.application

Set up the virtual host


  ServerName www.myapp.com
  DocumentRoot /var/www/sinatra/public

Now you can restart the app if you make adjustments!

touch tmp/restart.txt

Keep on singing :)

Inspired by http://blog.zerosum.org/2008/7/4/passenger-3-sinatra

Double Click Event Using Prototype Javascript Framework

Posted 11 Aug 2009 — by admin
Category Programming

Super simple to get double click “desktop” like functionality out of Prototype! For some reason, googling it doesn’t yield many useful results. http://www.google.com/#hl=en&q=double+click+in+prototype+javascript&aq=f&oq=&aqi=&fp=peEfEjG9pWY :(

Anyway, here is the code

	document.observe('dblclick', function(){
		alert("Hello World");
	});

Change default ssh port number on Ubuntu

Posted 10 Aug 2009 — by admin
Category Linux

Login as the root user or as a user that can execute sudo commands.

#open this file for editing...
vim /etc/ssh/sshd_config

Find the line that reads

Port 22

Change this to an different and an available port number…

Port 8000

Next reload ssh

/etc/init.d/ssh reload

You won’t be kicked out of your session. But if you want to open a new connection to your server you need to specify the port number for the connection.

ssh -p8000 root@yourdomain.com

Using sendmail to send mail on ubuntu box

Posted 07 Aug 2009 — by admin
Category Linux

I normally install postfix for my MTA. However, I’ve never really used sendmail so I’d decide to give it a whirl for a new application I’m working on. I don’t use it for anything but handling the mail that the application needs to send out, like new user welcome emails, password resets, etc.

apt-get install sendmail

Sendmail, unlike postfix, won’t work out of the box. Postfix will prompt you for the necessary config setup when running the install. Sendmail won’t, and therefore it’s not ‘out of the box’. You’ll have to make some modifications on your own. Nothing major but this is what I’ve found in order to get it to work, reliably and quickly. The first thing I did was add the fully qualified domain name to my /etc/hosts file

#vim /etc/hosts
127.0.0.1 www.mydomain.com

After this I added the fully qualified domain name to my apache default configuration file

#/etc/apache2/sites-available/default
ServerName www.mydomain.com
#vhost info etc...

Reload and restart…

/etc/init.d/apache2 force-reload
/etc/init.d/sendmail restart

You can test sendmail like so

sendmail email@example.com
hello
from
me
. 

This should deliver a message to you (the “.” on a new line, followed by a new line, closes the message).