Skip to content

Instantly share code, notes, and snippets.

(def ^:dynamic *err-info* nil)
(defmacro with-error-data [data & body]
`(let [old-data# *err-info*]
(when *err-info*
(set! *err-info* (merge *err-info* ~data)))
(let [result# (do ~@body)]
;; if no exception was thrown above, revert *err-info*:
(when *err-info*
(set! *err-info* old-data#))
https://4clojure.oxal.org/#/problem/117
; 227
#(loop [[[y x] & q] (for [[y r] (map list (range) %)
[x c] (map list (range) r)
:when (= \M c)]
[y x])
b (vec (map vec %))]
(if x
(if (= \C ((b y) x))
true
#!/usr/bin/env bash
# Use this share-session script in your tmux config to ease multi-user pairing,
# like this:
# set-option -g status-interval 5
# set-option -g status-right '#(/home/chouser/repos/tmux-multiuser/share-session go+rwx go+rw) | "#{pane_title}" #(date +"%H:%M %d-%b-%Y")'
# Set socket dir and socket permissions
chmod "$1" "${TMUX%/*}"
chmod "$2" "${TMUX%%,*}"
@Chouser
Chouser / malli_play.clj
Created February 3, 2023 04:54
Playing around with specs in malli
(ns us.chouser.malli-play
(:require [malli.core :as m]
[malli.error :as me])
(:import (clojure.lang ExceptionInfo)))
;; {:deps {metosin/malli {:mvn/version "0.10.1"}}}
;; No refinement chaining yet
;; No clear separation of constraint violation from runtime error
(defn var-sym [v]
@Chouser
Chouser / filter-with-context.clj
Created January 29, 2023 23:19
A handful of implementations of "grep -C"
;; primitive lazy-seq
(defn filter-with-context-ls [pred n coll]
(let [step (fn step [buffer suffix coll]
(lazy-seq
(when-let [[v & more] (seq coll)]
(if (pred v)
(concat (take-last n buffer) [v] (step [] n more))
(if (pos? suffix)
(cons v (step [] (dec suffix) more))
(step (conj buffer v) 0 more))))))]
(ns us.chouser.merge-sort
"Experiments in parallel folding of vectors"
(:require [clojure.core.reducers :as r]
[criterium.core :as c]
[dom-top.core :refer [loopr]]))
(set! *warn-on-reflection* true)
(defn array-type
"Return a string representing the type of an array with dims
@Chouser
Chouser / experiment.clj
Created April 22, 2022 00:49
core async reseting experiment
(ns io.chouser.experiment
(:require [clojure.core.async :as async]))
(defn bang []
(future
(dotimes [i 10]
(async/go
(print (str "start " i "\n")) (flush)
(Thread/sleep 20000)
(prn :done i)))))
; In England the currency is made up of pound, £, and pence, p, and
; there are eight coins in general circulation:
;
; 1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).
;
; It is possible to make £2 in the following way:
;
; 1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p
;
; How many different ways can £2 be made using any number of coins?
(ns party.units
(:refer-clojure :exclude [+ - * /])
(:require [clojure.algo.generic.arithmetic :as ari :use [+ - * /]]
[clojure.algo.generic.math-functions :refer [pow]]
[clojure.repl :refer [doc source apropos dir find-doc]]))
(defrecord Measurement [sym factor units]
clojure.lang.IFn
(invoke [a b] (* a b)))
@Chouser
Chouser / keybase.md
Created December 14, 2017 21:59
keybase.md

Keybase proof

I hereby claim:

  • I am chouser on github.
  • I am chouser (https://keybase.io/chouser) on keybase.
  • I have a public key whose fingerprint is 2835 9367 72DD 2F1C BBCF BBED 94AE 902B F718 ED2A

To claim this, I am signing this object: