Skip to content

Instantly share code, notes, and snippets.

@rlm
rlm / classpath_utils.clj
Created January 12, 2011 03:03
export_files.clj
(ns rlm.classpath-utils
(:require [clojure.contrib [duck-streams :as ds]])
(:use [clojure.contrib java-utils]))
(defn classpath []
(get-system-property "java.class.path"))
(defn add-to-classpath [file-name]
@sunilnandihalli
sunilnandihalli / curry.clj
Created December 17, 2010 20:33
a macro to create fixed-arity curryable function in clojure
(defmacro def-curry-fn [name args & body]
{:pre [(not-any? #{'&} args)]}
(if (empty? args)
`(defn ~name ~args ~@body)
(let [rec-funcs (reduce (fn [l v]
`(letfn [(helper#
([] helper#)
([x#] (let [~v x#] ~l))
([x# & rest#] (let [~v x#]
(apply (helper# x#) rest#))))]
@mja
mja / homebrew_scipy.sh
Created December 13, 2010 08:09
Install numpy, scipy, and matplotlib on OS X 10.6
homebrew install gfortran
homebrew install python
homebrew install distribute
homebrew install pip
pip install ipython
pip install numpy
pip install scipy
pip install -f http://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.0/matplotlib-1.0.0.tar.gz matplotlib
anonymous
anonymous / gist:734122
Created December 8, 2010 23:39
~/projects/jruby ➔ jmap -histo 19907 | grep rubyobj | head -50
116: 1945 46680 rubyobj.Gem.Version
118: 1898 45552 rubyobj.Gem.Version
120: 1826 43824 rubyobj.Gem.Requirement
123: 1804 43296 rubyobj.Gem.Requirement
158: 914 21936 rubyobj.Gem.Dependency
166: 876 21024 rubyobj.Gem.Dependency
209: 463 11112 rubyobj.Gem.Specification
211: 455 10920 rubyobj.Gem.Specification
319: 142 3408 rubyobj.ActiveSupport.TimeZone
class A
def implicit_block_implicit_ensure
begin
"block"
ensure
"ensure"
end
end
def implicit_block_explicit_ensure
@pjb3
pjb3 / method_vs_attr_reader.rb
Created October 16, 2010 11:56
Apparently attr_reader is faster than a method in all ruby implementations. Why?
require 'benchmark'
puts
puts ENV["RUBY_VERSION"]
class A
def initialize(foo)
@foo = foo
end
def foo
# Allow RSpec assertions over the elements of a collection. For example:
#
# collection.should all_be > 0
#
# will specify that each element of the collection should be greater
# than zero. Each element of the collection that fails the test will
# be reported in the error message.
#
# Examples:
# [1,1,1].should all_be eq(1)
(defn mapmap
"Return a new map, mapping keys to (keyfn key) and mapping values to
(valfn val)"
([valfn map]
(mapmap identity valfn map))
([keyfn valfn map]
(persistent! (reduce
(fn [c [k v]] (assoc! c (keyfn k) (valfn v)))
(transient {})
map))))
@mnutt
mnutt / Instrument Anything in Rails 3.md
Created September 6, 2010 06:50
How to use Rails 3.0's new notification system to inject custom log events

Instrument Anything in Rails 3

With Rails 3.0 released a few weeks ago I've migrated a few apps and I'm constantly finding useful new improvements. One such improvement is the ability to log anything in the same way that Rails internally logs ActiveRecord and ActionView. By default Rails 3 logs look slightly spiffier than those produced by Rails 2.3: (notice the second line has been cleaned up)

Started GET "/" for 127.0.0.1 at Mon Sep 06 01:07:11 -0400 2010
  Processing by HomeController#index as HTML
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1
  CACHE (0.0ms)  SELECT `users`.* FROM `users` WHERE (`users`.`id` = 3) LIMIT 1

Rendered layouts/_nav.html.erb (363.4ms)

(ns org.dipert.reconfig
"Reads a file of Clojure data into *config*
when a SIGHUP is recieved.
Useful for daemons that support the reloading of
configuration data while running."
(:use [clojure.contrib.io :only (reader)]
[clojure.contrib.logging :only (info warn)])
(:import (sun.misc Signal SignalHandler)
(java.io File PushbackReader)))