Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Jürgen Hötzel juergenhoetzel

🎯
Focusing
View GitHub Profile
View gist:418216
(ns joc
(:use [clojure.test]))
(defn rpn-orig
([tokens] (rpn-orig tokens []))
([[top & tail] stack]
(lazy-seq
(if top
(if (fn? top)
(let [l (peek stack)
@juergenhoetzel
juergenhoetzel / lein-swank.el
Created May 30, 2010
Launch a Leiningen Swank Process and connect
We couldn’t find that file to show.
View contract.clj
(defmacro defcontract [name & forms]
(let [body (collect-bodies forms)]
(list* 'defn name body)))
(declare build-contract)
(defn collect-bodies [forms]
(for [form (partition 3 forms)]
(build-contract form)))
View DynaFrame.clj
(ns joy.gui.DynaFrame
(:gen-class
:name joy.gui.DynaFrame
:extends javax.swing.JFrame
:prefix df-
:implements [clojure.lang.IMeta]
:state state
:init init
:constructors {[String] [String]}
:methods [[display [java.awt.Container] void]
View widgets.clj
(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))
View calc-slice-count.clj
(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))
View web.clj
(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))
@juergenhoetzel
juergenhoetzel / hanging-shift-mode.el
Created Aug 9, 2010
Fix mistyped upcase characters in Emacs
View hanging-shift-mode.el
;;; 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)))
@juergenhoetzel
juergenhoetzel / defmethod-explicit.clj
Created Aug 10, 2010
Monkeying with Clojure’s defmethod Macro
View defmethod-explicit.clj
(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))
View defunits-of.clj
(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)))))