This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Hacks so that CouchRest::Document, which descends from Hash, | |
# doesn't appear to Rails routing as a Hash of options | |
class Hash | |
def self.===(other) | |
return false if other.is_a?(CouchRest::Document) | |
super | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ActionController::Base.class_eval do | |
protected | |
# BACKPORT OF CHANGE FROM 3.0 EDGE: http://github.com/rails/rails/commit/256b0ee8e3c1610967dfc89f864e24b98ed3c236 | |
# Returns true or false if a request is verified. Checks: | |
# | |
# * is the format restricted? By default, only HTML requests are checked. | |
# * is it a GET request? Gets should be safe and idempotent | |
# * Does the form_authenticity_token match the given token value from the params? | |
def self.verified_request? | |
!protect_against_forgery? || |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Returns a blank 200 OK response for any form posts that include a value for the honeypot field | |
module Rack | |
class Honeypot | |
def initialize(app, field_name) | |
@app = app | |
@field_name = field_name | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20_000 times | |
user system total real | |
Time.parse: 3.810000 0.020000 3.830000 ( 3.870988) | |
Time.parse_gm: 0.420000 0.190000 0.610000 ( 0.596905) | |
Time.parse_mktime: 0.520000 0.180000 0.700000 ( 0.707689) | |
Time.parse_maketime: 0.700000 0.190000 0.890000 ( 0.899610) | |
Time.parse_utc: 0.390000 0.180000 0.570000 ( 0.575244) | |
Time::mktime_with_offset: 0.760000 0.210000 0.970000 ( 0.965841) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
class Article < Hash | |
def initialize(hsh={}) | |
replace(hsh) | |
end | |
def ==(other) | |
if other.is_a?(Date) | |
self[:date] == other |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'active_model' | |
class ActiveCouchModel | |
extend ActiveModel::Callbacks | |
include ActiveModel::Conversion | |
include ActiveModel::Naming | |
include ActiveModel::Validations | |
define_model_callbacks :save, :create | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Rails commands multi-process demo | |
# | |
# For use with https://github.com/rails/commands | |
# | |
# Put this file in an app in script/superconsole (or whatever name) and chmod +x | |
# or just put this in lib/superconsole.rb. | |
# | |
# This script opens the console in the development env, and forks a child process |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Positioned | |
extend ActiveSupport::Concern | |
included do | |
before_save :set_position, unless: :position | |
end | |
module ClassMethods | |
def positioned | |
order(:position, :id) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Helper to set HTTP Basic Auth in functional/controller tests | |
# Put this in test/test_helper.rb: | |
class ActionController::TestCase | |
def login_via_http_basic_auth username, password | |
@request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(username, password) | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Processing Test</title> | |
<script type="text/javascript" src="http://cloud.github.com/downloads/processing-js/processing-js/processing-1.4.1.js"></script> | |
</head> | |
<body> | |
<canvas id="mysketch" data-processing-sources="sketch.pde"></canvas> | |
</body> |
OlderNewer