Skip to content

Instantly share code, notes, and snippets.

(defroutes admin-routes
(GET "/admin" request (admin-index request)))
(wrap! admin-routes :require-admin)
(defroutes app
(GET "/" request (index request))
admin-routes)
(wrap! app :log-analytics)
@xeqi
xeqi / refactor-ruby-koan-182.rb
Created July 19, 2011 03:48
Refactor ruby koan 182
# http://stackoverflow.com/questions/6738715/ruby-koans-182-refactor-help
def old_score(dice)
rollGreedRoll = Hash.new
rollRollCount = Hash.new
(1..6).each do |roll|
rollGreedRoll[roll] = roll == 1 ? GreedRoll.new(1000, 100) :
GreedRoll.new( 100 * roll, roll == 5 ? 50 : 0)
rollRollCount[roll] = dice.count { |a| a == roll }
end
@xeqi
xeqi / gist:1439142
Created December 6, 2011 17:46
clojure binding and resolve
user> (binding [*ns* nil] (ns-resolve 'clojure.core '=))
#'clojure.core/=
user> (binding [*ns* nil] (resolve 'clojure.core/=))
No message.
[Thrown class java.lang.NullPointerException]
Restarts:
0: [QUIT] Quit to the SLIME top level
Backtrace:
@xeqi
xeqi / gist:1449897
Created December 9, 2011 02:40
swank classloader-heirarchy
user> (defn classloader-heirarchy
([]
(classloader-heirarchy (clojure.lang.RT/baseLoader)))
([tip]
(if tip
(conj (classloader-heirarchy (.getParent tip)) tip) [])))
#'user/classloader-heirarchy
user> (classloader-heirarchy)
[#<ExtClassLoader sun.misc.Launcher$ExtClassLoader@7ea2dfe> #<AppClassLoader sun.m\
isc.Launcher$AppClassLoader@61ba34f2> #<DynamicClassLoader clojure.lang.DynamicCla\
@xeqi
xeqi / gist:1449916
Created December 9, 2011 02:48
clojure version mismatch error
No message.
[Thrown class java.lang.ExceptionInInitializerError]
Restarts:
0: [QUIT] Quit to the SLIME top level
1: [CAUSE1] Invoke debugger on cause Attempting to call unbound fn: #'clojure.core/refer [Thrown class java.lang.IllegalStateException]
Backtrace:
0: clojure.set__init.__init0(Unknown Source)
1: clojure.set__init.<clinit>(Unknown Source)
@xeqi
xeqi / output.txt
Created March 1, 2012 06:20
clojure.java.jdbc, sqlite3, transactions, and resultsets
$ TEST_DBS=sqlite mvn clojure:test
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building java.jdbc
[INFO] task-segment: [clojure:test]
[INFO] ------------------------------------------------------------------------
Downloading: http://repo1.maven.org/maven2/net/sourceforge/jtds/jtds/1.2.4/jtds-1.2.4.pom
Downloading: http://repo1.maven.org/maven2/net/sourceforge/jtds/jtds/1.2.4/jtds-1.2.4.jar
@xeqi
xeqi / pallet.clj
Last active December 14, 2015 23:39
immutant and pallet
(require
'[pallet.crate.git :refer [git clone]]
'[pallet.crate.java :refer [java]]
'[pallet.crate.lein :refer [lein leiningen]])
(def repo "git://github.com/jcrossley3/random-apps-of-kindness.git")
(def demo-directory "random-apps-of-kindness/demo")
(defplan setup-machine
@xeqi
xeqi / gist:6227351
Created August 14, 2013 01:45
bob exercism
class Bob
def hey(message)
behaviors = {
-> {message.nil? || message.strip.empty?} => 'Fine. Be that way!',
-> {message.upcase == message} => 'Woah, chill out!',
-> {message[-1].chr == '?'} => 'Sure.'
}
behaviors.fetch(behaviors.keys.find(&:call), "Whatever.")
end
end
@xeqi
xeqi / build.clj
Last active August 29, 2015 14:17
(require 'cljs.closure)
(require 'cljs.js-deps)
(import 'java.net.URLClassLoader)
(import 'java.net.URL)
(def react-url
"https://clojars.org/repo/cljsjs/react/0.13.0-0/react-0.13.0-0.jar")
{ :repl {:plugins [[cider/cider-nrepl "0.9.0-SNAPSHOT"]]
:dependencies [[org.clojure/tools.nrepl "0.2.7"]]}