This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (define-syntax rotate | |
| (syntax-rules () | |
| [(rotate a) (void)] | |
| [(rotate a b c ...) (begin | |
| (swap a b) | |
| (rotate b c ...))])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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))] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defmacro predeclare-defs [& forms] | |
| (let [defforms (filter #(is-prefixed-with-def? (str (first %))) forms) | |
| names (map #(second %) defforms)] | |
| `(do (declare ~@names) ~@forms))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ;;; 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (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$"))] |