Skip to content

Instantly share code, notes, and snippets.

@djtango
djtango / all_db_object_sizes.sql
Last active June 6, 2019 13:47
Postgres Disk Usage
-- adapted from https://wiki.postgresql.org/wiki/Disk_Usage
SELECT *
, pg_size_pretty(total_bytes) AS total
, pg_size_pretty(index_bytes) AS INDEX
, pg_size_pretty(toast_bytes) AS toast
, pg_size_pretty(table_bytes) AS TABLE
FROM (
SELECT *, total_bytes-index_bytes-COALESCE(toast_bytes,0) AS table_bytes FROM (
SELECT c.oid,nspname AS table_schema, relname AS TABLE_NAME
, c.reltuples AS row_estimate
@djtango
djtango / heroku_to_jdbc.clj
Created July 19, 2019 12:19
Convert Heroku DB URL into a JDBC url
(ns heroku-to-jdbc
"untested and brittle parser - use at your own peril")
(defn colon?
[_ c]
(= c \:))
(defn label-result [result label]
(update result 0 (fn [x] [label x])))
@djtango
djtango / httpkit_ssl.clj
Created July 24, 2019 10:32
recipe for SSL configuration with httpkit to solve javax.net.ssl.SSLException
(ns httpkit-ssl
"recipe for SSL configuration with httpkit if you get javax.net.ssl.SSLException on Java 8
more info: https://github.com/http-kit/http-kit/issues/334"
(:require [org.httpkit.client :as http])
(:import (java.net URI)
(javax.net.ssl SSLEngine
SSLParameters
SNIHostName)))
(defn sni-configure
@djtango
djtango / core.clj
Created August 27, 2019 17:11
Clojure Socket Repl + clojure.test exception
(ns socket-test.core)
(defn foo
"I don't do a whole lot."
[x]
(println x "Hello, World!"))
@djtango
djtango / README.md
Created October 22, 2019 08:53
three-mens-morris

three-mens-morris

Kata: Three Men's Morris History

The game of Three Men's Morris, similar to Noughts and Crosses or Tic-Tac-Toe is known alternately as:

"Terni Lapilli" or "Three Stones" in Roman times
"Tapatan" in the Philippines

"Luk Tsut K'i" ('six man chess') in China

@djtango
djtango / capture.clj
Created August 15, 2020 21:27
capture function inputs and arguments for REPL debugging
(ns capture
"This is useful if you are debugging a dependency, for example")
(defmacro capture [fname atm]
`(alter-var-root
(var ~fname)
(fn [f#]
(fn [& args#]
(let [result# (apply f# args#)]
(swap! ~atm conj {:args args#