Skip to content

Instantly share code, notes, and snippets.

@joinr
joinr / demo.clj
Created July 10, 2024 06:18
accurate serialization of false values with nippy on top of java.io.Serializable
(ns demo
(:require [taoensso.nippy :as nippy])
(:import [java.io ObjectOutputStream ObjectInputStream]))
;;https://gist.github.com/orendon/e38ac86dcd4c64cadad8fd5c749452b7
(defn serialize
"Serializes value, returns a byte array"
[v]
(let [buff (java.io.ByteArrayOutputStream. 1024)]
(with-open [dos (java.io.ObjectOutputStream. buff)]
@joinr
joinr / notes.md
Created May 14, 2024 06:50
notes on "Embracing Common Lisp in the Modern World"

[Since OP deleted the original post, I ported my response from https://www.reddit.com/r/Clojure/comments/1afviv4/embracing_common_lisp_in_the_modern_world/kod6r0d/?context=3]

I saw this pop on the lisp subreddit and concurred with some of the criticisms of the claims. I have not watched the presentation, but based my remarks on the slide contents.

10.1 Compiled Code Performance

CL implementations compile to machine code, often more CPU efficient.

Especially true for numeric and CPU-intensive tasks
@joinr
joinr / hangman.clj
Created April 26, 2024 15:10
port of demo hangman project to maps
(ns first-cloj.core)
(def list-of-words ["horse" "dog" "bird"])
(def init {:guesses [] :incorrect-guesses 0})
(def hang-vec
[" ______"
" | |"
" O |"
"/|\\ |"
@joinr
joinr / transform.clj
Created March 29, 2024 03:10
Meander experiments with vega
(require '[meander.epsilon :as m])
(require '[meander.strategy.epsilon :as m*])
(def simplify-conjunctions
(m*/rewrite
[:and_expr ?x] ?x
[:or_expr ?x] ?x))
(def simplify-all-conjs
(m*/bottom-up
@joinr
joinr / transit.cljs
Last active March 21, 2024 00:20
messing with transit to avoid the clj->js tax
(require '[cognitect.transit :as t])
(def jt js/transit)
(def r (t/reader :json))
(def w (t/writer :json))
(def jr (jt.reader "json"))
@joinr
joinr / parallelism.txt
Created January 16, 2024 21:26
paralleldiscuss
Outside of the bevy of good answers, I think there's some utility in discerning between concurrency and parallelism. I like rob pike's talk "Concurrency is not Parallelism". Clojure has great features for handling concurrency (dealing with lots of things happening at the same time) and enabling correct solutions without much effort. Those features extend into enabling parallelism (doing lots of things at the same time). I think the immutable data model and the early focus on integrated STM constructs (designed to be used with the immutable data structures) helped a lot. core.async borrowing the communicating sequential processes (CSP) from go added even more options for correct concurrency.
So if you can write correct concurrent programs, then you can begin to leverage system resources (e.g. cores) to distribute how work is done and maybe get some performance improvement on top (or maybe not, or maybe up to a point....it depends).
Alternately, if you have a bunch of independent work that you want to chew th
@joinr
joinr / brute.clj
Last active December 5, 2023 21:48
revised brute force day 5-2
(defn some-fast [f xs]
(reduce (fn [acc x]
(let [res (f x)]
(if res (reduced res)
acc)))
false xs))
(defn toDigits [s] (mapv read-string (re-seq #"\d+" s)))
(defn parseInput [d]
@joinr
joinr / primred.clj
Created October 22, 2023 07:12
primitive reducing, now primitive backed vectors don't have to suck as much.
(ns prims)
(defprotocol IPrimitiveReducible
(reduce-prim- [this f init]))
(definterface IPrimitiveReduce
(^long LLLreduce [^clojure.lang.IFn$LLL f ^long init])
(^double DDDreduce [^clojure.lang.IFn$DDD f ^double init]))
(def am->type
@joinr
joinr / project.clj
Created July 19, 2023 12:58
upated harmonikit project file
(require '[leiningen.core.utils :refer [get-os]])
(def JVMOPTS
"Per os jvm options. Options common to all cases go under
`:any`. Options specific to one OS go under the key returned by
`leiningen.core.eval/get-os` for that system. Temporarily disabled
options can be kept under `:disabled`."
{:any
["-Xms512m" "-Xmx1g" ; Minimum and maximum sizes of the heap
"-XX:MaxGCPauseMillis=20" ; Specify a target of 20ms for max gc pauses
@joinr
joinr / threadjunk.clj
Created June 15, 2023 05:21
exgenous pseuo thread-local variable concept.
(ns threadjunk
(:import [java.util.concurrent ConcurrentHashMap]
[java.util.function Function]))
;;satisfy conc hashmap's needs..
(defn Func ^Function [f]
(reify Function
(apply [this v] (f v))))
(defn get-binding! [^ConcurrentHashMap ctx k ^Function f]