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 mapmap | |
"Return a new map, mapping keys to (keyfn key) and mapping values to | |
(valfn val)" | |
([valfn map] | |
(mapmap identity valfn map)) | |
([keyfn valfn map] | |
(persistent! (reduce | |
(fn [c [k v]] (assoc! c (keyfn k) (valfn v))) | |
(transient {}) | |
map)))) |
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
(defconst java-import-regex "^[[:space:]]*import[[:space:]]+\\(.*\\)\\.\\(.*\\);") | |
(defun clojure-java-import-line-parse (line) | |
(unless (string-match java-import-regex line) | |
(error "No import line")) | |
(let ((package (match-string-no-properties 1 line)) | |
(symbol (match-string-no-properties 2 line))) | |
(list package symbol))) | |
(defun clojure-java-import-region (start 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
(defun slime-update-namespace () | |
"Find the namespace in the current buffer and set the package of | |
the REPL buffer to PACKAGE." | |
(interactive) | |
(let ((package (slime-find-buffer-package))) | |
(if package | |
(slime-repl-set-package package) | |
(call-interactively 'slime-repl-set-package)))) |
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
(comment " | |
SpeedNotes Clojure script, by Torbjørn Marø. | |
Version 1.0 - 2010.08.17 | |
Clojure version 1.1 (w/Contrib) | |
====================================================================== | |
Always have it running in a console window to quickly note down stuff | |
you need to remember - thoughts and ideas you don't want to loose, | |
but don't want to steal focus away from what you are currently doing | |
either. |
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
(defmacro defunits-of [quantity base-unit & units] | |
(let [magnitude (gensym) | |
unit (gensym) | |
conversions (apply hash-map base-unit 1 units)] | |
`(defmacro ~(symbol (str "unit-of-" quantity)) | |
[~magnitude ~unit] | |
`(* ~~magnitude | |
~(relative-units ~unit ~conversions))))) |
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
(defmacro defmethod-explicit | |
[multifn dispatch-val & fn-tail] | |
(let [[kw n & body] fn-tail] | |
(if (= :as kw) | |
`(let [~n ~dispatch-val] | |
(defmethod ~multifn ~dispatch-val ~body)) | |
`(defmethod ~multifn ~dispatch-val ~fn-tail)))) | |
(defmulti expl-mm (juxt first second)) |
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
;;; hanging-shift-mode.el --- | |
;; Author: Jürgen Hötzel <juergen@archlinux.org> | |
;; http://stackoverflow.com/questions/3431911/emacs-should-set-the-second-character-of-a-word-in-lower-case | |
(require 'cl) | |
(defun hanging-shift-sanitise-word () | |
(interactive) | |
(let ((word (current-word t t))) |
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 joy.web | |
(:import (com.sun.net.httpserver HttpHandler HttpExchange HttpServer) | |
(java.net InetSocketAddress HttpURLConnection) | |
(java.io IOException FilterOutputStream) | |
(java.util Arrays))) | |
(defn default-handler [txt] | |
(proxy [HttpHandler] [] | |
(handle [exchange] | |
(.sendResponseHeaders exchange HttpURLConnection/HTTP_OK (.length txt)) |
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 calc-slice-count [thing] | |
"Calculates the number of possible slices using the formula: | |
(n + r - 1)! | |
------------ | |
r!(n - 1)! | |
where n is (count thing) and r is 2" | |
(let [! #(reduce * (take % (iterate inc 1))) | |
n (count thing) | |
r 2] | |
(/ (! (- (+ n r) 1)) |
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
(import (javax.swing Box BoxLayout JTextField JPanel | |
JSplitPane JLabel JButton JOptionPane) | |
(java.awt.event ActionListener) | |
(java.awt Component GridLayout FlowLayout)) | |
(defn shelf [& components] | |
(let [shelf (JPanel.)] | |
(.setLayout shelf (FlowLayout.)) | |
(doseq [c components] (.add shelf c)) | |
shelf)) |