Skip to content

Instantly share code, notes, and snippets.

@condotti
condotti / gist:845079
Created February 26, 2011 09:39
Start standalone swank-clojure server within emacs.
(defvar my-swank-clojure-command "c:/path/to/swank-clojure.bat")
(defun my-start-swank-server ()
(interactive)
(start-process "swank-clojure" " *swank-clojure*" my-swank-clojure-command))
@condotti
condotti / gist:845081
Created February 26, 2011 09:41
An advice for paredit in lisp-interaction-mode.
(defadvice paredit-newline (around eval-print-last-sexp activate)
(if (eq major-mode 'lisp-interaction-mode)
(eval-print-last-sexp)
(paredit-newline)))
@condotti
condotti / gist:848874
Created March 1, 2011 09:14
PowerShell.elでパスに漢字を使えるようにする (powershell-hookが無いのでdefadvice)
(defadvice powershell (after process-coding-system activate)
(mapc #'(lambda (process)
(if (eq (process-buffer process) (current-buffer))
(set-process-coding-system process 'sjis-dos 'sjis-dos)))
(process-list)))
(fn my-iterate [f x]
(cons x (lazy-seq (my-iterate f (f x)))))
; trampolineを書けって問題だと思ったら違ったのね
; せっかくだから書いたtrampolineをメモしとこう
(defn my-trampoline [f & args]
((fn [f] (if (fn? f) (recur (f)) f)) (apply f args)))
@condotti
condotti / word_chain.clj
Created May 26, 2011 09:36
https://4clojure.com/problem/82 の答なんだけど、大変だったから解き方のメモ
;; condotti's solution to Word Chains
;; https://4clojure.com/problem/82
; この問題は結局グラフに開いたハミルトン路が含まれるかに帰着します。
; 単語の順列を生成してしらみ潰しに調べればわかるのですが、効率が悪すぎるので、
; 単語を頂点、1文字違いの単語の組を辺と考えて、辺の組み合わせを生成します。
; 全ての辺を使ったグラフと頂点の数を変えずに、開いたオイラー路(一筆書き)が
; できれば、元のグラフにはハミルトン路が含まれることになります。元のグラフ
; から余計な辺を取り除くイメージですね。一筆書きは頂点の次数を求めれば判定
; できます。多分しらみ潰しに調べるよりも多少は効率がいいはず。
@condotti
condotti / my-org-export-as-pdf.el
Created July 28, 2011 01:09
orgからpdfにexport
(defcustom my-htmltopdf-program
"wkhtml2pdf"
"Program to convert html into pdf."
:type 'string
:group 'my)
(defcustom my-htmltopdf-args
""
"command arguments for my-htmltopdf-program"
:type 'string
@condotti
condotti / bf.clj
Created October 9, 2011 08:27
brainfuck interpreter in Clojure
(defn brainfuck [s]
(letfn [(fmb [[t p] f ip] ; find matching bracket
((fn [ip n]
(condp = (nth s ip)
t (if (= n 0) ip (recur (f ip) (dec n)))
p (recur (f ip) (inc n))
(recur (f ip) n)))
ip 0))]
((fn [c dp ip]
(if (< ip (count s))
@condotti
condotti / bf2.clj
Created October 9, 2011 08:32
brainfuck interpreter in Clojure, transient vector version
(defn brainfuck2 [s]
(let [c (transient (vec (repeat 30000 (byte 0))))]
(letfn [(fmb [[t p] f ip] ; find matching bracket
((fn [ip n]
(condp = (nth s ip)
t (if (= n 0) ip (recur (f ip) (dec n)))
p (recur (f ip) (inc n))
(recur (f ip) n)))
ip 0))]
((fn [dp ip]
(defn combination [k xs]
(if (pos? k)
(if (<= (count xs) k) (list xs)
(concat
(map #(conj % (first xs)) (combination (dec k) (rest xs)))
(combination k (rest xs))))))
(defn all-partitions [xs]
(map #(list % (seq (reduce disj (set xs) %)))
(combination (/ (count xs) 2) xs)))