Skip to content

Instantly share code, notes, and snippets.

View jxson's full-sized avatar

Jason Campbell jxson

View GitHub Profile
# Drop this file in config/initializers to run your Rails project on Ruby 1.9.
# This is three separate monkey patches -- see comments in code below for the source of each.
# None of them are original to me, I just put them in one file for easily dropping into my Rails projects.
# Also see original sources for pros and cons of each patch. Most notably, the MySQL patch just assumes
# that everything in your database is stored as UTF-8. This was true for me, and there's a good chance it's
# true for you too, in which case this is a quick, practical solution to get you up and running on Ruby 1.9.
#
# Andre Lewis 1/2010
# encoding: utf-8

Old way:

$ git checkout -b preandpost_fork_hooks  scotttam/preandpost_fork_hooks
Branch preandpost_fork_hooks set up to track remote branch preandpost_fork_hooks from scotttam.
Switched to a new branch 'preandpost_fork_hooks'

New way:

$ git checkout preandpost_fork_hooks

Branch preandpost_fork_hooks set up to track remote branch preandpost_fork_hooks from scotttam.

// Usage:
//
// $('#the-select').choose('Some Option');
//
// It'll throw an error if the option doesn't exist.
$.fn.choose = function(name) {
var elem = $(this);
if (elem.is(':not(select)')) { return elem; }
var option = elem.find('option').filter(function() {
require 'rubygems'
require 'grit'
include Grit
repo = Repo.new(".git")
head = repo.head
puts "branch: " + head.name
puts "sha: " + head.commit
var css64Encode = function (string) {
return $.base64Encode(string).
replace(/\//g, '--_').
replace(/\+/g, '-_').
replace(/\=/g, '_');
};
var css64Decode = function (string) {
return $.base64Decode(string.
replace(/--_/g, '/').
#
# RFC822 Email Address Regex
# --------------------------
#
# Originally written by Cal Henderson
# c.f. http://iamcal.com/publish/articles/php/parsing_email/
#
# Translated to Ruby by Tim Fletcher, with changes suggested by Dan Kubb.
#
# Licensed under a Creative Commons Attribution-ShareAlike 2.5 License
# monkey patch for setting headers
# http://bit.ly/aYhlWg
module Capybara
class Session
def set_request_header(name, value)
driver.header(name, value)
end
end
end
@jxson
jxson / Rakefile
Created June 9, 2010 19:21
example arg pasing in rake
desc 'shortcut to do:dev'
task :do => 'do:dev'
namespace :do do
FileList["#{CONFIG_DIR}/*.json"].each do |f|
target = File.basename(f, '.*')
desc "do stuff for #{target}"
task target do
Rake::Task['do:stuff'].invoke(target)
# borrowed from rails actionpack/lib/action_view/helpers/javascript_helper.rb
JS_ESCAPE_MAP = {
'\\' => '\\\\',
'</' => '<\/',
"\r\n" => '\n',
"\n" => '\n',
"\r" => '\n',
'"' => '\\"',
"'" => "\\'" }
@jxson
jxson / application.js
Created September 21, 2010 01:19
Example code for
$(window).load(function(){
if (!Modernizr.input.placeholder){
$('input').supportPlaceHolder();
}
if (!Modernizr.textarea.placeholder){
$('textarea').supportPlaceHolder();
}
});