Skip to content

Instantly share code, notes, and snippets.

View davidrupp's full-sized avatar

David Rupp davidrupp

View GitHub Profile
@davidrupp
davidrupp / gist:8ba1df41f479b60fa566
Last active August 29, 2015 14:19
alter-var-root-constantly-1
(def thing 1) ; value of thing is now 1
; do some stuff with thing
(alter-var-root #'thing (constantly nil)) ; value of thing is now nil
@davidrupp
davidrupp / gist:33211aab85984ea198a4
Created April 23, 2015 15:09
alter-var-root-constantly-2
(def thing 1)
; do some stuff with thing
(def thing nil)
; value of thing is now nil
@davidrupp
davidrupp / gist:8ecce770be8cadc77f70
Last active August 29, 2015 14:19
alter-var-root-constantly-3
(def thing 1)
; general form is
; (alter-var-root var-to-be-altered
; function-to-apply-to-old-value)
(alter-var-root #'thing inc) ; value of thing is now 2
; equivalently ...
(alter-var-root #'thing (fn [old-val] (inc old-val))) ; value of thing is now 3
; also equivalently ...
(alter-var-root #'thing #(inc %1)) ; value of thing is now 4
@davidrupp
davidrupp / gist:1ae6fa19a9ea5bae7b50
Last active August 29, 2015 14:19
alter-var-root-constantly-4
(def thing 1)
(alter-var-root #'thing (fn [old-val] nil)) ; value of thing is now nil
; we don't really need to name the argument, because we don't use it
; but we *do* need to include it; otherwise we'll get an arity exception
(alter-var-root #'thing (fn [_] nil)) ; value of thing is now nil
; equivalently (kind of) ...
(alter-var-root #'thing (constantly nil))
@davidrupp
davidrupp / gist:903201c1144331d0b16b
Created April 23, 2015 16:07
alter-var-root-constantly-5
(#(identity %3) 1 2)
;=> ArityException Wrong number of args (2) passed to: user/eval3407/fn--3408 ...
@davidrupp
davidrupp / gist:78dd79fb608b9130c6d4
Created April 23, 2015 16:14
alter-var-root-constantly-6
(def thing 1)
; these all happen to work, but ... yuck
(alter-var-root #'thing #(if %1 nil))
(alter-var-root #'thing #(last [%1 nil]))
(alter-var-root #'thing #(do %1 nil))
@davidrupp
davidrupp / keybase.md
Created June 2, 2015 19:24
keybase.md

Keybase proof

I hereby claim:

  • I am davidrupp on github.
  • I am davidrupp (https://keybase.io/davidrupp) on keybase.
  • I have a public key whose fingerprint is 99A3 E112 A4A4 96D1 64BB EB79 8D5F F86E 49D8 E7C5

To claim this, I am signing this object:

@davidrupp
davidrupp / seconds_to_days_hours_minutes_seconds.rb
Created October 14, 2009 16:23
seconds_to_days_hours_minutes_seconds
seconds = 356521
days, hours, minutes, seconds =
[1.day, 1.hour, 1.minute, 1.second].inject([]) do |acc, unit|
quotient, seconds = seconds.divmod unit
acc << quotient
end
@davidrupp
davidrupp / pull_all_git_repos.rb
Created November 4, 2009 02:31
find all git repos and 'git pull' each of them
#!/usr/bin/env ruby
require 'find'
Find.find("/Users/david/Developer") do |path|
Dir.chdir(path) do |d|
next unless File.exists? ("#{d}/.git")
puts d
`git pull`
Find.prune
@davidrupp
davidrupp / gemmate.rb
Created January 14, 2010 20:38 — forked from bguthrie/gemmate.rb
gemmate
#!/usr/bin/env ruby
if ARGV.empty?
puts "Usage: gemmate <name-of-gem>"
else
src = `gem which #{ARGV[0]}`.split.last
lib_dir = src.slice 0, src.rindex("lib")
`mate -a '#{lib_dir}'`
end