Monday, January 31, 2011

Install Java 6 on Ubuntu 10.10
$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk 

$ sudo update-java-alternatives -s java-6-sun

Thursday, January 20, 2011

Copy music from an IPod to iTunes (Mac OS X)

I recently picked up a new iPod Nano and needed to get music off my old iPod onto the new device. Unfortunately I also recently had a hard drive crash on the laptop that held my iTunes library. Here are the steps I used to pull music off my old iPod onto my new laptop and ultimately onto my new Nano. 
  1. Plug in the IPod you want to copy music from
  2. In iTunes, select your iPod from the left hand menu "Devices > Your iPod". Under "Options" check the box "Enable disk use"
  3. Open a new Finder Window and you should see your iPod listed under devices
  4. Navigate to "Your iPod > iPod Control"
  5. Copy the Music folder to your drive. Let it finish.
  6. The Music folder needs to be "un-hidden" before you can import it into iTunes. Open a terminal window and navigate to the folder where you copied the Music folder. Run the following command to unhide Music
  7. $ chflags -R nohidden Music
    
    The folder should now be accesible in iTunes
  8. In iTunes select "File >  Add to Library"
  9. Select the Music folder
  10. Music from your iPod should now be copied to your library. When it's finished you can plug in a different iPod and sync your music.
Hope this helps.

Use Ruby To Retrieve a User's Public Twitter Timeline

Install the twitter gem:
$ gem install Twitter

Write the code:
#!/usr/bin/env ruby
require 'rubygems'
require 'twitter'

screen_name =  String.new ARGV[0]

timeline = Twitter.user_timeline(screen_name)
timeline.each do |t|
  puts "#{t.text}"
end

Run the code:
ruby twitter.rb ryantremaine

Saturday, January 1, 2011

Setting Up Rails 3.0 On EC2

This tutorial assumes you followed my steps in Creating a (free) Linux EC2 Instance. If you're doing this on a 32-bit instance step 8 will be slightly different.

1. SSH into your instance
$ ssh ec2-user@50.16.195.2 -i ~/rtremainekey.pem
2. Install GCC - enter "y" when prompted
$ sudo yum install gcc
3. Install MySQL - enter "y" when prompted
$ sudo yum install mysql-server mysql-libs mysql-devel
4. Install Ruby - enter "y" when prompted
sudo yum install ruby ruby-devel ruby-irb ruby-rdoc ruby-ri
5. Install RubyGems
$ cd /tmp
$ wget -q http://production.cf.rubygems.org/rubygems/rubygems-1.3.7.tgz
$ tar xzf rubygems-1.3.7.tgz
$ cd rubygems-1.3.7
$ sudo ruby setup.rb
6. Install Rails - this one will take a while
$ sudo gem install rails
7. Start MySQL
$ sudo /etc/init.d/mysqld start
8. Give the root MySQL user a password
$ mysqladmin -u root password yourpassword
9. Create symlinks to MySQL libraries
$ cd /usr/lib64/
$ sudo ln -s mysql/libmysqlclient.so
$ sudo ln -s mysql/libmysqlclient.so.16
$ sudo ln -s mysql/libmysqlclient_r.so
$ sudo ln -s mysql/libmysqlclient_r.so.16
10. Install MySQL Gem
Expect to see some "No definition" errors.
$ sudo gem install mysql
11. Open Port 3000
To keep things simple I'm opening port 3000 which is the default WEBrick binding. Login to the AWS Management Console and select the security group for your instance. Add a new entry with the following values.
  • Connection Method: HTTP
  • Protocol: TCP
  • From Port: 3000
  • To Port: 3000


The remaining steps are taken from the Getting Started with Rails tutorial. I'm only using the first few steps here to verify Rails and MySQL are configured and running correctly.


12. Create A Test Project
$ cd ~
$ rails new blog --database=mysql
$ cd blog
$ sudo bundle install
13. Set your MySQL password
Edit config/database.yml
$ nano config/database.yml
and apply the root password from step 8. You'll need to add it in 3 places, your database.yml should look like this when finished:
development:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: blog_development
  pool: 5
  username: root
  password: yourpassword
  socket: /var/lib/mysql/mysql.sock

test:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: blog_test
  pool: 5
  username: root
  password: yourpassword
  socket: /var/lib/mysql/mysql.sock

production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: blog_production
  pool: 5
  username: root
  password: yourpassword
  socket: /var/lib/mysql/mysql.sock
14. Create The Database
$ rake db:create
15. Start WEBrick
$ rails server
Note: WEBrick should really only be used for development & testing. For a production level web server you'll want something like Mongrel.

16. Welcome Aboard!
Browse to http://50.16.195.2:3000/ (using your Elastic Ip). If everything worked you will be greeted with the welcome aboard page.
You should be all set. If you're new to Rails I recommend continuing the Getting Started with Rails tutorial, to keep going with it start at 4.2 Say “Hello”, Rails.