Skip to content

Instantly share code, notes, and snippets.

View cloojure's full-sized avatar

Alan Thompson cloojure

View GitHub Profile
@cloojure
cloojure / tst-demo-core.clj
Created January 10, 2020 16:03
Symbol (double-deref) vs Var obj (single-deref) vs Value (plain object). Auto-deref of Var obj in function call.
(ns tst.demo.core
(:use tupelo.core tupelo.test))
(def wilma 3)
; `wilma` is a global symbol that points to
; an Var object, that points to
; a java.lang.Long object of value `3`
(dotest
(is= java.lang.Long (type wilma))
@cloojure
cloojure / string-to-hashcode.clj
Created July 31, 2019 16:42
Replicating Java's String.hashCode() method for a cljc project
(ns tst.demo.core
(:use demo.core tupelo.core tupelo.test)
(:require [tupelo.core :as t]) )
(defn str->hashcode
"Work-alike impl of Java String.hashCode() fn"
[str-val]
(let [char-codes (mapv int str-val)
step-fn (fn step-fn [hash-in char-code]
(let [hash-out (+ char-code
@cloojure
cloojure / with_properties.clj
Created July 31, 2019 16:40
Temporarily redefine jvm system properties to include user-specified items
(defmacro with-properties
"Temporarily redefine jvm system properties to include entries from `props-user`."
[props-user & body]
`(let [props-orig# (into {} (for [[prop-key# prop-val#] ~props-user]
[prop-key# (System/getProperty prop-key#)]))]
(doseq [prop-key# (keys ~props-user)]
(System/setProperty prop-key# (get ~props-user prop-key#)))
(try
~@body
(finally
@cloojure
cloojure / Demo.java
Created February 27, 2019 19:36
Java example:
package expr;
import java.io.InputStream;
import static java.lang.System.in;
import static java.lang.System.out;
class Gopher implements Runnable {
public void run() {
try {
@cloojure
cloojure / rot13.clj
Created June 1, 2016 01:25
Clojure Rot13 test
(ns tst.clj.core
(:use clj.core
clojure.test
tupelo.core))
(def first-char \a)
(def first-char-val (int first-char))
(defn str->codes
[arg-str]