Skip to content

Instantly share code, notes, and snippets.

@bmabey
bmabey / named_params.clj
Created October 19, 2012 22:38
Named parameters, documented parameters, and named documented parameters in clojure
(ns rbl.utils.named-params
"Macros for creating functions with named and documented parameters.
The np-fn and defn-np macros are to create a functions with named parameters. They allow
for optional values to be provided in the fn declaration. The key information (e.g. required
keys) will live on the metadata of the function.
The dp-fn and defn-dp macros are to create a functions with documented parameters. They
will not allow functions to be defined without providing a corresponding docstring for
each parameter. The resulting para docs live as meta data on the fn.
/*
As of version 1.1.2, Propane will load and execute the contents of
~Library/Application Support/Propane/unsupported/caveatPatchor.js
immediately following the execution of its own enhancer.js file.
You can use this mechanism to add your own customizations to Campfire
in Propane.
Below you'll find two customization examples.

ordered-map-compiler-bug

From the REPL this code runs fine:

(def map-a {:a 1 :b 2 :c 3})
(def map-b {:a 1 :b 2 :c 3})
(def my-map
  (merge
   (ordered-map map-a)
@bmabey
bmabey / ch3.clj
Created August 18, 2012 22:11
noodling around with SICP and clojure.. taking advantage of all the built in seq functions instead of rolling it all from scratch. It feels like cheating but the underlying functions aren't hard too write anyways so it saves time.. and is more fun. :)
(ns sicp.ch3
(:use midje.sweet))
;; Exercise 3.55. Define a procedure partial-sums that takes as
;; argument a stream S and returns the stream whose elements are
; ;S0, S0 + S1, S0 + S1 + S2, .... For example, (partial-sums integers)
;; should be the stream 1, 3, 6, 10, 15, ....
(defn partial-sums [seq]
;; yeah, I know, seems like cheating
function yank {
cat $1 | pbcopy
}
function ywd {
pwd
pwd | tr -d '\n'| pbcopy
}
function csv-summary {
; Stolen from circumspec
(defmacro wtf
"'What the form' is going on? Convenience for macroexpand."
[form]
`(pprint (macroexpand-1 '~form)))
(defmacro wtff
"'What the full form' is going on? Convenience for macroexpand-all."
[form]
`(pprint (macroexpand-all '~form)))
@bmabey
bmabey / gist:1276546
Created October 10, 2011 21:09
pallet error
java.util.concurrent.ExecutionException: com.jcraft.jsch.JSchException: Auth fail
[Thrown class java.lang.RuntimeException]
Restarts:
0: [QUIT] Quit to the SLIME top level
1: [CAUSE1] Invoke debugger on cause com.jcraft.jsch.JSchException: Auth fail [Thrown class java.util.concurrent.ExecutionException]
2: [CAUSE2] Invoke debugger on cause Auth fail [Thrown class com.jcraft.jsch.JSchException]
Backtrace:
0: clojure.lang.LazySeq.sval(LazySeq.java:47)
#/usr/bin/env ruby
require 'set'
require 'rspec'
module WordBreak
class << self
def segmentize(string, dictionary)
end
end
@bmabey
bmabey / 1.8
Created August 15, 2011 05:03
odd jruby benchmarks going from 1.8 mode to 1.9
$ rvm use jruby-1.6.3 && jruby --server --1.8 lazy_benchmark.rb
Rehearsal ------------------------------------------------------
non-lazy one op 0.144000 0.000000 0.144000 ( 0.144000)
lazy one op 0.472000 0.000000 0.472000 ( 0.472000)
non-lazy two ops 0.068000 0.000000 0.068000 ( 0.068000)
lazy two ops 0.215000 0.000000 0.215000 ( 0.215000)
non-lazy three ops 0.057000 0.000000 0.057000 ( 0.057000)
lazy three ops 0.273000 0.000000 0.273000 ( 0.273000)
--------------------------------------------- total: 1.229000sec
Given an input string and a dictionary of words,
segment the input string into a space-separated
sequence of dictionary words if possible. For
example, if the input string is "applepie" and
dictionary contains a standard set of English words,
then we would return the string "apple pie" as output.
http://thenoisychannel.com/2011/08/08/retiring-a-great-interview-problem/