Skip to content

Instantly share code, notes, and snippets.

(defn my-count [coll]
(reduce (fn [n x] (inc n)) 0 coll))
(my-count [1 2 3 3]) ;; produces 4
(defn my-reverse [coll]
(reduce (fn [xs x] (into [x] xs)) [] coll))
(my-reverse [1 2 3]) ;; => [3 2 1]
;; Tom Crayford adapted this from clojure-test-mode.el
(require 'clojure-mode)
(require 'cl)
(require 'slime)
(require 'swank-clojure)
(require 'which-func)
;; Faces
(defun untabify-buffer ()
(interactive)
(untabify (point-min) (point-max)))
(defun indent-buffer ()
(interactive)
(indent-region (point-min) (point-max)))
(defun cleanup-buffer ()
"Perform a bunch of operations on the whitespace content of a buffer."
(defn some-name [f] ;; Takes a function that
(fn [& fns] ;; Returns a function that takes a list of functions that returns
(fn [& args] ;; A function that calls the original function with identity over applying each function to the args of this anonymous function #ohgod
(f identity (map apply fns (repeat args))))))
@tcrayford
tcrayford / rspec.vim
Created October 24, 2010 22:09
Better rspec compiler for vim
" Vim compiler file
" Language: RSpec
" Maintainer: Tim Pope <[email protected]>
" Last Change: 2009 Dec 22
" URL: http://vim-ruby.rubyforge.org
" Anon CVS: See above site
" Release Coordinator: Doug Kearns <[email protected]>
if exists("current_compiler")
finish
@tcrayford
tcrayford / lua_assert.vim
Created November 13, 2010 00:32
lua_assert.vim
" Vim compiler file
" Language: Lua assertions
if exists("current_compiler")
finish
endif
let current_compiler = "lua_assert"
if exists(":CompilerSet") != 2
command -nargs=* CompilerSet setlocal <args>
Thu Dec 9 22:15 2010 Time and Allocation Profiling Report (Final)
Main +RTS -p -RTS
total time = 1312.56 secs (65628 ticks @ 20 ms)
total alloc = 563,371,406,784 bytes (excludes profiling overheads)
COST CENTRE MODULE %time %alloc
findOffsetIn Cipher 26.9 21.6
#!/usr/bin/env ruby
freqs = Hash.new(0)
files = `find . -name "*.java" -print`
results = files.split("\n").map do |filename|
`git blame #{filename}`
end.map do |blame_result|
blame_result.split("\n")
end.each do |blame_result_array|
blame_result_array.map do |blame_line|
#!/usr/bin/env ruby
freqs = Hash.new(0)
commits = `git log --pretty=oneline --abbrev-commit`.split("\n").map do |line|
line.split(" ")[0]
end
commits.map do |sha|
`git show --pretty="format:" --name-only #{sha}`
@tcrayford
tcrayford / game_of_life.rb
Created March 10, 2011 20:23
An (unfinished) game of life implementation by @t_crayford and @AvivBY
#Any live cell with fewer than two live neighbours dies, as if caused by under-population.
#Any live cell with two or three live neighbours lives on to the next generation.
#Any live cell with more than three live neighbours dies, as if by overcrowding.
#Any dead cell with exactly three live neighbours becomes a live cell, as if by reproduction.
class Cell
attr_accessor :x, :y
def initialize(x,y)
@x = x
@y = y
end