Skip to content

Instantly share code, notes, and snippets.

@tommi-lew
tommi-lew / gist:2952154
Last active October 6, 2015 06:38
Generate RESTful URLs by using Ruby's method missing
class Client
attr_accessor :calls
def get()
api = "http://www.cslew.com/api/"
request = ""
@calls.each do |c|
request += "#{c.keys[0]}/"
request += "#{c.values[0]}/" if c.values[0] != []
@tommi-lew
tommi-lew / gist:2934994
Last active October 6, 2015 04:18
Using Nokogiri to convert hash to XML
require 'nokogiri'
def create_resource(xml)
xml.resource('path' => 'statuses/public_timeline.{format}') {
xml.param('name' => 'format', :'required' => 'true') {
xml.option('value' => 'json', 'mediaType' => 'application/json')
xml.option('value' => 'xml', 'mediaType' => 'application/xml')
}
xml.method_('id' => 'METHOD_ID', 'name' => 'GET', 'apigee:displayName' => 'METHOD_DISPALY_NAME') {
@tommi-lew
tommi-lew / gist:2934347
Created June 15, 2012 02:19
Ruby Magic
#use activesupport's hash to xml without rails
require 'active_support/core_ext/hash/conversions'
@tommi-lew
tommi-lew / heroku-postgres
Created June 12, 2012 09:30
Commands for managing heroku & postgres
#list current backups
heroku pgbackups --app app_name
#do a manual backup immediately
heroku pgbackups:capture --expire --app app_name
#restore postgres with dump (overwrite current state)
pg_restore --clean --no-acl --no-owner -d database_name dump_filename
#download dump and save as file
@tommi-lew
tommi-lew / Generate bar chart
Created June 6, 2012 16:03
Using Google Chart API to generate bar chart
https://chart.googleapis.com/chart?cht=bhs&chs=250x100&chd=t:33,50,17&chxt=y,r&chxl=0:|friends|search%20engine|social%20media|1:|33%|50%|17%&chxs=1,0000dd,13,-1,t
@tommi-lew
tommi-lew / gist:1518571
Created December 25, 2011 00:44 — forked from dhh/gist:1014971
Use concerns to keep your models manageable
# autoload concerns
module YourApp
class Application < Rails::Application
config.autoload_paths += %W(
#{config.root}/app/controllers/concerns
#{config.root}/app/models/concerns
)
end
end
@tommi-lew
tommi-lew / rails31init.md
Created December 25, 2011 00:44 — forked from docwhat/rails31init.md
Rails 3.1 with Rspec, Factory Girl, Haml, Database Cleaner, Spork, and Guard

Install Rails 3.1

gem install rails

generate new app, skipping Test::Unit file generation

rails new my_app -T

Set up Gemfile