Skip to content

Instantly share code, notes, and snippets.

View dnch's full-sized avatar

Dan Cheail dnch

  • melbourne, au
View GitHub Profile
def v1(value)
value || "-"
end
def v2(object, method)
object && value = object.send(method) ? value : "-"
end
# assuming the following columns in `things`
#
# children_counter_cache :integer
# parent_id :integer
#
class Thing < ActiveRecord::Base
has_many :children, :class_name => "Thing", :foreign_key => "parent_id", :dependent => :nullify
belongs_to :parent, :class_name => "Thing", :foreign_key => "parent_id", :counter_cache => 'children_counter_cache'
end
namespace :db do
desc "Generates ownership queries"
task :chown => :environment do
ActiveRecord::Base.connection.tables.sort.each do |t|
puts "ALTER TABLE #{t} OWNER TO radius;"
end
end
desc "Migrate database from MySQL to PostgreSQL"
# named_scope :between, lambda {|start_date, end_date, field|
# { :conditions => ["\"#{field}\" >= ? AND \"#{field}\" <= ?", start_date, end_date] }
# }
From the docs...
A range may be used in the hash to use the SQL BETWEEN operator
Student.find(:all, :conditions => { :grade => 9..12 })
// the DOM is wacky
targetTabHeight: function() {
this.targetTab().style.visibility = "hidden";
this.targetTab().style.display = "block";
_height = this.targetTab().offsetHeight;
this.targetTab().style.display = "none";
this.targetTab().style.visibility = "visible";
return _height;
class Report
# ENGINEERING MACHINATIONS
machine(:status, :field_name => "status") do
# we are waiting for someone to upload a file
state :file_pending do
event :upload_file, :to => :file_uploaded
end
# we've got a file, but it's not approved by a hu-man
[Parabox] dan:~$ cat ~/.gemrc
---
:verbose: true
gem: --no-ri --no-rdoc
:benchmark: false
:sources:
- http://gems.github.com
- http://gems.rubyforge.org
:update_sources: true
:backtrace: false
#!/usr/bin/env ruby
require 'rubygems'
require 'zip/zip'
require 'zip/zipfilesystem'
require 'digest/md5'
Dir.glob("/Users/dan/Desktop/SAMPLE_DATA/**/*.zip").each do |f|
begin
puts "hash: " + Digest::MD5.hexdigest(Zip::ZipFile.open(f).read("fx.txt"))
@dnch
dnch / survey
Created November 2, 2009 00:56 — forked from radar/survey.md
What did you do to get good at Rails?
Who taught you what you know?
Do you have any fond (or not so fond) memories of your learning experiences?
What was your first production app and what did you learn from it?
What tools do you use to make your life easier?
What did you find particularly hard to grok when learning Rails?
When did you start on Rails?
Did you learn Ruby first or try to jump straight into Rails?
Did you read any books to get good at Rails?
What system do you use?
=rounded_corners(!radius)
:border-radius = !radius
:-moz-border-radius = !radius
:-webkit-border-radius = !radius