Skip to content

Instantly share code, notes, and snippets.

View bgarret's full-sized avatar

Benoit Garret bgarret

View GitHub Profile
@bgarret
bgarret / application_controller.rb
Created February 21, 2012 08:31 — forked from jamesbebbington/application_controller.rb
Rack middleware and form tag patch to insert csrf tokens into cached pages
class ApplicationController < ActionController::Base
TOKEN_PLACEHOLDER = "__CROSS_SITE_REQUEST_FORGERY_PROTECTION_TOKEN__"
before_filter :form_authenticity_token
after_filter :inject_csrf_token
private
def inject_csrf_token
if protect_against_forgery? && token = session['_csrf_token']
@bgarret
bgarret / nap.sh
Created January 13, 2012 14:24
Napping script
#!/bin/bash
# Napping script
#
# Plays waves sound for $duration, followed by beeps
#
# Usage:
# ./nap.sh 15:00 => 15 minutes nap
set -u
@bgarret
bgarret / .rvmrc
Created May 27, 2011 12:38
.rvmrc for automatic gemset creation
#!/usr/bin/env bash
ruby_string="1.9.2"
gemset_name="tiffandmo"
if rvm list strings | grep -q "${ruby_string}" ; then
# Load or create the specified environment
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
&& -s "${rvm_path:-$HOME/.rvm}/environments/${ruby_string}@${gemset_name}" ]] ; then
@bgarret
bgarret / widget.rb
Created May 20, 2011 15:47
Redefine responds_to_event to allow preventing event bubbling
class Widget < Apotomo::Widget
# ...
def self.responds_to_event(*options)
bubble? = options.last.delete[:bubble] || false
unless bubble?
# Get the method name
method_name = options.last[:with] || options.first