Skip to content

Instantly share code, notes, and snippets.

View keegancsmith's full-sized avatar

Keegan Carruthers-Smith keegancsmith

View GitHub Profile
@keegancsmith
keegancsmith / index.html
Created January 26, 2024 09:45
SSE with gzip in go playground
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>SSE</title>
</head>
<body onload="onLoaded()">
<h1>Server Sent Events</h1>
@keegancsmith
keegancsmith / darwin_notmuch_config.py
Created July 29, 2023 21:37
_notmuch_config.py fixes
#/nix/store/5xxrp9pq2jsm30aqhca1x9sbrw3m7394-notmuch-0.37-bindingconfig/_notmuch_config.py
# _notmuch_config.py was automatically generated by the configure
# script in the root of the notmuch source tree.
NOTMUCH_VERSION_FILE='/private/tmp/nix-build-notmuch-0.37.drv-0/notmuch-0.37/version.txt'
NOTMUCH_INCLUDE_DIR='/private/tmp/nix-build-notmuch-0.37.drv-0/notmuch-0.37/lib'
NOTMUCH_LIB_DIR='/private/tmp/nix-build-notmuch-0.37.drv-0/notmuch-0.37/lib'
#!/usr/bin/env bash
cmd=${1-urls}
query='tag:gh and tag:inbox body:"Reply to this email directly or view it on GitHub"'
case "$cmd" in
"urls")
notmuch show "$query" | egrep -o '^https://github\.com.*/(issues|pull)/[0-9]+' | sort | uniq
;;
@keegancsmith
keegancsmith / magnus_dist.py
Created August 9, 2020 17:07
Magnus Distance
#!/usr/bin/env python3
# We read from stdin a list of lichess games of the format winner loser gameid.
# We calculate the "erdos number", but for people who have defeated magnus.
# We output number of people with a specific magnus number. Uses a BFS.
import fileinput
from collections import defaultdict, deque
# G is a graph. name -> { opponents won }
@keegancsmith
keegancsmith / postgres-gin.org
Last active August 6, 2020 22:21
exploring pg_trgm

Postgres trigram exploration

  • State “DONE” from “TODO” [2020-08-07 Fri 00:19]
[2020-08-06 Thu 21:30]

I went a bit off the deep end and compiled postgres to better understand the gin + pg_trgm indexes. I was seeing weird behaviour where =~

@keegancsmith
keegancsmith / update-pricedb.py
Last active February 24, 2022 20:01
Maintain .pricedb file for ledger3 for gbp/usd to zar
#!/usr/bin/env python3
from html.parser import HTMLParser
import datetime
import itertools
import os.path
import re
import urllib.request
symbols = {
@keegancsmith
keegancsmith / docker
Created December 17, 2019 11:33
docker CLI wrapper which adds the current cgroup as the --cgroup-parent
#!/usr/bin/env python3
import os
import os.path
import sys
def get_memory_cgroup(data):
for line in data.splitlines():
if not line:
@keegancsmith
keegancsmith / beams.py
Last active September 6, 2019 21:50
Randomized greedy algorithm for allocating presized beams
import random, collections
sizes = [6, 6.6, 7.2, 7.8, 8.4, 9.6, 12]
beams = [
(6, 3.700),
(37, 6.700),
(4, 5.600),
(40, 7.800),
(2, 1.100),
@keegancsmith
keegancsmith / go.mod
Created October 8, 2018 14:08
Example of how k8s sends protobuf responses for GET and GET watches
module k8sgetexample
require (
github.com/ericchiang/k8s v1.2.0
github.com/golang/protobuf v1.2.0
golang.org/x/net v0.0.0-20181005035420-146acd28ed58 // indirect
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f // indirect
golang.org/x/text v0.3.0 // indirect
)
(use-package org-gcal
:config
(setq org-gcal-client-id "REDACTED"
org-gcal-client-secret "REDACTED"
org-gcal-file-alist '(("REDACTED" . "~/org-files/gcal.org")
("REDACTED" . "~/org-files/office.org")
("REDACTED" . "~/org-files/oncall.org")))
;; org-gcal wrappers to only sync with a timeout
(defvar org-gcal-fetch-last-run (current-time)
"Timestamp of the last time org-gcal-fetch-store-time was run")