Skip to content

Instantly share code, notes, and snippets.

@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

@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 / 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 / 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 / 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 / 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: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:2958404
Created June 20, 2012 06:14
Ruby SOAP Client
#Part of a school project using SAP ERP.
#Created a composite application using a Linux EC2 Instance & created SOAP web services.
#Used Ruby to invoke enterprises services in SAP.
require 'rubygems'
require 'savon'
client = Savon::Client.new do
wsdl.document = File.read("wsdl_document.wsdl")
http.auth.basic "username", "password"
@tommi-lew
tommi-lew / gist:2960141
Created June 20, 2012 14:22
Code snippets on using PIL for overlaying text over image
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
from StringIO import StringIO
font = ImageFont.load_default()
input = StringIO(self.request.get("img"))
img = Image.open(input)
draw = ImageDraw.Draw(img)
@tommi-lew
tommi-lew / log4j.properties
Created June 24, 2012 02:02
Java log4j.properties
log4j.rootLogger=debug, stdout, file
### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
### file appender
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.maxFileSize=100KB