Skip to content

Instantly share code, notes, and snippets.

chr15m /
Last active April 12, 2023 00:10
Hash map / dictionary / associative array implementation for bash
# Bash hash-map which works in Bash 3.
# WARNING: this code is useless and you should not use it. See the comments.
# Hashing function from Adam Katz:
ht() {
local h=0 i
for (( i=0; i < ${#1}; i++ )); do
let "h=( (h<<5) - h ) + $(printf %d \'${1:$i:1})"
chr15m /
Created March 28, 2022 03:19
Extract channel names from xm or it files saved with modplug tracker
from sys import argv
f = open(argv[1], "rb").read()
i = f.index(bytearray("CNAM", "utf8"))
for n in range(3):
x = f[i+n*20+8:i+n*20+28].decode("utf8")
print(n, x)
chr15m / git-cloc
Last active January 14, 2022 02:29
Count lines of code in your git repo
View git-cloc
# Count the lines of source code checked into your repository
# Requires the `cloc` command as a dependency.
# You can pass extra arguments to cloc like this:
# git cloc --exclude-dir=build --exclude-ext=js
git ls-tree -r `git branch | grep '^*' | colrm 1 2` --name-only | sed 's/.*/"&"/' | xargs cloc "$@"
chr15m / outlined-drop-shadow-header.html
Created December 28, 2021 13:46
Outlined drop-shadow header demo
View outlined-drop-shadow-header.html
<!doctype html>
<html lang="en-us">
<title>Fat font drop shadow.</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="mobile-web-app-capable" content="yes">
<meta name="description" content="Pure CSS fat outline letters with hard drop shadow.">
@import url('');
chr15m / sync-deps.clj
Created October 3, 2021 08:25
Generate :npm-deps in deps.cljs from package.json using nbb
View sync-deps.clj
(ns update-deps
["fs" :as fs]
[clojure.edn :as edn]
[clojure.pprint :refer [pprint]]))
(let [package (js/require "../package.json")
js-deps (js->clj (aget package "dependencies"))
deps (edn/read-string (fs/readFileSync "src/deps.cljs" "utf8"))
deps-updated (assoc deps :npm-deps js-deps)]
chr15m /
Created October 28, 2020 04:14
Python wrapper for byzanz-record to capture gifs
#!/usr/bin/env python
# You'll need to have `xrectsel` and `byzanz-record` installed
from __future__ import print_function
import re
import sys
import subprocess
if len(sys.argv) == 1:
chr15m / Makefile
Created February 27, 2020 13:14
Makefile rules to activate Python virtualenv for the whole Makefile
View Makefile
# get makefile's own path
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir := $(dir $(mkfile_path))
# add virtualenv in folder "virtualenv" to the path
export PATH := $(mkfile_dir)/virtualenv/bin:$(PATH)
export VIRTUAL_ENV=$(mkfile_dir)/virtualenv
python # <- this will be called with virtualenv activated
chr15m / microtest.hy
Created August 29, 2019 05:46
Hy testing microframework
View microtest.hy
; *** Test harness
; Note: works in Hy 0.11.1 - needs to be upgraded for recent Hy
(defn print-expression [expr]
(+ "(" (.join " " (list-comp (cond [(= (type x) HyExpression) (print-expression x)]
[(= (type x) HyString) (+ "\"" x "\"")]
[True (str x)]) [x expr])) ")"))
(defmacro test-case [expr]
(quasiquote (do
chr15m / vintage-old-school-console-effect-css.html
Created March 15, 2019 07:41
Vintage old-school console effect boilerplate HTML and CSS
View vintage-old-school-console-effect-css.html
<!DOCTYPE html>
<meta charset="utf-8">
<meta content="width=device-width, initial-scale=1" name="viewport">
<title>Vintage console</title>
function log(message) {
document.getElementById("log").textContent += message + "\n";
chr15m / websockets.js
Created July 6, 2018 02:02
Minimal Javascript websocket client/server
View websockets.js
// server
ws = require('ws');
wss = new ws.Server({ port: 8033 });
wss.on('connection', function(s) {
console.log("got connection", s);
s.on('message', function incoming(message) {
console.log("received", message);