Skip to content

Instantly share code, notes, and snippets.

<a href="//bufferapp.com/add" class="buffer-add-button" data-count="vertical">Buffer</a>
<script type="text/javascript" src="//d389zggrogs7qo.cloudfront.net/js/button.js"></script>
@gma
gma / Gemfile
Created February 4, 2013 15:42 — forked from datenimperator/Gemfile
source 'http://rubygems.org'
gem 'nesta', '~> 0.9.13'
gem 'haml'
gem 'haml-coderay'
gem 'sass'
gem 'compass'
gem 'sprockets-sass'
the 'create action' do
def post_create(params = {})
post :create, invitation: params
end
def valid_params
{ email: 'user@domain.com', first_name: 'First', last_name: 'Last' }
end
it 'should send an email to invite new users' do
@gma
gma / tennis.py
Created December 21, 2012 15:46
Tennis scoring functions, in Python.
import unittest
POINTS = ('0', '15', '30', '40')
def increment_point(player_points, scorer):
if player_points == ['40', '40']:
scorer_points = 'ADV'
else:
@gma
gma / gist:4285182
Created December 14, 2012 12:35
Setting the HTML_X_REQUESTED_WITH header in jQuery, which doesn't seem to be set for me unless I force it. If I don't set this, Rails concludes that I'm not making an xhr request and tries to serve HTML, even though the HTTP_ACCEPT header is clearly set to `application/json, text/javascript, */*`.
$.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)
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)
def redirect_to_app_when_logged_in
if request.path == '/' && request.referer.blank? && current_user
redirect_to iteration_path('current')
end
end
@gma
gma / soc-to-the-max.rb
Created July 17, 2012 09:55 — forked from rlivsey/soc-to-the-max.rb
Separation of concerns sketch
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
@gma
gma / card_creator.rb
Created July 6, 2012 17:29
Exceptions and the observer pattern
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)
@gma
gma / card_creator.rb
Created July 6, 2012 17:00
Moving response callbacks out of controller
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