Skip to content

Instantly share code, notes, and snippets.

View jebberjeb's full-sized avatar

Jeb Beich jebberjeb

View GitHub Profile
(find-ns 'baz)
(create-ns 'baz)
(find-ns 'baz)
(= 5 (bit-and 5 15))
(not= 5 (bit-and 5 16))
(+ Long/MAX_VALUE 1)
;ArithmeticException integer overflow clojure.lang.Numbers.throwIntOverflow (Numbers.java:1388)
(+ (bigint Long/MAX_VALUE) 1)
;9223372036854775808N
(def a-map {:foo "foozle" :bar "barzle"})
(prn "reader readable -- read-string works")
(prn a-map)
(eval (read-string (with-out-str (pr a-map))))
(println "human readable -- read-string throws")
(println a-map)
(eval (read-string (with-out-str (print a-map))))
(ns cli-tools-app.core
(:require [clojure.tools.cli :refer [cli]])
(:gen-class))
(defn parse-args
[args]
(cli args
["-u" "--username" "PropSol API username" :default
"rentpath@trinitypm"]
["-p" "--password" "PropSol API password" :default
(ns test-app.core)
;; get from a map, vector, set
(def r (range 10))
(def m (->> r
(map (juxt (comp keyword str) identity))
(into {})))
(def v (apply vector (keys m)))
(def s (set (keys m)))
(ns test-app.core)
(def r (range 10))
(def s (set r))
(def v (apply vector r))
;; We can do this because set is seqable, so
;; drop-while can seq it.
(drop-while (partial > 5) s)
(ns test-app.core)
(defn get-rand-by-n
[n]
(* n (rand)))
(with-redefs
[clojure.core/rand (fn [] 2)]
(= 6 (get-rand-by-n 3)))
[(= (next (range 10))
(rest (range 10)))
(= (next '(1)) ;; => nil
(rest '(1))) ;; => ()
(= (next nil) ;; => nil
(rest nil))] ;; => ()
(partition-by #(mod % 3) (range 1 10))
;;((1) (2) (3) (4) (5) (6) (7) (8) (9))
(partition-by #(mod % 3) (mapcat (partial repeat 3) (range 1 10)))
;;((1 1 1) (2 2 2) (3 3 3) (4 4 4) (5 5 5) (6 6 6) (7 7 7) (8 8 8) (9 9 9))
(group-by #(mod % 3) (range 1 10))
;;{1 [1 4 7], 2 [2 5 8], 0 [3 6 9]}
(group-by #(mod % 3) (mapcat (partial repeat 3) (range 1 10)))