Skip to content

Instantly share code, notes, and snippets.

View jxson's full-sized avatar

Jason Campbell jxson

View GitHub Profile
@jxson
jxson / 0_reuse_code.js
Created June 6, 2014 00:07
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jxson
jxson / gist:227501
Created November 5, 2009 23:18 — forked from atmos/gist:227332
Spec for enforcing whitespace
require File.dirname(__FILE__) + '/spec_helper'
describe "The library itself" do
Spec::Matchers.define :have_no_tab_characters do
match do |filename|
@failing_lines = []
File.readlines(filename).each_with_index do |line,number|
@failing_lines << number + 1 if line =~ /\t/
end
@failing_lines.empty?
# 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() {
# 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|
/* iphone... */
@media screen and (max-device-width: 480px) {
}
/* ...iphone */
/* iphone portrait... */
@media screen and (max-device-width: 480px) and (orientation:portrait) {
}
/* ...iphone portrait */
# Add this to more_web_steps.rb
# Selenium docs: http://code.google.com/p/selenium/wiki/RubyBindings#Javascript_Alert/Confirm today!
When /^I (accept|dismiss) the "([^"]*)" alert$/ do |action, text|
alert = page.driver.browser.switch_to.alert
alert.text.should eq(text)
alert.send(action)
end
@jxson
jxson / bitly-node.md
Created May 9, 2011 20:38 — forked from joemccann/bitly-node.md
Bitly shortening from the command line with node, motherfuckers.
@jxson
jxson / forceScrollbars.coffee
Created September 13, 2011 23:40 — forked from madrobby/forceScrollbars.coffee
Get Safari (Lion) to hopefully always indicate & show scrollbars correctly
# CoffeeScript source
$.fn.forceScrollbars = ->
@css position: 'static'
@[0].offsetHeight if @length > 0
@css position: 'relative'