Skip to content

Instantly share code, notes, and snippets.

<?xml version="1.0"?>
<!--
Convert podcast RSS to commands for curl.
Originally from bashpodder, modified by Alexander Solovyov.
Usage:
xsltproc podcast2wget.xsl path/to/podcast.rss
OR
;; extend honeysql
(defmethod honeyhelpers/build-clause :returning [ _ m cols]
(assoc m :returning (honeyhelpers/collify cols)))
(defmethod honeyfmt/format-clause :returning [[_ cols] _]
(str "RETURNING " (honeyfmt/comma-join (map honeyfmt/to-sql cols))))
(extend-protocol honeyfmt/ToSql
clojure.lang.Sequential
@piranha
piranha / change-wallpaper.sh
Last active May 22, 2016 07:00
Set desktop wallpaper
#!/bin/sh
if [ -z "$1" ]; then
echo "Usage: $0 <path-to-wallpaper>"
exit 1
fi
realpath() {
[[ $1 = /* ]] && echo "$1" || echo "$PWD/${1#./}"
}
(ns mk.fe.core.why-update
(:require [cljsjs.react]))
(defn comp-did-update [prev-props prev-state]
(this-as this
(let [name (or (aget this "displayName")
(aget this "constructor" "displayName")
(aget this "constructor" "name"))
prev-state (aget prev-state ":rum/state")
state (aget (.-state this) ":rum/state")]
@piranha
piranha / cx.clj
Last active February 2, 2018 17:51
(defmacro cx [& classes]
"This macro compiles this:
(cx :one true :two true :three false :four (pos? 1))
Into this:
[ \"one two\", 1 > 0 ? \"four\" : null ].join(\" \")
"
(let [class-map# (partition 2 classes)
groups# (group-by (fn [[k v]]
@piranha
piranha / async-profiler-mw.clj
Created February 5, 2019 10:38
Async Profile Middleware
(defn make-profile-transform [^String thread-name]
(fn [^String s]
(when (> (.indexOf s thread-name) -1)
(-> s
(str/replace #"com.fasterxml.jackson.+" "JACKSON...")
(str/replace #"org.elasticsearch.client.RestClient.+" "ES request...")
(str/replace #"clojure.tools.logging/.+" "LOG...")))))
(defn profiler-mw [handler]
@piranha
piranha / hex.clj
Created March 11, 2020 12:33
hex and unhex in clojure
(defn hex [ba]
(->> (map #(format "%02x" %) ba)
(apply str)))
(defn unhex [s]
(->> (partition 2 s)
(map #(Integer/parseInt (apply str %) 16))
byte-array))
@piranha
piranha / encrypt.clj
Last active March 11, 2020 12:46
Simple encryption/decryption in Clojure
(ns encrypt
(:import [javax.crypto Cipher]
[javax.crypto.spec SecretKeySpec]
[java.security MessageDigest]
[java.util Base64 Base64$Encoder Base64$Decoder]))
(def SECRET (or (System/getenv "SECRET")
(binding [*out* *err*]
(print "\nWARNING: set 'SECRET' env variable to be secure\n\n")
:headers = <<
Content-Type: application/json
#
# what indices are there
GET http://localhost:9200/_cat/indices
# delete product
DELETE http://localhost:9200/product
@piranha
piranha / recdescent.js
Created June 11, 2023 16:48
Simple recursive descent in JavaScript
const test = require('node:test');
const assert = require('node:assert').strict;
let RE = /[\s,()]/;
function tokenize(s) {
var tokens = []
let j = 0;
for (var i = 0; i < s.length; i++) {