View tennis.py
1 2 3 4 5 6 7 8 9 10
import unittest
 
 
POINTS = ('0', '15', '30', '40')
 
 
def increment_point(player_points, scorer):
if player_points == ['40', '40']:
scorer_points = 'ADV'
else:
View gist:4285182
1 2 3 4 5 6 7 8 9
$.ajax @api_url,
dataType: 'json'
beforeSend: (jqXHR, settings) ->
jqXHR.setRequestHeader('X-Requested-With', 'XMLHttpRequest')
success: (data, textStatus, jqXHR) =>
@onDataLoaded(data, textStatus, jqXHR)
callback?()
error: (jqXHR, textStatus, errorThrown) =>
@onLoadFailed(jqXHR, textStatus, errorThrown)
View capybara_assertions.rb
1 2 3 4 5 6 7 8 9 10
module CapybaraAssertions
def css_assertion_builder(outcome, selector, text, message)
if text
options = { :text => text }
message ||= "#{outcome} have found '#{selector}' containing '#{text}'"
else
options = {}
message ||= "#{outcome} have found '#{selector}'"
end
is_present = page.has_css?(selector, options)
View gist:3634662
1 2 3 4 5
def redirect_to_app_when_logged_in
if request.path == '/' && request.referer.blank? && current_user
redirect_to iteration_path('current')
end
end
View soc-to-the-max.rb
1 2 3 4 5 6 7 8 9
class TasksController < ApplicationController
def complete
# add responder as listener, or could subscribe etc...
# task could be the actual task, or pass through the ID
task.add_subscriber(TaskCompletedResponse.new(self))
task.add_subscriber(TaskEmail.new)
task.add_subscriber(TaskIndex)
task.complete_by(person)
end
View card_creator.rb
1 2 3 4 5 6 7 8 9 10
class CardCreator
include Publisher
def create(iteration, attributes)
card = iteration.cards.build(attributes)
card.save!
rescue ActiveRecord::RecordInvalid
notify_subscribers(:create_failed, card)
else
notify_subscribers(:created, card)
View card_creator.rb
1 2 3 4 5 6 7 8 9 10
class CardCreator < Struct.new(:listener)
def create(iteration, attributes)
card = iteration.cards.build(attributes)
if card.save
listener.created(card)
else
listener.create_failed(card)
end
end
end
View card_creator.rb
1 2 3 4 5 6 7 8 9 10
class CardCreator < Struct.new(:listener)
class Failed < RuntimeError
attr_accessor :model
def initialize(model)
@model = model
end
end
def self.create(iteration, attributes)
View gist:1876872
1 2 3 4 5 6 7 8 9
# The best approach depends on how you define a blog entry. If you think
# of a blog article the same way I do, that means "all pages with a date".
#
# In Ruby you can re-open a class and redefine its methods. Normally, this
# would be a horrific thing to do (as others could be very confused by
# your code) but in the context of a typical Nesta site I don't think it's
# particularly bad news, and its very convenient.
#
# So, in app.rb, add this (which is very similar to the default):
View gist:1876095
1 2 3 4 5 6 7
11:53:07 web.1 | /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/sass-3.1.15/lib/sass/plugin/compiler.rb:29:in `<class:Compiler>'
11:53:07 web.1 | /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/sass-3.1.15/lib/sass/plugin/compiler.rb:28:in `<module:Plugin>'
11:53:07 web.1 | /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/sass-3.1.15/lib/sass/plugin/compiler.rb:9:in `<top (required)>'
11:53:07 web.1 | /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/sass-3.1.15/lib/sass/plugin.rb:4:in `<top (required)>'
11:53:07 web.1 | /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/haml-3.1.4/lib/sass/rails3_shim.rb:15:in `block in <top (required)>'
11:53:07 web.1 | /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
11:53:07 web.1 | /Users/graham/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/activesupport-3.2.
Something went wrong with that request. Please try again.