Skip to content

Instantly share code, notes, and snippets.

(defn score
"Score site with pssm"
[pssm site]
(reduce (fn [acc [col-hash c]]
(+ acc (col-hash c)))
0
(zip pssm site)))
@gtrak
gtrak / relativize.clj
Created June 30, 2013 21:09
Simple HTML URL rewriting using compojure/laser, relativizing to a servlet-context path.
(defn add-context-fn
[attr context]
(fn [node]
(update-in
node
[:attrs attr]
(fn [val]
(let [val (str val)]
(if (or (-> val java.net.URI. .isAbsolute)
(.startsWith val "//")
(ns com.gtrak.emu.chips.ym2612)
(defmacro defs
[& def-specs]
(let [def-specs (partition 2 def-specs)
forms (for [[var val] def-specs]
`(def ~var ~val))]
`(do ~@forms)))
(defn restricted-logging
"Helper function to make cascading logging do something useful while running Hadoop queries."
[]
(doto (Logger/getRootLogger)
(.setLevel Level/INFO)
(.addAppender (WriterAppender. (SimpleLayout.) *out*)))
(-> (Logger/getRootLogger)
.getLoggerRepository
(.getLogger "org.apache.zookeeper")
(.setLevel Level/ERROR)))
(def mailbox-map
(vec (flatten [(repeat 20 -1)
(map #(do [-1 % -1])
(partition 8 (range 64)))
(repeat 20 -1)])))
(def mailbox-map
(vec (concat (repeat 20 -1)
(flatten (map #(concat [-1] % [-1])
(partition 8 (range 64))))
(repeat 20 -1))))
@gtrak
gtrak / gist:5468481
Last active December 16, 2015 17:09
nice screenshat
(12:10:18 PM) Gary Trakhman: screenshotting.. you are a talented noun-verber.
(12:10:39 PM) Gary Trakhman: to screenshoot maybe
(12:10:43 PM) Scott Bale: I know, right?
(12:11:39 PM) Alex Hall: @gary i believe 'screenshoot' is actually the noun form of the verb 'to screenshot'
(12:12:07 PM) Gary Trakhman: ah yes, a screenshoot
(12:12:15 PM) Scott Bale: but 'screenshot' is past-tense of 'screenshoot' verb
(12:13:00 PM) Scott Bale: You have to know how to conjugate these noun-verbs.
no.disassemble> (println (disassemble (class (fn []))))
no/disassemble$eval11772$fn__11773
#<byte[] [B@13940478>
// Compiled from NO_SOURCE_FILE (version 1.5 : 49.0, super bit)
public final class no.disassemble$eval11772$fn__11773 extends clojure.lang.AFunction {
// Method descriptor #7 ()V
// Stack: 0, Locals: 0
public static {};
0 return
@gtrak
gtrak / gist:5239837
Created March 25, 2013 19:21
clojure reflections
(ns reflection
;;(:import nothing)
)
(defn class-loader
"could be any classloader"
[]
(.getContextClassLoader (Thread/currentThread)))
(defn get-class
@gtrak
gtrak / deferred.clj
Created March 12, 2013 00:14
Deferred loading. Remove :use and :requires from the ns declaration, as that will load the referred classes recursively in the static initializer of your namespace. Total time spent loading classes doesn't change, but you can amortize it along the perceptions of the user in chunks.
(defmacro deferred
"Loads and runs a function dynamically to defer loading the namespace.
Usage: \"(deferred clojure.core/+ 1 2 3)\" returns 6. There's no issue
calling require multiple times on an ns."
[fully-qualified-func & args]
(let [func (symbol (name fully-qualified-func))
space (symbol (namespace fully-qualified-func))]
`(do (require '~space)
(let [v# (ns-resolve '~space '~func)]
(v# ~@args)))))