Free excerpt from TypeSafe (pdf): Scala for the Impatient
I discovered the special syntax for a field setter:
class Person {
private var privateAge = 0 // Make private and rename
def age = privateAge
def age_ = (newValue: Int) {Free excerpt from TypeSafe (pdf): Scala for the Impatient
I discovered the special syntax for a field setter:
class Person {
private var privateAge = 0 // Make private and rename
def age = privateAge
def age_ = (newValue: Int) {| 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): |
| Check out README.md to get started editing Clojure with Emacs. |
| (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)) |
| ;; 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") |
| ;; 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) |
| (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) |
| ; 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. |
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