Skip to content

Instantly share code, notes, and snippets.

@leshill
leshill / git-prunelocal
Last active April 15, 2024 13:13
Prune local tracking branches that have been removed upstream. Place file in your path (perhaps `~/bin` or `~/scripts`).
#!/bin/bash
#
# Prune local tracking branches that have been removed upstream.
# Your remote tracking branches can be removed automatically by setting `fetch.prune` to true or running `git fetch -prune`.
# Another command to clean up your remote tracking branches is `git remote prune <remote>`.
#
# Author: @leshill
# https://gist.github.com/leshill/9a1088a17f94cef24831
if [[ $# = 1 && $1 == '-n' ]]; then
@leshill
leshill / git-peruse
Last active August 29, 2015 13:57
Peruse a git branch from a commit to the HEAD in chronological order (oldest to newest). Now with support for navigating across merges.
#!/bin/bash
#
# Peruse a git branch from a commit to the HEAD in chronological order (oldest
# to newest). This uses `git rev-list` to find the child commits; read up on
# the default mode.
#
# v0.2 Added support for folks who merge :)
#
delete_tag() {
@leshill
leshill / jasmine_spec.rb
Created February 18, 2013 22:30
Want to run your Jasmine suite from your RSpec suite? Easy. Add `jasmine_spec.rb` to your `specs/features` and enjoy. We are using https://github.com/bradphelan/jasminerice to run our CoffeeScript suite. You might need to tweak this if you are running Jasmine some other way in your app. Hat tip to Sandro (https://github.com/sandro) who wrote thi…
require 'spec_helper'
describe 'Jasmine suite', :js do
def run_jasmine_tests
visit '/jasmine'
Timeout.timeout(10) do
while page.has_css?('.runningAlert')
sleep 0.25
end
end
@leshill
leshill / some_concern.coffee
Created May 14, 2012 17:49
Mixins in CoffeeScript
class SomeConcern
constructor: (klass) ->
_.extend klass.prototype,
doesAllTheThings: ->
true
rvm gemset use global
curl -OL http://rubyforge.org/frs/download.php/75414/linecache19-0.5.13.gem
curl -OL http://rubyforge.org/frs/download.php/75415/ruby-debug-base19-0.11.26.gem
# Tweak to match your 1.9.3 install (we use falcon)
gem install linecache19-0.5.13.gem ruby-debug-base19-0.11.26.gem -- --with-ruby-include=$rvm_path/src/ruby-1.9.3-p125-falcon/
rm linecache19-0.5.13.gem ruby-debug-base19-0.11.26.gem
module DonorsChoose
extend self
attr_accessor :api_key
def projects_near_me(latitude, longitude)
Request.get(:centerLat => latitude, :centerLong => longitude)
end
def projects_by_zip(zipcode)
Request.get(:keyword => zipcode)
@leshill
leshill / 0-readme.md
Created February 2, 2012 18:46 — forked from burke/0-readme.md
ruby-1.9.3-p0 cumulative performance patch.

Patched ruby 1.9.3-p0 for 30% faster rails boot

What is?

This script installs a patched version of ruby 1.9.3-p0 with patches to make ruby-debug work again (#47) and boot-time performance improvements (#66 and #68), and runtime performance improvements (#83 and #84).

Huge thanks to funny-falcon for the performance patches.

@leshill
leshill / gist:1684107
Created January 26, 2012 18:10 — forked from justinko/gist:1684051
Methods to aid in testing without loading the Rails environment
def stub_model(model_name)
stub_class model_name, ActiveRecord::Base
end
def stub_class(class_name, super_class = Object)
stub_module class_name, Class.new(super_class)
end
def stub_module(module_name, object = Module.new)
module_name = module_name.to_s.camelize
@leshill
leshill / match_method.rb
Created December 30, 2011 07:13 — forked from avdi/match_method.rb
Defining method_missing and respond_to? in one fell swoop
# Do you ever define #method_missing and forget #respond_to? I sure
# do. It would be nice if we could do them both at the same time.
module MatchMethodMacros
def match_method(matcher, &method_body)
mod = Module.new do
define_method(:method_missing) do |method_name, *args|
if matcher === method_name.to_s
instance_exec(method_name, *args, &method_body)
else
def output name=((default=true); "caius")
puts "name: #{name.inspect}"
puts "default: #{default.inspect}"
end
output
# >> name: "caius"
# >> default: true
output "avdi"