Skip to content

Instantly share code, notes, and snippets.

@jonpaul
jonpaul / backbone_sync.js
Created July 24, 2012 19:14
Rewriting backbone.sync for rails CSRF
(function($) {
var methodMap = {
'create': 'POST',
'update': 'PUT',
'delete': 'DELETE',
'read' : 'GET'
};
var getUrl = function(object) {
if (!(object && object.url)) return null;
@zyxar
zyxar / exercise.tour.go
Last active April 28, 2024 17:06
tour.golang exercise solutions
/* Exercise: Loops and Functions #43 */
package main
import (
"fmt"
"math"
)
func Sqrt(x float64) float64 {
z := float64(2.)
@burke
burke / 0-readme.md
Created January 27, 2012 13:44 — forked from funny-falcon/cumulative_performance.patch
ruby-1.9.3-p327 cumulative performance patch for rbenv

ruby-1.9.3-p327 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p327 with various performance improvements and a backported COW-friendly GC, all courtesy of funny-falcon.

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

@jonpaul
jonpaul / rspec-syntax-cheat-sheet.rb
Created January 23, 2012 03:51 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
match_data = /(?<area_code>\d{3})-(?<prefix>\d{3})-(?<line_number>\d{4})/.match("678-248-2440")
if match_data
PhoneNumber.new(
area_code: match_data[:area_code],
prefix: match_data[:prefix],
line_number: match_data[:line_number])
end
def download
@email = User.emails.concat(Organization.emails).compact!
outfile = "members_" + Time.now.strftime("%D") + ".csv"
unless @email.blank?
data = CSV.generate do |csv|
csv << ['Email']
@email.each do |e|
csv << [e]
end
end
@jonpaul
jonpaul / public_controller.rb
Created October 28, 2011 18:25 — forked from bsodmike/public_controller.rb
Render 404 via catch-all route in Rails 3.1
class CmsPageNotFound < StandardError; end
class PublicController < ApplicationController
rescue_from CmsPageNotFound do
render 'not_found', :status => :not_found and return false
end
def index
end
@jonpaul
jonpaul / Capistrano-Deployment-Recipe.rb
Created October 19, 2011 13:22 — forked from mrrooijen/Capistrano-Deployment-Recipe.rb
a "base" Capistrano Rails Deployment Recipe. Use it to deploy your Rails application. It is also easily expandable. So feel free to grab this Recipe and add your own tasks/customization!
# Guide
# Configure the essential configurations below and do the following:
#
# Repository Creation:
# cap deploy:repository:create
# git add .
# git commit -am "initial commit"
# git push origin master
#
# Initial Deployment:
@jonpaul
jonpaul / sanitize_helper.rb
Created August 10, 2011 14:24 — forked from workmad3/sanitize_helper.rb
Sanitize class macro
class ActiveRecord::Base
def self.sanitize_attribute(*attr_names)
attr_names.each do |attr_name|
define_method attr_name do
self[attr_name].try(:html_safe)
end
define_method "#{attr_name}=" do |attr_value|
self[attr_name] = attr_value.try(:sanitize)
end
end
@jonpaul
jonpaul / watchr script
Created June 13, 2011 15:16 — forked from markbates/watchr script
A Watchr script for rails, rspec, and cucumber
ENV["WATCHR"] = "1"
system 'clear'
def growl(message)
growlnotify = `which growlnotify`.chomp
title = "Watchr Test Results"
puts message
image = message.match(/\s0\s(errors|failures)/) ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png"
options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'"
system %(#{growlnotify} #{options} &)