Greetings :)

Hi, I'm Louis!
I like to code, but I don't do enough of it.

This blog is about trying my best to keep up with the ever evolving stream of technology.

Saturday, March 10, 2012

Setting up postgres on ubuntu, and getting it going on heroku

links: https://help.ubuntu.com/community/PostgreSQL,

sudo apt-get install postgresql
sudo apt-get install postgresql-server-dev-all

#Create a user account for postgresql, and a database with the name of your user account
sudo -u postgres createuser --superuser myUbuntuUsername
sudo -u postgres psql
postgres=# \password myUbuntuUsername
\q
createdb myUbuntuUsername

#Check that your postgres useraccount was setup properly
psql
\du 

Use require
'dm-core'
instead of
require 'datamapper'
http://devcenter.heroku.com/articles/database

Keep test and production gems separate:
http://yehudakatz.com/2010/05/09/the-how-and-why-of-bundler-groups/

Working with rails

gem install rails
sudo apt-get install libmysql-ruby libmysqlclient-dev

rails new myProject -d mysql

Saturday, November 19, 2011

Helpful sinatra info

https://github.com/toolmantim/sinatra-content-for -- allow you to pass in say the title from a page to the layout.

Sunday, October 16, 2011

Helpful ruby commands

Remove all gems
* gem list | cut -d" " -f1 | xargs gem uninstall -aIx
* (From RVM) rvm do gem list | cut -d" " -f1 | xargs rvm do gem uninstall -aIx

Remove RVM
1.rvm implode

2.gem uninstall rvm

Saturday, September 24, 2011

Adding local 'DNS' entries to your mac

I'm currently working on adding subdomains to my sinatra app - following the instructions at:
http://tannerburson.com/2009/01/extracting-subdomains-in-sinatra.html

First we need to add a local domain name to our hosts file:
http://decoding.wordpress.com/2009/04/06/how-to-edit-the-hosts-file-in-mac-os-x-leopard/

  • sudo vi /private/etc/hosts
  • Run dscacheutil flushcache


Once this is done, wildcard subdomains will need to be supported. I'm using Heroku, and thus I'll follow the instructions at http://devcenter.heroku.com/articles/custom-domains

Heroku notes

Create a new heroku instance

gem install heroku
heroku create
git push heroku master

>> 'successfully deployed' then you go to the site and ... error...

heroku logs

>> figure out the error (e.g. missing gem.. update Gemfile) then try again...

now that we've got something running, can add a domain...

(taken from http://devcenter.heroku.com/articles/custom-domains)
heroku addons:add custom_domains
heroku domains:add www.example.com
heroku domains:add example.com

And now setup domains on your domain provider (I'm using godaddy)

75.101.163.44
75.101.145.87
174.129.212.2
In GoDaddy find your domain name, click on it, and then click the 'DNS Manager' on the page that shows all the information about your domain. Click on the 'Quick Add' on the Hosts(A) section, and just add the @ ip address - have to do three entries. The www will reference to @, so don't need to worry about that one :)


Getting the mongo connection string:

heroku config --long


You'll get some output that includes a line where your mongo connection is:

MONGOHQ_URL         => mongodb://heroku:myPassword@myHost:10013/appname545


You can then take this string, and use it to connect to mongo:

mongo -u heroku -p myPassword --host myHost -port 10013 appname545










We may already have an app and we're on a different machine than the original

  • Install toolbelt - https://toolbelt.herokuapp.com/linux
  • heroku login
  • heroku keys:add [path to keyfile]
  • git remote add heroku git@heroku.com:myAppOnHeroku.git

Friday, August 5, 2011

Deleting objects with ruby on Amazon S3

Problem:
I ended up with loads of objects in my bucket after configuring some logging in Amazon S3. Deleting these manually is not the best use of time (click click click... one has been deleted) * 1 million (slightly over-exaggerated)

Solution:
Use Ruby to do it!

Solution Problem:
I was trying to use the 'aws/s3' gem, and apparently there's some problems with european regions or something... anyway, I tried some sample code found in http://stackoverflow.com/questions/27267/delete-amazon-s3-buckets, and then I found - http://thewebfellas.com/blog/2009/8/29/protecting-your-paperclip-downloads which led me to my eventual solution...

Solution Problem Solution:
Use a different gem - the 's3' gem.

Here's what I ended up with:

require 's3'

service = S3::service.new(:access_key_id => your key from amazon account page, 
                          :secret_access_key => your secret key from amazon account page)

my_bucket = service.buckets.find("my-unique-bucket-name")
my_bucket.objects.each {|object| object.destroy}

Pretty simple in the end huh :)

Check that it worked by doing my_bucket.objects.size before and after you delete the objects.