This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
;; | |
;; NS CHEATSHEET | |
;; | |
;; * :require makes functions available with a namespace prefix | |
;; and optionally can refer functions to the current ns. | |
;; | |
;; * :import refers Java classes to the current namespace. | |
;; | |
;; * :refer-clojure affects availability of built-in (clojure.core) | |
;; functions. |
This gist is part of a blog post. Check it out at:
http://jasonrudolph.com/blog/2011/08/09/programming-achievements-how-to-level-up-as-a-developer
; SLIME | |
user> | |
user> (load-file "c:/projects/github/fix-clj/src/fix_clj/core.clj") | |
#'fix-clj.core/next-value-and-rest | |
user> (load-file "c:/projects/github/fix-clj/test/fix_clj/test_core.clj") | |
nil | |
user> (use ['fix-clj.core 'fix-clj.test_core] :reload-all :verbose) | |
; Evaluation aborted. | |
user> (use '[fix-clj.core fix-clj.test_core] :reload-all :verbose) | |
; Evaluation aborted. |
(defn any-pair-make-sum? [arr target] | |
(let [m (frequencies arr)] | |
(loop [f (first arr) | |
x (- target f) | |
r (rest arr)] | |
(let [entry (find m x) | |
only-needs-one-count (not (= x f))] | |
(if (and entry (or only-needs-one-count (> 1 (val entry)))) | |
true | |
(if (empty? r) |
;; See: http://codereview.stackexchange.com/q/6682/9032 | |
(defn map-invert-preserve-dups [m] | |
(apply merge-with into | |
(for [[k v] m] | |
{v [k]}))) | |
(->> "http://www.weeklyscript.com/Pulp%20Fiction.txt" | |
(slurp) | |
(re-seq #"\w{5,}") | |
(frequencies) |
;; Datomic example code | |
(use '[datomic.api :only (db q) :as d]) | |
;; ?answer binds a scalar | |
(q '[:find ?answer :in ?answer] | |
42) | |
;; of course you can bind more than one of anything | |
(q '[:find ?last ?first :in ?last ?first] | |
"Doe" "John") |
(defn method-spy | |
"Print out reflection info about a method." | |
[classname methodname] | |
(let [c (Class/forName classname) | |
all-methods (.getDeclaredMethods c) | |
matching-methods (filter #(= methodname (.getName %)) all-methods) | |
pr-col (fn [name info] (println (format "%24s: %s" name info)))] | |
(doseq [m matching-methods] | |
(println (.toGenericString m)) | |
(pr-col "ReturnType" (.getReturnType m)) |
Check out README.md to get started editing Clojure with Emacs. |
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer | |
from zipfile import ZipFile | |
from string import join | |
import os | |
import re | |
def getMavenCoordinates(elements): | |
return dict(zip(('group', 'artifact', 'version'), elements)) | |
def getMavenArtifactName(coordinates): |