Tim Craft timcraft

View original.rb
1 2 3 4 5 6 7 8 9 10
def display_date_or_range(event, sup = true, html = true, short = false)
return if event.start_date.blank? and event.end_date.blank?
if event.single_day?
if short
out = event.start_date.strftime("%b")
else
out = event.start_date.strftime("%B")
end
 
out << " "
View README.md
View README.md

2010 UK General Election Results

D3 flavoured demo of electionmap.

View testcase.rb
1 2 3 4 5 6 7 8 9 10
require 'sequel'
require 'sqlite3'
 
puts "Using SQLite3 #{SQLite3::VERSION}"
 
db = Sequel.connect('sqlite:/')
 
db.create_table!(:things) do
column :email, :varchar, unique: true
end
View gist:4579910
1 2 3 4 5 6 7 8 9
begin
dataset.insert(attributes)
rescue Sequel::DatabaseError => exception
if exception.message =~ /\b((column \w+ is|columns .+ are) not unique|duplicate key value violates unique constraint)\b/
raise SomeOtherException
else
raise exception
end
end
View profile_presenter.rb
1 2 3 4 5 6 7 8 9 10
class ProfilePresenter
def initialize(user, photo_url)
@user, @photo_url = user, photo_url
end
 
def title
@user.full_name
end
 
def member_since
View gist:1286656
1 2 3
def customers
line_items.map { |item| item.order.user_id }
end
View example.rb
1 2 3 4 5 6 7 8 9 10
require 'date'
 
require './presenter'
 
class MonthSelect < Presenter
def initialize(attrs = {})
@attrs = attrs.to_hash
end
 
def html
View example.rb
1 2 3 4 5 6
def format(seconds)
'%d:%02d' % seconds.divmod(60)
end
 
puts format(200)
puts format(121)
Something went wrong with that request. Please try again.