Skip to content

Instantly share code, notes, and snippets.

@gigamonkey
gigamonkey / tidy-branches
Last active February 1, 2018 01:22
Bash script for cleaning up local branches that have been removed from remotes
#!/bin/bash
# Prune remote branches that no longer exist on remotes
for remote in $(git remote); do
git remote prune "$remote"
done
# Delete branches whose tracking branch no longer exists
for b in $(git show-ref --heads | cut -c 53-); do
remote=$(git config "branch.$b.remote")
#!/usr/bin/env python3
#
# Dump all the messages from a given Slack channel since a certain
# timestamp, one line per message with timestamp and user name.
#
from datetime import datetime
from pytz import timezone, utc
#!/usr/bin/env python3
#
# Find the best matches between a set of dirty names and a canonical set.
#
# Is O(N^2) in the number of names.
#
import json
from lcs import lcs
@gigamonkey
gigamonkey / entitle_google_docs.js
Last active September 9, 2018 02:15
App Script script to change the link text of the link at the current cursor position to the name of the linked Google doc.
function onInstall() {
onOpen();
}
function onOpen() {
DocumentApp.getUi()
.createMenu('Fix links')
.addItem('Entitle link at cursor', 'entitleAtCursor')
.addItem('Entitle all links', 'entitleAllLinks')
.addToUi();
@gigamonkey
gigamonkey / logging.py
Last active October 16, 2017 08:30
Proof of concept of a decorator for logged database objects.
#!/usr/bin/env python3
from functools import wraps
import json
# Pretend this was logging to disk
log = []
def mutator(fn):
@gigamonkey
gigamonkey / ids.py
Last active September 5, 2017 23:09
#!/usr/bin/env python3
from time import sleep
from datetime import datetime, timezone
# Snowflake like ID generator that generates a 53-bit id suitable for sending as a number in JSON.
TIME_BITS = 40
COUNTER_BITS = 10
MACHINE_BITS = 3
@gigamonkey
gigamonkey / allen.md
Last active August 7, 2017 20:56
Turing Award Winner Fran Allen on changing role of women in computing. (From Coders at Work)

Turing Award Winner Fran Allen on changing role of women in computing. (From Coders at Work)

Seibel: You also mentioned before that when you started, people thought women would be good programmers because women were thought to be detail-oriented. These days the conventional wisdom is that it’s men who have a bizarre ability to focus on things, usually to the detriment of everything else, and that’s why most programmers are men.

Allen: Right.

(defun longest-increasing-subsequence (numbers)
(loop
with sequences = (make-array (1+ (length numbers)) :initial-element nil)
with length = 0
for i from 0
for n in numbers do
(loop
with lo = 1
with hi = length
while (<= lo hi) do
@gigamonkey
gigamonkey / lis.py
Created April 20, 2017 19:30
Whoops, Slyphon was doing LIS not LCS
#!/usr/bin/env python3
def lis_recursive(numbers, limit=0):
if not numbers:
return []
else:
n, *rest = numbers
if n >= limit:
@gigamonkey
gigamonkey / lcs.py
Created April 20, 2017 03:18
lcs for slyphon
#!/usr/bin/env python3
def lcs_recursive(a, b):
if a is "" or b is "":
return ""
else:
x = lcs_recursive(a[1:], b)
y = lcs_recursive(a, b[1:])
z = a[0] + lcs_recursive(a[1:], b[1:]) if a[0] == b[0] else ""
return max([x, y, z], key=lambda x: len(x))