Skip to content

Instantly share code, notes, and snippets.

View dnch's full-sized avatar

Dan Cheail dnch

  • melbourne, au
View GitHub Profile
@dnch
dnch / gist:5241
Created August 13, 2008 15:21 — forked from nfelsen/gist:5197
<% @sections.each do |section| %>
<h2><%= section_name(section) %></h2>
<% section.topics.each do |topic| %>
<%= topic.name %><br>
<% end %>
<% end %>
def donate
@heroPage = HeroPage.search_url(params[:url], DateTime.now)
unless @heroPage
redirect_to :action=>"the_unknown_hero"
return
else
@donation = Donation.new()
# if @donation.save? then session[:mydonation_id] = @donation.id end
def self.determine_if_this_is_an_event_or_hero_page_mode(args)
if args[:event_url]
"event"
elsif args[:url]
"hero_page"
end
end
def self.retrieve_capture_fields(the_page, type_of_capture)
case the_page
when Event then retrieve_capture_data(type_of_capture, the_event_or_hero_page)
when HeroPage then
if the_event_or_hero_page.is_this_hero_page_associated_with_an_event && the_page.event
retrieve_capture_data(type_of_capture, the_page.event)
end
end
end
def v1(value)
value || "-"
end
def v2(object, method)
object && value = object.send(method) ? value : "-"
end
# 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 })
@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?
grey='\e[0;90m'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$grey%}("
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$grey%}) %{$fg[yellow]%}✗%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$grey%})"
function pat_prompt {
(( spare_width = ${COLUMNS} ))
prompt=" "
@dnch
dnch / intro.md
Created October 11, 2010 04:42 — forked from radar/intro.md

Ruby Intro - Setlist

  • no fucking semi-colons (unless you really want them)
  • irb
  • local variable definition
  • +, *, /, - are all methods
  • puts vs print
  • multiplying strings
  • using if & when
  • defining a method
@dnch
dnch / gist:1350453
Created November 9, 2011 05:02 — forked from damncabbage/gist:1350367
Calculating Mass-Assignable ActiveRecord Attributes
class Article < ActiveRecord::Base
# Has attributes: :title, :body, :active
attr_protected :active
end
class Image < ActiveRecord::Base
# Has attributes: :title, :filename, :active
attr_accessible :title