Skip to content

Instantly share code, notes, and snippets.

View cmer's full-sized avatar

Carl Mercier cmer

  • Toronto, ON, Canada
View GitHub Profile
@cmer
cmer / application_controller.rb
Created September 13, 2012 19:13 — 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__"
after_filter :inject_csrf_token
private
def inject_csrf_token
if protect_against_forgery? && token = session['_csrf_token']
if body_with_token = response.body.gsub!(TOKEN_PLACEHOLDER, token)
# Set your full path to application.
app_path = "/Users/carl/Dropbox/code/web" # -> changed for development env
# Set unicorn options
worker_processes 20
preload_app true
timeout 180
listen 8080 #"/tmp/.unicorn.sock" -> changed for development env
# Spawn unicorn master worker for user apps (group: apps)
@cmer
cmer / data-benchmark-large-dom.html
Created July 26, 2012 17:33
Benchmarks for data(), attr() and getAttribute() over a large DOM
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<ul></ul>
<p data-foo='abc'></p>
<script>
@cmer
cmer / data-benchmark.html
Created July 26, 2012 16:08
Benchmarks for data(), attr() and getAttribute()
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
</head>
<body>
<ul></ul>
<p data-foo='abc'></p>
<script>
@cmer
cmer / gist:3157850
Created July 22, 2012 01:16
Spam on Quora
Sam John sent you a message on Quora
Sam John said:
"Greetings to you and your family,
my came is Barr. Samora Johnson. I’m personal Attorney to late (Mr Victor .A. Mercier)a nationality of your country, who bear the same surname with yours. died in heart attack after the death of his wifi and only daughter in a car accident, in Benin Republic West Africa on 21st April 2008. (May their gentle souls rest in perfect peace) without anyone to claim his Fund.USD12.5M deposit in the Security bank.
The Bank has issued me an ultimatum to present the next-of-kin of the deceased to inherit the funds to my late client; I have made several enquiries to your embassy here to locate any of my clients extended relatives in his home country,
I decided to contact you hence I know that you bear the same surname with him.
def foo
# do something here
end
# Is it considered bad practice to assign a variable in a conditional statement?
# Ruby gives me a warning: "warning: found = in conditional, should be =="
if x = foo
puts x.to_s
end
@cmer
cmer / _user.json.jbuilder
Created March 27, 2012 23:13
Poor man's caching for Jbuilder
# app/views/users/_user.json.jbuilder
json.(user, :id, :name, :age, :gender)
@cmer
cmer / powssl
Created March 22, 2012 02:52 — forked from paulnicholson/powssl
ssl with pow using stud

Instructions

  • Install stud $ brew install https://raw.github.com/paulnicholson/homebrew/master/Library/Formula/stud.rb
  • Download and install the powssl script $ curl https://raw.github.com/gist/2050941/3ea59efe8c7e9013c265313045a9fdda5c653963/powssl > ~/bin/powssl $ chmod +x ~/bin/powssl
  • Run powssl to create development certificate and configure stud.
  • $ powssl
@cmer
cmer / gist:2008671
Created March 9, 2012 20:59
Avoid console.log crash in IE when developer tools is closed
if(typeof(console) === 'undefined') {
var console = {};
console.log = console.error = console.info = console.debug = console.warn = console.trace = console.dir = console.dirxml = console.group = console.groupEnd = console.time = console.timeEnd = console.assert = console.profile = function() {};
}
@cmer
cmer / cjax.js.coffee
Created March 9, 2012 20:54
CJAX - History.js-PJAX hybrid that doesn't suck in IE
# This is a work in progress. I use it in production and it works very well, but use at your own risk!
@initCJAX = () ->
History = @History
$ = @jQuery
document = @document
return false unless @History.enabled
$ ->
contentSelector = ".main"