Skip to content

Instantly share code, notes, and snippets.

@burbma
burbma / utils.clj
Last active October 25, 2024 16:52
Clojure sym-map variants
;; Credit (Chad Harrington)[https://github.com/chadharrington] from whom I copied
;; `sym-map` and who thus inspired the others.
(defmacro sym-map
"Builds a map from symbols. Symbol names are turned into keywords and become the
map's keys. Symbol values become the map's values.
(let [a 1 b 2]
(sym-map a b)) ;; => {:a 1 :b 2}
"
[& syms]
@burbma
burbma / vt_tea.go
Created February 22, 2024 01:58
Pass VT to Bubbletea
// Incomplete code, leaves out the imports and Bubbletea model and setup
func nextFreeConsole() (int, error) {
f, err := os.OpenFile("/dev/tty0", os.O_WRONLY, 0)
if err != nil {
return 0, err
}
defer f.Close()
free, err := unix.IoctlGetInt(int(f.Fd()), linuxvt.VT_OPENQRY)
if err != nil {
@burbma
burbma / npmap.clj
Last active December 22, 2020 21:27
Clojure pmap with variable number of threads. Optionally operate on results real time via async/channel.
(defn npmap
"Like pmap but also takes n to specify the number of threads. Also differs
in that it can return the results on a channel. If you don't specify a
channel you will get all the results back in a vector after they are all
done. If you do pass in a channel results will be put on that channel
(by async/pipeline) as they are available. When all computation is done
async/pipeline closes said results channel."
([f n coll]
(->> coll
(npmap f n (async/chan))
@burbma
burbma / bokeh_default_select.ipynb
Created November 3, 2016 16:08
Bokeh default selected dot
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@burbma
burbma / unicorn.cljc
Last active August 16, 2016 15:03
clojure spec seq of maps
(ns unicorn
(:require [#?(:clj clojure.spec :cljs cljs.spec) :as s]
[#?(:clj clojure.spec.test :cljs cljs.spec.test) :as stest]))
(def names ["Eugene" "Smith" "Crabbs" "Jeff" "Shelly" "Barbra" "Joanne" "Jane"])
(s/def ::name (into #{} names))
(s/def ::is-white boolean?)
(s/def ::has-horn boolean?)
# Suppose I've pulled $CHILD out of $PARENT but lost the git history in the proccess.
# Let the last commit's sha1 that $CHILD was in $PARENT be denoted $LAST_COMMIT.
# Suppose further that I rename $CHILD, now I have $CHILD_OLD_NAME and $CHILD_NEW_NAME.
# If $CHILD was not renamed when pulled out you can use just $CHILD or set $CHILD_OLD_NAME and
# $CHILD_NEW_NAME to the same thing.
cd $PARENT
git co $LAST_COMMIT
git log --pretty=email --patch-with-stat --reverse --full-index --binary -- $CHILD_OLD_NAME > patch
cd ../$CHILD_NEW_NAME
git co master