Skip to content

Instantly share code, notes, and snippets.

(try+
(+ 1 0)
(catch "foo" e
e))
(try+ (+ 1 0)
(catch "foo" e
e))
(try
@adreyer
adreyer / gist:184d11209955f4c0ccbf
Last active August 29, 2015 14:16
Is there a clojure function to do this?
(defn walk-leaves
"Walks a map applying a function to all non-map nodes(or leaves)"
[m f]
(let [handle-map (fn [[k v]] (if (map? v) [k v] [k (f v)]))]
(postwalk (fn [x] (if (map? x) (into {} (map handle-map x)) x)) m)))
(defn walk-leaves2
"Explicitly recursive with kitchsink/mapvals"
[m f]
(mapvals #(if (map? %) (map-leaves2 % f) (f %)) m))
#!/usr/bin/env ruby
require 'puppet-lint'
require 'json'
glob = File.join(ARGV[0], "**/*")
# choose only the manifests we care about
manifests = Dir.glob(glob).select {|name| name =~ /\.pp/}
manifests = manifests.reject {|name| name =~ /tests\//}
"requires": [
{
"fact":"/foo/bar",
"values": "{ |x| File.exists?(x)}"
}
]
@adreyer
adreyer / rules.rst
Last active December 15, 2015 12:29
a contest of magic for 2-5 players

Goal

To start with a shuffled pool of magic cards and allow 2-5 players to immediately start playing a limited format that will usually terminate in under an hour.

Requirements

the game is played with a shuffled pool of cards containg spells and land as well as one of each basic land per player. This is basically a cube or booster packs shuffled with basic land but we do not know the optimal makeup.

@adreyer
adreyer / README
Created December 9, 2011 15:15
proxy load tester
-set /etc/hosts so that www.test.wsbtv.com points to the OTIS vip-
-cd here
-run "runload.sh 100
@adreyer
adreyer / cookies.js
Created November 22, 2011 18:31
cookie grabber
stupid cookie parser
@adreyer
adreyer / README.rst
Created October 25, 2011 19:52
a simple script for loadtesting solr using it's logs

there are many loadtesting tools here.

apache_load_test.js

replays a single apache log piped into it delaying requests to occur at the same rate they did. takes a single argument, the host to make the request to. A cookie can be copied into line 22 to make authenticated requests

multi-apache

import inspect
def binder(fun, *args, **kwargs):
""" given a function fun, args and kwargs will bind the values or
defaults and return a dictionary. Doesn't do anything with
variable args or kwargs now """
arg_spec = inspect.getargspec(fun)
arg_names = arg_spec[0]
defaults = arg_spec[3]
binding = {}