Skip to content

Instantly share code, notes, and snippets.

@gma
gma / gist:5100428
Last active December 14, 2015 14:28
Do not want this behaviour. Mmmkay? It's bad. Got it? Good…
(rdb:1) p cache_control
{"max-age"=>"0", "private"=>true, "must-revalidate"=>true}
# It's a hash? That's weird...
(rdb:1) p cache_control.class
Rack::Cache::CacheControl
# Oh you dirty liar. Let's check.
(rdb:1) p cache_control.class.ancestors
[Rack::Cache::CacheControl, Hash, Mocha::HashMethods, JSON::Ext::Generator::GeneratorMethods::Hash, Enumerable, Object, Metaclass::ObjectMethods, Mocha::ObjectMethods, PP::ObjectMixin, ActiveSupport::Dependencies::Loadable, JSON::Ext::Generator::GeneratorMethods::Object, Kernel, BasicObject]
@gma
gma / master.sass
Created March 6, 2013 15:01
Styles used on effectif.com.
@import "mixins.sass"
@import "normalize"
body
font: $size1 Bitter, serif
line-height: 1.6
color: $base-color
div#container
position: relative
<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: '[email protected]', 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