This file contains 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
@EventHandler | |
public void onInvClick(InventoryClickEvent event) { | |
Player p = (Player) event.getWhoClicked(); | |
if(event.getRawSlot() == event.getSlot()) { | |
p.sendMessage("TOP"); | |
} | |
else { | |
p.sendMessage("BOTTOM"); | |
} | |
} |
This file contains 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
#!/bin/bash | |
# | |
# This file echoes a bunch of color codes to the | |
# terminal to demonstrate what's available. Each | |
# line is the color code of one forground color, | |
# out of 17 (default + 16 escapes), followed by a | |
# test use of that color on all nine background | |
# colors (default + 8 escapes). | |
# | |
# Shamelessly stolen from: |
This file contains 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 partial* [f & static-args] | |
(fn [& dynamic-args] | |
(loop [args [] | |
static-args static-args | |
dynamic-args dynamic-args] | |
(if-let [static (first static-args)] | |
(if (= static :%) | |
(if-let [dynamic (first dynamic-args)] | |
(recur (conj args dynamic) (rest static-args) (rest dynamic-args)) | |
(throw (Exception. "too few arguments"))) |
This file contains 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 '[clojure.zip :as z]) | |
(defn forms-zip | |
"Returns a clojure.zip zipper over a tree of Clojure forms." | |
[form] | |
(z/zipper coll? | |
#(if (map? %) (interleave (keys %) (vals %)) (seq %)) | |
#(cond | |
(map? %1) (apply hash-map %2) | |
(seq? %1) %2 |
This file contains 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
function pbcopy(data) { | |
var proc = require('child_process').spawn('pbcopy'); | |
proc.stdin.write(data); | |
proc.stdin.end(); | |
} |
This file contains 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 parse-opts [ks aseq] | |
(let [ks (set ks)] | |
(loop [last-k nil | |
opts {} | |
frontier aseq] | |
(if-let [value (first frontier)] | |
(if (ks value) | |
(recur value opts (rest frontier)) | |
(recur last-k (update-in opts [last-k] (fnil conj []) value) (rest frontier))) | |
opts)))) |
This file contains 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 expr-fn.core | |
(:require [clojure.walk :as walk])) | |
(defn forms-seq [form] | |
(tree-seq coll? | |
#(if (map? %) (interleave (keys %) (vals %)) %) | |
form)) | |
(defn resolved? [form] | |
(if (coll? form) |
This file contains 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
; http://www.reddit.com/r/Clojure/comments/2behsz/clojurescript_debugging_tips/cj4mvok | |
(defmacro defntraced | |
"Define a function with it's inputs and output logged to the console." | |
[sym & body] | |
(let [[_ _ [_ & specs]] (macroexpand `(defn ~sym ~@body)) | |
new-specs | |
(map | |
(fn [[args body]] | |
(let [prns (for [arg args] |
This file contains 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 scale | |
"Converts the number `x` from the scale `[old-min old-max]` to the scale | |
`[new-min new-max]`." | |
[x [old-min old-max] [new-min new-max]] | |
(let [old-range (- old-max old-min) | |
new-range (- new-max new-min)] | |
(+ (/ (* (- x old-min) new-range) old-range) new-min))) |
This file contains 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 weighted-choice | |
"Given a map `choices {outcome weight}`, returns a randomly chosen `outcome`. | |
The likelihood that a particular `outcome` will be chosen is proportional to | |
its assigned `weight`." | |
[choices] | |
(->> choices | |
(mapcat (fn [[outcome weight]] (repeat weight outcome))) | |
rand-nth)) |
OlderNewer