Skip to content

Instantly share code, notes, and snippets.

@joinr
joinr / puzzle.clj
Last active December 30, 2022 14:32
Using core.logic to solve a puzzle in a game
(ns puzzle
(:require [clojure.core.logic :as l]))
;; At the dinner party were Lady Winslow, Doctor Marcolla, Countess Contee, Madam
;; Natsiou, and Baroness Finch.
;; The women sat in a row. They all wore different colors and [Doctor Marcolla] wore a
;; jaunty [white] hat. [Natsiou] was at the far left, next to the guest wearing
;; a [red] jacket. The lady in [blue] sat left of someone in [purple]. I remember
;; that [blue] outfit because the woman spilled her [rum] all over it. The
;; traveler from [dabrovka] was dressed entirely in [green]. When one of the dinner
@joinr
joinr / demo.clj
Created October 20, 2022 06:38
Fancy derive types for clojure
(ns demo
(:require [fancyclass :as fancy :refer [derives?]]))
(defprotocol SomeParentType)
(fancy/derived-type CustomMap [SomeParentType :base/map :arbitrary/tag])
;; demo> (def m (->CustomMap :name "Bilbo" :occupation "Burglar"))
;; #'demo/m
;; demo> m
;; {:occupation "Burglar", :name "Bilbo"}
(ns util
(:refer-clojure :exclude [pmap])
(:require [clojure.core.async :as async]))
(defn chan? [x]
(instance? clojure.core.async.impl.channels.ManyToManyChannel x))
(defn guess-physical-cores
"Hueristic used to account for likely prevalent
hyperthreading influencing the supposed available
@joinr
joinr / hexspeakfast.clj
Last active September 27, 2022 19:39
Exploring improvements on the relatively slow HexSpeak demo from https://github.com/ttsiodras/HexSpeak
;;performance opts by joinr
;;running openjdk 1.8 because reasons, bumped clojure dep to 1.11.1
(ns thanassis.hexspeakfast
(:gen-class))
(set! *warn-on-reflection* true)
(set! *unchecked-math* :warn-on-boxed)
(defn slength ^long [^String x] (.length x))
@joinr
joinr / req.edn
Created June 13, 2022 06:13
a sample request map
{:reitit.core/match
#reitit.core.Match{:template "/test2", :data {:handler #function[rental.routes.home/home-routes/fn--30830]},
:result
#reitit.ring.Methods{:get #reitit.ring.Endpoint{:data {:handler #function[rental.routes.home/home-routes/fn--30830]},
:handler #function[rental.routes.home/home-routes/fn--30830],
:path "/test2", :method :get, :middleware []},
:head #reitit.ring.Endpoint{:data {:handler #function[rental.routes.home/home-routes/fn--30830]},
:handler #function[rental.routes.home/home-routes/fn--30830],
:path "/test2", :method :head, :middleware []},
:post #reitit.ring.Endpoint{:data {:handler #function[r
@joinr
joinr / setup.org
Last active May 4, 2022 17:58
A setup guide for getting spacemacs and cider and lein working from a bare environment. We also turn on CUA mode to avoid dodgy emacs bindings.

Clojure Setup With SpaceMacs + Clojure Layer (Ubuntu)

We will use spacemacs as our editor here, although I choose to follow the emacs route for setup (spacemacs offers an alternative vim mode that many people like. We also set things up with leiningen. For an alternate guide that goes more in depth with tooling, and follows the vim/spacemacs conventions see practicalli spacemacs.

update

sudo apt-get update
@joinr
joinr / intcasts.clj
Last active March 20, 2022 21:28
an exploration of int casting and long reads in clojure
(require '[clj-java-decompiler.core :refer [decompile disassemble]])
(require '[primitive-math])
(set! *warn-on-reflection* true)
(set! *unchecked-math* :warn-on-boxed)
(decompile
(fn []
(let [xs (int-array 10)
idx 0]
(aset xs idx 0))))
@joinr
joinr / Profiler.diff
Last active March 12, 2022 19:48
minor changes
diff --git a/gamedata/lua/lua/sim/Profiler.lua b/gamedata/lua/lua/sim/Profiler.lua
index 89ef924..d3d106d 100644
--- a/gamedata/lua/lua/sim/Profiler.lua
+++ b/gamedata/lua/lua/sim/Profiler.lua
@@ -22,12 +22,25 @@ local thread = false
--- Data that we send over to the UI
local data = CreateEmptyProfilerTable()
+-- change:
+
@joinr
joinr / platoon.org
Created August 20, 2021 17:30
SCFA Explorations

lua/platoon.lua

Exploring coarse pathfinding code.

PlatoonGenerateSafePathToLOUD

Many internally lifted (e.g. local) functions here designed to leverage cached information from navgraphs and previous static path computations to prevent submitting path requests to the engine.

@joinr
joinr / transducerdataset.clj
Last active October 14, 2021 17:43
exploring datasets and transducers in tech.ml.dataset
(ns transducertest
(:require [tech.v3.dataset :as ds]
[clojure.core.reducers :as r]))
(def d (ds/->dataset {:a [1 2 3] :b [:foo :bar :baz]}))
(defprotocol ITransposable
(-row-major [obj])
(-column-major [obj]))