Skip to content

Instantly share code, notes, and snippets.

View RutledgePaulV's full-sized avatar

Paul Rutledge RutledgePaulV

View GitHub Profile
@RutledgePaulV
RutledgePaulV / bktree.clj
Last active August 1, 2022 14:35
bktree.clj
(defn create-index [distance-fn]
(with-meta {} {:distance-fn distance-fn}))
(defn index->root [index]
(-> index meta :root))
(defn index->distance-fn [index]
(-> index meta :distance-fn))
@RutledgePaulV
RutledgePaulV / auth.clj
Created October 1, 2021 21:24
hikari rotating iam auth
(ns auth
(:import (com.zaxxer.hikari HikariDataSource HikariConfig)
(com.amazonaws.services.rds.auth RdsIamAuthTokenGenerator GetIamAuthTokenRequest)
(com.amazonaws.auth DefaultAWSCredentialsProviderChain)
(com.amazonaws.regions DefaultAwsRegionProviderChain)
(java.util Properties)
(java.time Duration)))
(defn parse-jdbc-url [jdbc-url]
(let [matcher (re-matcher #"//(?<host>[^:]+):(?<port>\d+)/(?<database>[^\\?]+)" jdbc-url)]
@RutledgePaulV
RutledgePaulV / dufus-diff.clj
Created March 10, 2021 20:42
dufus-diff.clj
(defn diff-branches [repo branch1 branch2]
(letfn [(tree-iterator [^Repository repo branch]
(let [head (.exactRef repo branch)]
(with-open [walk (RevWalk. repo)]
(let [commit (.parseCommit repo (.getObjectId head))
tree (.parseTree walk (.getId (.getTree commit)))
parser (CanonicalTreeParser.)]
(with-open [reader (.newObjectReader repo)]
(.reset parser reader (.getId tree)))
(.dispose walk)
@RutledgePaulV
RutledgePaulV / workseq.clj
Last active February 24, 2021 07:25
doseq but with work broken out into thread pools of specified sizes
(defmacro workseq [bindings & body]
(let [bind (first (partition 2 bindings))]
(if (empty? bindings)
`(do ~@body nil)
`(let [right# ~(second bind)
value# (first right#)
workers# (second right#)
num-values# (count value#)]
(if (and (< 1 workers#) (< 1 num-values#))
(let [thread-pool# (Executors/newFixedThreadPool workers#)
@RutledgePaulV
RutledgePaulV / ansilove
Created February 8, 2021 04:39
basic ansilove docker image. does not use a minimal distribution or evaluate checksums
FROM ubuntu:latest
ENV DEBIAN_FRONTEND=noninteractive
RUN apt-get update && apt-get install -y build-essential cmake wget libgd-dev
RUN wget https://github.com/ansilove/libansilove/archive/1.2.8.tar.gz \
&& tar -xvf 1.2.8.tar.gz \
&& cd libansilove-1.2.8 \
&& mkdir build \
&& cd build \
@RutledgePaulV
RutledgePaulV / timer.clj
Created July 4, 2020 22:34
A task timer for self-optimizing programs that favors recent timings over older timings.
(ns piped.tools
(:require [amalloy.ring-buffer :as rb]))
(defprotocol Timer
(start [this key] "Given some key, start timing it.")
(stop [this key] "Given some key, stop timing it.")
(avg [this] "Get the weighted average of timings tracked thus far with this timer. Recent timings are weighted more."))
(defn weighted-average
"Calculates the weighted average of numbers. Each subsequent number is weighted one
@RutledgePaulV
RutledgePaulV / less-1.7.5-nashorn.js
Created May 23, 2020 20:34
less-1.7.5-nashorn.js
/* Less.js v1.7.5 RHINO | Copyright (c) 2009-2014, Alexis Sellier <self@cloudhead.net> */
/*global name:true, less, loadStyleSheet, os */
function readFile(url) {
var result = "";
var imports = new JavaImporter(java.net, java.lang, java.io);
with (imports) {
(defn teed-writer [^Writer source ^Writer fork]
(proxy [Writer] []
(write
([c]
(cond
(int? c)
(do (.write source (int c))
(.write fork (int c)))
(string? c)
(do (.write source ^String c)
(defn tree-seq-bf [branch? children root]
(letfn [(walk [node]
(when (branch? node)
(lazy-seq
(let [children (children node)]
(lazy-cat children (mapcat walk children))))))]
(cons root (walk root))))
@RutledgePaulV
RutledgePaulV / install-latex.sh
Created January 18, 2020 18:27
install latex
#!/bin/bash
brew cask install basictex
find /Library/TeX/texbin/* -type f | xargs -L1 -I{} sh -c "base=$(basename {}); ln -sf {} /usr/local/bin/$base"