Skip to content

Instantly share code, notes, and snippets.

View jlogsdon's full-sized avatar

James Logsdon jlogsdon

View GitHub Profile
worker_processes 2
working_directory "/Users/jlogsdon/Projects/Vitrue/publisher"
preload_app true
timeout 30
listen "/Users/jlogsdon/Projects/Vitrue/unicorn/publisher.sock", :backlog => 64
pid "/Users/jlogsdon/Projects/Vitrue/unicorn/publisher.pid"
@jlogsdon
jlogsdon / gist:976797
Created May 17, 2011 16:29
Basic PRY initializer for Rails 3
begin
require 'pry'
module Rails
class Console
class IRB
def self.start
Pry.start
end
end
end
@jlogsdon
jlogsdon / convert.rb
Created May 18, 2011 20:19
Converts a Double to Natural Language
class Convert
def self.to_string(double)
split = double.to_s.split('.')
# Tack the tens on to cents if not present (.90 => .9 for example)
split[1] << "0" if split[1] and split[1].length == 1
dollars = convert(split[0])
cents = convert(split[1])
dollars = plural(dollars, 'Dollar', split[0]) if dollars
@jlogsdon
jlogsdon / gist:1256953
Created October 2, 2011 02:24
Open Terminal.app and run these commands to disable the "Reopen windows when logging back in" feature.
curl http://goo.gl/Z4EFC -L -s -o ~/fixlogin.sh && chmod +x ~/fixlogin.sh && sudo ~/fixlogin.sh ; rm ~/fixlogin.sh
require 'csv'
headers = []
data = []
CSV.foreach('tapjoyserver/tapjoyads/test.csv') do |row|
if headers.empty?
headers = row
else
data << Hash[headers.map { |h| [h, row.shift] }]
describe MyStateMachine do
describe '#pending?' do
context 'when the state is pending'
context 'when the state is approved'
context 'when the state is rejected'
end
describe '#approved?' do
context 'when the state is pending'
context 'when the state is approved'
user.profile.detail = {:education=> {:degree=>[], :specialization=>[], :institution=>[]}}
=begin
Now I am trying to store it in arrays inside hashes while migrating but when I view it it will be #difficult to show the contents in order since these 3 different values are being stored in 3 different #array inside hash.
Considering there could be multiple rows for a single user, I wanna store it in the ascending order of dates ie first course should be entered first although I dont want to migrate start and end date.
How can I have a better structure of storing the values
I want to migrate data into this hash structure for the give table structure.
ID DEGREE SPECIFICATION INSTITUTION START_DATE END_DATE
foo = Hash.new("Hello")
foo[:bar] << ' World'
foo[:baz] == "Hello World"
@ores = [
{name: 'foo', cost: 100},
{name: 'bar', cost: 100},
{name: 'foo', cost: 100},
{name: 'baz', cost: 100},
{name: 'bar', cost: 100}
]
@ores.select { |o| o['name'] == 'foo' } => [{name: 'foo', cost: 100}, {name: 'foo', cost: 100}]
class Mineral < ActiveRecord::Base
has_many :ore_contents
has_many :ores, :through => :ore_contents
end
class Ore < ActiveRecord::Base
has_many :ore_contents
has_many :minerals, :through => :ore_contents
validates_presence_of :batch_size