Skip to content

Instantly share code, notes, and snippets.

(defn assert-only-expected-keys
"Make sure that there are no extra keys in the item"
[keyset item]
(mapv (fn [k] (is (keyset k) (str k " is not one of " keyset)))
(keys item))
item)
(defn assert-all-expected-keys
"Make sure that every expected key exists in the item"
[keyset item]
@gtrak
gtrak / gist:3372429
Created August 16, 2012 18:30
Compojure demo
(defn OPTIONS
"Generate a OPTIONS route with the given response."
[response]
(fn [request]
(when (= (:request-method request) :options)
response)))
(defroutes routes
(GET "/" [] "<h1>Hello World</h1>")
(context (:registry contexts) [] registry)
(def servlets
"Map of servlet classes to ring handlers, add here. Needs to be quoted so symbols resolve to themselves."
'{:my.servlet.class.Servlet hr/app})
(defmacro make-servlet
"Call to generate a servlet class given the class name and a ring handler."
[servlet handler]
(let [servlet (name servlet)
prefix (str servlet "-")]
`(do (println "Compiling Servlet" ~servlet)
@gtrak
gtrak / gist:3189404
Created July 27, 2012 18:02
jax-rs issue
INFO: Initiating Jersey application, version 'Jersey: 1.4 09/11/2010 10:30 PM'
Jul 27, 2012 6:00:42 PM com.sun.jersey.spi.inject.Errors processErrorMessages
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
WARNING: A sub-resource method, public javax.ws.rs.core.Response com.cloudera.hoop.Hoop.root(java.security.Principal,com.cloudera.hoop.GetOpParam,com.cloudera.hoop.FilterParam,com.cloudera.hoop.DoAsParam) throws java.io.IOException,com.cloudera.lib.service.HadoopException, with URI template, "/", is treated as a resource method
SEVERE: Method, public javax.ws.rs.core.Response com.cloudera.hoop.Hoop.get(java.security.Principal,com.cloudera.hoop.FsPathParam,com.cloudera.hoop.GetOpParam,com.cloudera.hoop.OffsetParam,com.cloudera.hoop.LenParam,com.cloudera.hoop.FilterParam,com.cloudera.hoop.DoAsParam) throws java.io.IOException,com.cloudera.lib.service.HadoopException, annotated with GET of resource, class com.cloudera.hoop.Hoop, is not recognized as valid
@gtrak
gtrak / gist:3136631
Created July 18, 2012 14:48
pomodoro
(ns pomoclojo.core
(:import [org.apache.commons.exec
PumpStreamHandler
DefaultExecutor
ExecuteWatchdog
CommandLine]
[java.io ByteArrayOutputStream])
(:use [clj-time.core :only [in-secs in-minutes now interval plus minus within? minutes secs]]))
(defn execute
@gtrak
gtrak / gist:3136468
Created July 18, 2012 14:21
swanker project.clj
(defproject swanker "0.1.0-SNAPSHOT"
:description "Swank REPL for various usages"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.4.0"]
[swank-clojure "1.4.2"]
[javax.servlet/servlet-api "2.5" :scope "provided"]]
:aot [swanker.core])
java.lang.AbstractMethodError: null
at clojure.core.protocols/fn (protocols.clj:73)
clojure.core.protocols$fn__5828$G__5823__5841.invoke (protocols.clj:13)
clojure.core$reduce.invoke (core.clj:6030)
@gtrak
gtrak / gist:3122677
Created July 16, 2012 13:20
Swank in web app
(ns swanker.core
(:require [swank.swank :as swank]))
(gen-class
:name swanker.core.ServletFilter
:prefix servlet-
:implements [javax.servlet.ServletContextListener])
(comment
@gtrak
gtrak / gist:3057775
Created July 6, 2012 02:49
Gary's 5-Year Course in Programming
Books I've read that I recommend, pretty much in the order that I read them, I'm not listing books that I
considered to be too specific, without any generic and fundamental knowledge, or that could easily be replaced by other, similar books:
Code Complete 2
Programming Pearls (didn't finish it yet)
The Pragmatic Programmer
Mythical Man Month
Effective C++ Scott Meyers
Design Patterns (Gang of Four) (good reference, but pretty dry)
Pattern Hatching (explains how they came up with them)
Refactoring (Martin Fowler, (google for the pdf, read the first few
(ns pomoclojo.core
(:import [org.apache.commons.exec
PumpStreamHandler
DefaultExecutor
ExecuteWatchdog
CommandLine]
[java.io ByteArrayOutputStream])
(:use [clj-time.core :only [in-secs in-minutes now interval plus minus within? minutes secs]]))
(defn execute