Skip to content

Instantly share code, notes, and snippets.

class Node < ActiveRecord::Base
validates :name, :presence => true
end
class Team < Node
delegate :name, :to => :profile
after_initialize do |team|
team.build_profile(:name => team[:name]) if team.new_record? && team.profile.nil?
end
(rdb:1) date
2010-09-26 05:02:10 UTC
(rdb:1) date.class
Time
(rdb:1) @league.rounds.current.start_date.utc
2010-09-26 05:02:10 UTC
(rdb:1) @league.rounds.current.start_date.utc.class
Time
(rdb:1) @league.rounds.current.start_date.utc == date
false
ruby-1.9.2-p180 :007 > Team.all.count
Team Load (1.6ms) SELECT `nodes`.* FROM `nodes` WHERE `nodes`.`type` = 'Team' ORDER BY nodes.name DESC
=> 13
ruby-1.9.2-p180 :008 > Zone.all.count
Zone Load (2.2ms) SELECT `nodes`.* FROM `nodes` WHERE `nodes`.`type` = 'Zone' ORDER BY nodes.name DESC
League Load (0.5ms) SELECT `nodes`.* FROM `nodes` WHERE `nodes`.`type` = 'League' AND `nodes`.`id` = 1 ORDER BY nodes.name DESC LIMIT 1
Round Load (0.5ms) SELECT `rounds`.* FROM `rounds` WHERE (`rounds`.league_id = 1) ORDER BY rounds.starts_at DESC
SQL (0.4ms) SELECT COUNT(*) FROM `zone_configurations` WHERE (`zone_configurations`.zone_id = 5)
League Load (0.4ms) SELECT `nodes`.* FROM `nodes` WHERE `nodes`.`type` = 'League' AND `nodes`.`id` = 1 ORDER BY nodes.name DESC LIMIT 1
Round Load (0.4ms) SELECT `rounds`.* FROM `rounds` WHERE (`rounds`.league_id = 1) ORDER BY rounds.starts_at DESC
@tjmcewan
tjmcewan / custom.rake
Created June 25, 2011 05:36
password resetter
namespace :db do
desc 'Reset all User passwords to "letmein"'
task :password_reset => :environment do
count = 0
User.all.each do |u|
u.password = u.password_confirmation = 'letmein'
if u.save
count += 1
print '.'
else
@tjmcewan
tjmcewan / job-app.mdown
Created June 16, 2011 06:15
[JOB] junior/mid dev onsite at ISF, UTS (SYD)

Web Application Developer

Institute of Sustainable Futures @ University of Technology, Sydney

Want to work where you can really make a difference? A position at UTS is one of influence, recognition, reward and work-life balance.

The Institute for Sustainable Futures (ISF) at UTS is a leader in applied sustainability research. Over the last 13 years ISF has worked with numerous government, industry and community organisations, in Australia and

class JobDescription
def self.important_bits
chaff do
"""
## Position
You'll have an initial six to nine month negotiated contract, with a view to making you a permanent employee once we establish we're right for each other. You'll be enhancing & maintaining a range of existing projects, including our internal custom built Project Management System (PIMMS), our energy efficiency game website: [Climate Clubs](http://ccv2.heroku.com/), and our waste management tool for SMEs: [WasteNot](http://wastenot.streamline.org.au/) (built for us by :mocra). You'll also help us quickly knock up proof of concept sites (and nurture them into blossoming gardens; cheers @cmaitchison ;-) for the many community education & engagement ideas we have in the icebox.
## We use
Ubuntu/Passenger/Nginx, Heroku, JenkinsCI, Rails, Git, BackboneJS (jQuery), Rspec (Cucumber), whatever you want (except Haskell) :-p
ruby-1.8.7-p334 :001 > task = Task.create(:name => "test")
=> #<Task id: 4364, name: "test", created_at: "2011-06-07 10:38:24", updated_at: "2011-06-07 10:38:24">
ruby-1.8.7-p334 :003 > task.destroy
=> #<Task id: 4364, name: "test", created_at: "2011-06-07 10:38:24", updated_at: "2011-06-07 10:38:47">
ruby-1.8.7-p334 :004 > task
=> #<Task id: 4364, name: "test", created_at: "2011-06-07 10:38:24", updated_at: "2011-06-07 10:38:47">
ruby-1.8.7-p334 :005 > task.present?
=> true
ruby-1.8.7-p334 :007 > task.reload
ActiveRecord::RecordNotFound: Couldn't find Task with ID=4364
@tjmcewan
tjmcewan / .bash_profile
Created May 20, 2011 02:52
Rails version-agnostic server & console
# Rails 2 and Rails 3 console
function rc {
if [ -e "./script/console" ]; then
./script/console $@
else
rails console $@
fi
}
# Rails 2 and Rails 3 server
def select_animal(num)
animal = case num
when (1 or 2) then :monkey # 2 & 4 never get reached
when (3 || 4) then :giraffe
end
return animal
end
(1..4).each do |n|
puts select_animal(n)
# !/usr/bin/env ruby
#
# A pre-commit hook to test if jammit needs to be run
# In case you don't like on the fly stuff
require 'rubygems'
require "bundler"
Bundler.setup
require 'jammit'