Skip to content

Instantly share code, notes, and snippets.

View jxson's full-sized avatar

Jason Campbell jxson

View GitHub Profile
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();
}
});
@jxson
jxson / Get RJB to work
Created October 28, 2010 00:26
I was running into issues with the rjb gem on osx snow leopard and had to do this dance
# I was getting this err out of the blue: [BUG] cross-thread violation on rb_gc()
# that's bad news... Here is how I fixed it:
curl -o java.1.5.0-leopard.tar.gz http://ituploads.com/software-downloads/apple/java.1.5.0-leopard.tar.gz
tar -xvzf java.1.5.0-leopard.tar.gz
sudo mv 1.5.0 /System/Library/Frameworks/JavaVM.framework/Versions/1.5.0-leopard
cd /System/Library/Frameworks/JavaVM.framework/Versions/
sudo rm 1.5.0
sudo ln -s 1.5.0-leopard 1.5.0
# adapted from rspec-rails http://github.com/rspec/rspec-rails/blob/master/spec/rspec/rails/mocks/mock_model_spec.rb
shared_examples_for "ActiveModel" do
require 'test/unit/assertions'
require 'active_model/lint'
include Test::Unit::Assertions
include ActiveModel::Lint::Tests
# to_s is to support ruby-1.9
ActiveModel::Lint::Tests.public_instance_methods.map{|m| m.to_s}.grep(/^test/).each do |m|
$ cd ~/clients
$ DISPLAY=:1; bundle exec cucumber features/web-client/test.feature --format progress
Using the default profile...
F.F.F--
(::) failed steps (::)
unable to obtain stable firefox connection in 60 seconds (Selenium::WebDriver::Error::WebDriverError)
./features/web-client/step_definitions/elements.rb:4:in `evaluate_script'
./features/web-client/step_definitions/web.rb:53:in `__instance_exec_609716008'
@jxson
jxson / AppDelegate.m
Created January 21, 2011 00:20
Enable Cookies in your phoneGap app and open http/ https links in safari
- (id) init
{
/**
* Enable cookies
**/
NSHTTPCookieStorage *cookieStorage = [NSHTTPCookieStorage sharedHTTPCookieStorage];
[cookieStorage setCookieAcceptPolicy:NSHTTPCookieAcceptPolicyAlways];
NSHTTPCookie *cookie;
for (cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage]
cookies]) {