Skip to content

Instantly share code, notes, and snippets.

View sj26's full-sized avatar
🤹‍♂️

Samuel Cochran sj26

🤹‍♂️
View GitHub Profile
@sj26
sj26 / Gemfile
Created June 8, 2011 05:59
Compass support in Rails 3.1
gem 'sass-rails', :git => 'https://github.com/rails/sass-rails.git'
gem 'compass', :git => 'https://github.com/chriseppstein/compass.git', :branch => 'rails31'
@sj26
sj26 / jquery.touch.js
Created June 16, 2011 02:43
Zepto touch for jQuery
(function($){
var touch = {}, touchTimeout;
function parentIfText(node){
return 'tagName' in node ? node : node.parentNode;
}
function swipeDirection(x1, x2, y1, y2){
var xDelta = Math.abs(x1 - x2), yDelta = Math.abs(y1 - y2);
if (xDelta >= yDelta) {
@sj26
sj26 / gist:1046117
Created June 25, 2011 03:48
String dedent/redent
class String
def dedent
indent = lines.reject(&:empty?).map { |line| line.index(/\S/) }.compact.min
gsub /^ {1,#{indent.to_i}}/, ''
end unless method_defined? :dedent
def redent prefix
prefix = " " * prefix if prefix.is_a? Numeric
dedent.gsub! /^(?=[ \t]*\S+)/, prefix
end unless method_defined? :redent
@sj26
sj26 / _gem
Created August 31, 2011 04:59 — forked from alexvollmer/_gem
zsh completion for rubygems
#compdef gem gem1.9
gem_general_flags=("(-h --help)"{-h,--help}"[Get help on this command]"
"(-V --verbose)"{-V,--verbose}"[Set the verbose level of output]"
"(-q --quiet)"{-q,--quiet}"[Silence commands]"
"--config-file[Use this config file instead of default]:file:_files"
"--backtrace[Show stack backtrace on errors]"
"--debug[Turn on Ruby debugging]"
$nul_arg
)
@sj26
sj26 / 1.9.2-p290-loadpatch
Created September 9, 2011 05:59
ruby-build definition for ruby 1.9.2 p290 with load.c patch
# Save this somewhere, then run `ruby-build path/to/1.9.2-p290-loadpatch`
build_package_apply_loadpatch() {
{ curl "https://raw.github.com/gist/1008945/4edd1e1dcc1f0db52d4816843a9d1e6b60661122/ruby-1.9.2p290.patch" | patch
} >&4 2>&1
}
install_package "yaml-0.1.4" "http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz"
install_package "ruby-1.9.2-p290" "http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p290.tar.gz" apply_loadpatch standard
install_package "rubygems-1.8.10" "http://production.cf.rubygems.org/rubygems/rubygems-1.8.10.tgz" ruby
@sj26
sj26 / ONP.py
Created September 21, 2011 04:46
Some SPOJ attempts in Python
import sys
from string import ascii_letters as letters
ops = ('+', '-', '*', '/', '^')
cases = int(sys.stdin.readline().strip())
for line in sys.stdin:
stack = [[]]
for c in line.strip():
if c == '(':
stack.append([])
elif c == ')':
def psuedorandoms seed
Enumerator.new do |yielder|
loop do
seed = Digest::MD5.digest(seed)
seed.unpack("Q*").each do |number|
yielder.yield number.to_f / 2**64
end
end
end
end
@sj26
sj26 / assign.rb
Created November 23, 2011 06:27
Rspec rails assign matcher
module RSpec::Rails::Matchers::Assign
private
# +nodoc+
class AssignMatcher
attr_accessor :actual, :operator, :expected
def initialize scope, name, expected=nil
@scope = scope
@name = name
FactoryGirl.define do
factory :business
factory :client do
business
first "Homer"
end
factory :appointment do
client
# Adds SASS rendering support to Rails actionview (from controllers)
module Sass::Rails::Views
class Railtie < ::Rails::Railtie
initializer "sass-rails-views" do
# Tell ActionView we can handle SASS templates
ActionView::Template.register_template_handler :sass, Sass::Rails::Views::Template
end
# Create a SASS file as a rails template
class Template