Skip to content

Instantly share code, notes, and snippets.

module ActionController
module RequestForgeryProtection
def verify_authenticity_token
verified_request? || handle_unverified_request
end
def handle_unverified_request
reset_session
end
@dsueiro
dsueiro / databases.rake
Created May 23, 2011 20:46 — forked from lukemelia/databases.rake
Our replacement for schema.rb dump/load
namespace :db do
namespace :structure do
desc "Dump the database structure to a SQL file"
task :dump => :load_config do
config = ActiveRecord::Base.configurations[Rails.env]
command = "mysqldump -u #{config["username"]} #{config["database"]} --no-data --skip-comments --skip-add-drop-table > db/#{Rails.env}_structure.sql"
puts "Running: #{command}"
system command
@dsueiro
dsueiro / gist:1024682
Created June 14, 2011 10:59 — forked from mkdynamic/gist:198559
Paperclip, S3 & Delayed Job
#
# Add a :processing flag to our model
#
class AddProcessingToImages < ActiveRecord::Migration
def self.up
add_column :images, :processing, :boolean
end
def self.down
@dsueiro
dsueiro / pubsub.md
Created November 5, 2011 21:20 — forked from addyosmani/pubsub.md
Four ways to do Pub/Sub with jQuery 1.7 and jQuery UI (in the future)

#Four Ways To Do Pub/Sub With jQuery 1.7 and jQuery UI (in the future)

Between jQuery 1.7 and some of work going into future versions of jQuery UI, there are a ton of hot new ways for you to get your publish/subscribe on. Here are just four of them, three of which are new.

(PS: If you're unfamiliar with pub/sub, read the guide to it that Julian Aubourg and I wrote here http://msdn.microsoft.com/en-us/scriptjunkie/hh201955.aspx)

##Option 1: Using jQuery 1.7's $.Callbacks() feature:

$.Callbacks are a multi-purpose callbacks list object which can be used as a base layer to build new functionality including simple publish/subscribe systems. We haven't yet released the API documentation for this feature just yet, but for more information on it (including lots of examples), see my post on $.Callbacks() here:

@dsueiro
dsueiro / gemspec-usage.md
Created February 13, 2012 03:25 — forked from holman/gemspec-usage.md
test/spec/mini

Just install this in your apps like so:

gem 'test-spec-mini', :git => 'git://gist.github.com/1806986.git', :require => 'mini'

@dsueiro
dsueiro / my.cnf
Created April 1, 2012 11:53 — forked from sowawa/my.cnf
mysql config for rackhub
# Example MySQL config file for small systems.
#
# This is for a system with little memory (<= 64M) where MySQL is only used
# from time to time and it's important that the mysqld daemon
# doesn't use much resources.
#
# MySQL programs look for option files in a set of
# locations which depend on the deployment platform.
# You can copy this option file to one of those
# locations. For information about these locations, see:
@dsueiro
dsueiro / tree.md
Created April 30, 2012 00:48 — forked from hrldcpr/tree.md
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@dsueiro
dsueiro / README.md
Created July 5, 2012 02:25 — forked from mbostock/.block
Stacked Radial Area

This plot might be suitable for showing cyclical trends, though I'm not sure it’s a great idea as the radial display has a number of limitations:

  • The underlying data goes from Sunday to Saturday, but the chart shows continuity from Saturday through to the previous Sunday. Time does not flow backwards, so you might instead prefer to plot two values for Sunday; this would show a discontinuity on opposite sides of the Sunday axis.

  • Displaying the discontinuity requires an open interpolator, rather than cardinal-closed as used here. However, this causes the tangents of the incoming and outgoing lines to no longer be orthogonal to the axis. To display the discontinuity properly, you’d need to write a custom interpolator to generate the correct tangents.

  • Due to the interpolation taking place in Cartesian (rather than polar) coordinates, the intermediate values of the lines do not have the correct radial values: if you tried to measure t

@dsueiro
dsueiro / cfb2.rb
Created July 14, 2012 13:57 — forked from jimweirich/cfb2.rb
Inspired by "Programming with Nothing" http://experthuman.com/programming-with-nothing. See comment below for some details.
require './interface'
puts to_strings(->(limit) {
->(lst) {
->(f) {
->(f) {
->(g) {
->(n) {
f.(g.(g)).(n)
}
}.(->(g) {
@dsueiro
dsueiro / dnsd.rb
Created July 28, 2012 05:20 — forked from peterc/dnsd.rb
Simple, scrappy UDP DNS server in Ruby (with protocol annotations)
# Simple, scrappy UDP DNS server in Ruby (with protocol annotations)
# By Peter Cooper
#
# MIT license
#
# * Not advised to use in your production environment! ;-)
# * Requires Ruby 1.9
# * Supports A and CNAME records
# * See http://www.ietf.org/rfc/rfc1035.txt for protocol guidance
# * All records get the same TTL