Skip to content

Instantly share code, notes, and snippets.

View KirinDave's full-sized avatar

Dave Fayram KirinDave

View GitHub Profile
(require '(blogpost [bloomfilters :as 'bloom])
; We can do it this way:
(extend-protocol BloomFilterable
MyIntHolder
(make-hash [this] (.data this)) ; return own data
(human-readable-hash [this] (str (.data this)))) ; return a string
; Or perhaps like this:
(extend-type MyIntHolder
bloom/BloomFilterable
@KirinDave
KirinDave / Makefile
Created August 5, 2010 15:47
Random number in a range. Assumes you have GNU GSL in /usr/local/*
GSL_BUILDFLAGS=-I/usr/local/include -L/usr/local/lib -lgsl
all: rnd+gsl
rnd+gsl: rnd+gsl.c
g++ $(GSL_BUILDFLAGS) -o rnd+gsl rnd+gsl.c
(define-syntax rotate
(syntax-rules ()
[(rotate a) (void)]
[(rotate a b c ...) (begin
(swap a b)
(rotate b c ...))]))
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
*
* The contents of this file are subject to the terms of the Common Development
* and Distribution License("CDDL") (the "License"). You may not use this file
* except in compliance with the License.
*
* You can obtain a copy of the License at:
(defn get-route [route-map req]
(loop [routes (keys route-map)]
(let [route (first routes)]
(if (route-matches route req)
(get route-map route)
(recur (rest routes))))))
; This is one way
(defn get-route [route-map req]
(when-let [[route fun] (first (filter #(route-matches (first %) req) route-map))]
(defmacro predeclare-defs [& forms]
(let [defforms (filter #(is-prefixed-with-def? (str (first %))) forms)
names (map #(second %) defforms)]
`(do (declare ~@names) ~@forms)))
(defn- pre-and-unparse-date [pre formatter string]
"Expects pre to return a vector, [v, data]. Returns [(unparse formatter v), data].
If nil is returned from pre, it is propagated. If unparse fails, also returns nil."
(when-let [[v data] (pre string)]
(try
[(parse formatter v) data]
(catch IllegalArgumentException e
nil))))
(defn- split-out-timezone [str]
(defn date-for-request-header [request header-name]
(when-let [val (-> request :headers (get (.toLowerCase header-name)))]
(when-let [[t tz] (date-timezone-from-string val)]
(when (#{"UTC" "GMT"} tz)
t))))
@KirinDave
KirinDave / main.el
Created November 23, 2010 05:19
My core emacs config
;;; Dave Fayram's Emacs setup.
;;; ~/.emacs -> (load "~/.emacs.d/main.el)
;;; This was installed by package-install.el.
;;; This provides support for the package system and
;;; interfacing with ELPA, the package archive.
;;; Move this code earlier if you want to reference
;;; packages in your .emacs.
(when
(load
(ns com.banksimple.util.scala-tools
(:require [clojure.contrib [string :as str]]
[def :as deftools]))
(defmacro import-singleton [klass-sym]
(let [singleton-str (str klass-sym "$")
simple-name (symbol (.toLowerCase (last (str/split #"\." (str klass-sym)))))
singleton-sym (symbol singleton-str)
mod-field-sym (symbol (str singleton-str "/MODULE$"))]