This file contains hidden or 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 CHEATSHEET | |
;; | |
;; * :require makes functions available with a namespace prefix. | |
;; | |
;; * :use makes functions available without a namespace prefix | |
;; (i.e., refers functions to the current namespace). | |
;; | |
;; * :import refers Java classes to the current namespace. | |
;; |
This file contains hidden or 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
#!/usr/bin/env perl | |
# Restores directories from an HFS+ Time Machine backup. Time Machine | |
# uses hard links to directories, which Linux does not support, so we have | |
# to suss out the actual directory locations and contents. | |
# | |
# Hard-linked directories have their "link count" stat set to a number which | |
# corresponds to a directory in the ".HFS+ Private Directory Data" | |
# directory, which can be found in the root of the volume. | |
# |
This file contains hidden or 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
set noswapfile | |
set nowrap | |
au BufRead,BufNewFile *.txt setlocal wrap " enable wrap for textfiles | |
set linebreak | |
set number | |
set tabstop=4 | |
set shiftwidth=4 | |
set softtabstop=4 |
This file contains hidden or 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://clojure-log.n01se.net/" java.net.URL. html-resource | |
(select {[:#main [:p (has [:b])]] [:#main [:p (right (has [:b]))]]}) | |
(let-select [[nick] [:b] | |
says [:p :> (but-node #{whitespace :b [:a first-of-type]})]] | |
[(text nick) (apply str (texts says))])) | |
(comment Sample output | |
(["bradbeveridge: " "is Java's ZipInputStream really slow, or am I using it wrong?\n clojurebot: pastebin?\n"] | |
["clojurebot: " "excusez-moi\n"] | |
["bradbeveridge: " "http://clojure.pastebin.com/zR9di5K0"] |
This file contains hidden or 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 enlive-mw.core | |
(:use compojure) | |
(:require [net.cgrand.enlive-html :as e])) | |
(e/deftemplate simple-layout "enlive_mw/layout.html" | |
[{:keys [title ps widget]}] | |
#{[:title] [:h1]} (e/content title) | |
[:p] (e/clone-for [p ps] (e/content p)) | |
[:#widget] (e/content widget)) |
This file contains hidden or 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
(set! *warn-on-reflection* true) | |
(defn bfs-seq [branch? children root] | |
"Same as tree-seq but walks the tree breadth-first instead | |
of depth-first." | |
(let [walk (fn walk [queue] | |
(when-let [node (peek queue)] | |
(lazy-seq | |
(cons node (walk (into (pop queue) | |
(when (branch? node) |
This file contains hidden or 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
;; TODO: make Windows-friendly; extensive tests | |
(defn- glob->regex [s] | |
"Takes a glob-format string and returns a regex." | |
(let [stream (java.io.StringReader. s)] | |
(loop [i (.read stream) | |
re "" | |
curly-depth 0] | |
(let [c (char i) |
This file contains hidden or 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
(use '(clojure.contrib (str-utils :only (str-join)))) | |
(def print-trace println) ;; rebind locally as appropriate | |
(defmacro trace [form] | |
`(let [value# ~form] | |
(print-trace (format "%s => %s" '~form value#)) | |
value#)) | |
(defn trace-seq* [name value] |
This file contains hidden or 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
(use 'clojure.contrib.duck-streams | |
'clojure.contrib.combinatorics) | |
;; pull in our word candidates (assumes a decent-quality list) | |
(def words (set (map #(.toLowerCase %) (read-lines "/Users/tin/src/clj/words.txt")))) | |
;; unscramble a word | |
(set (filter words (map (partial apply str) (permutations "rettul")))) | |
;; figure out the first word (four letters) |
This file contains hidden or 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
;; for minimal filesystem mocking (only listFiles and getName methods work) | |
(defn mock-filesystem | |
"Takes a tree of vectors and returns a minimal mock file/dir hierarchy" | |
[file] | |
(if (vector? file) | |
(let [[dir & files] file | |
children (into-array File (map mock-fs files))] | |
(proxy [File] [dir] | |
(listFiles [] children))) |
OlderNewer