Skip to content

Instantly share code, notes, and snippets.

-- Opens up terminal tabs and runs commands in them.
-- Modify switch_dir and/or tab_commands to taste.
-- If you switch away from Terminal.app in the middle
-- of the script running, you'll (probably) get an error.
-- Based on this script by Matthew Lambie:
-- http://lambie.org/2007/11/03/tabs-in-terminal-using-applescript-on-leopard/
-- Modified by James MacAulay 2009-2010
#!/usr/bin/env ruby
# call with filenames as arguments
# outputs lines which appear in all files
# (stripping leading and trailing whitespace, in no predictable order)
# $ cat > foo
# apple
# orange
# pear
# git-freeze: take the current index and working tree state and "freeze" them
# by creating a commit for each as necessary
#
# git-thaw: look for commits created by git-freeze and restore them to
# working tree or index as appropriate
# alias gf='git-freeze'
# alias gt='git-thaw'
function git-freeze () {
@jamesmacaulay
jamesmacaulay / rietveld.upload.py.open_url.diff
Created January 27, 2011 16:34
rietveld code review upload.py patch to open issue in browser after upload
--- codereview
+++ (clipboard)
@@ -1665,6 +1665,12 @@
vcs.UploadBaseFiles(issue, rpc_server, patches, patchset, options, files)
if options.send_mail:
rpc_server.Send("/" + issue + "/mail", payload="")
+
+ if response_body.startswith("Issue created.") or\
+ response_body.startswith("Issue updated."):
+ url = msg[msg.rfind("http"):]
@jamesmacaulay
jamesmacaulay / gist:860763
Created March 8, 2011 18:53
zsh hooks to growl completion of long-running commands
# long-running command growler
# hooks for zsh, built on bash version at http://hints.macworld.com/article.php?story=20071009124425468
preexec_functions+='save_preexec_time'
save_preexec_time() {
export PREEXEC_CMD="$(history $HISTCMD | sed 's/ *[0-9]* *//')"
export PREEXEC_TIME=$(date +'%s')
}
precmd_functions+='growl_about_long_running_commands'
@jamesmacaulay
jamesmacaulay / gist:861291
Created March 8, 2011 22:58
get the fixture label of a given record
# fixture_label_of_record(shops(:snowdevil))
# => "snowdevil"
class ActiveSupport::TestCase
def fixture_label_of_record(record)
yaml_file = fixture_path + record.class.table_name + '.yml'
labels = YAML.load(File.read(yaml_file)).keys
labels.find {|l| Fixtures.identify(l) == record[record.class.primary_key]}
end
end
class Batman.Cons extends Batman.Object
@accessor (key) ->
return unless key.match(/^c[ad][ad]+r$/)
@get("c#{key[1]}r.c#{key[2..key.length-2]}r")
@accessor 'car', -> @car
@accessor 'cdr', -> @cdr
constructor: (@car, @cdr) ->
class Batman.Stream extends Batman.Cons
@accessor 'cdr', -> @cdrFunction()
@jamesmacaulay
jamesmacaulay / routes.rb
Created December 2, 2011 17:13
Batman pushState routes
class JSONMatcher
def matches?(request)
request.format && request.format.json?
end
end
BatmanPaginator::Application.routes.draw do
resources :children
resources :components
(ns jasmine.core)
(def expect (.-expect js/window))
(.beforeEach js/window (fn []
(this-as spec
(.addMatchers spec (js-obj
"to_be" #(this-as expectation
(= % (.-actual expectation))))))))
@jamesmacaulay
jamesmacaulay / iffn.clj
Created February 20, 2013 05:09
Like `if`, but operates on the level of functions.
(defmacro iffn
"Like `if`, but operates on the level of functions. Returns a function which applies its arguments to `test-fn`.
If the return value of `test-fn` is truthy, `then-fn` is called with the same arguments to get the return value.
Otherwise, `else-fn` is used. In other words, it lets you rewrite this:
#(if (pos? %) (inc %) (dec %))
as this:
(iffn pos? inc dec)"