Skip to content

Instantly share code, notes, and snippets.


ed edthrn

View GitHub Profile
edthrn / redis.clj
Created Feb 20, 2021 — forked from ragnard/redis.clj
Using Redis for persistent memoization of Clojure functions
View redis.clj
(ns util.redis
(:refer-clojure :exclude [memoize])
(:require [taoensso.carmine :as car]))
;; boilerplate stuff that is not in Carmine
(def ^:dynamic ^:private *pool*)
(def ^:dynamic ^:private *spec*)
(defmacro with-redis
edthrn /
Created Feb 10, 2021
Remove old data from Git repo and Git history
# Taken from
# Warning:
# --------
# All stashes may be lost!
# 1. Force Git to process, but not check out, the entire history of every branch and tag
# 2. Remove the specified file, as well as any empty commits generated as a result
edthrn /
Last active Nov 20, 2019
Put a password stored in `1password` to clipboard
# Usage: ./
op get item $1 | jq -r '.details.fields[] | select(.designation=="password").value' | xclip -selection c
edthrn /
Last active Aug 16, 2019
Sorting for humans with Python
# Inspired by
# Adding a `key` argument so we can expect the same behaviour as the builtin `sorted`
import re
def humansorted(seq, key=None):
"""Return the sequence in the order that a human being expects.
If `key` is provided, as per the built-in `sorted` function, it must be a
callable that accepts a single argument.
edthrn /
Last active May 7, 2020
Execute Shell command on EC2 Linux instance with Python and Boto3
# Following
import boto3
ssm = boto3.client('ssm')
response = ssm.send_command(
Parameters={'commands': ['echo "This command ran on $(date)"']
edthrn /
Last active Jul 23, 2019
Sync content from one Postgres database to another

Say we have a database A hosted at loaded with data, and we want to replicate this data over database B, located at We suppose database A and B have identical schemas, and both databases are accessible via port 5432.

Dump content from database A

 pg_dump --data-only \
 -h \
 -U {database_user} \
 -f /tmp/dump.sql \
 -T={table pattern to exclude [optional]} \
edthrn /
Last active Jun 23, 2019
Execute shell commands in EC2 with SSM
import boto3
# Need AWS credentials in ~/.aws...
ssm = boto3.client('ssm')


Implement a Vector class. It should take an undefenite amount of parameters and behave like this:

>>> v1 = Vector(5, 9, -8, 2, 13, -23, 0, 0, 12)
>>> v2 = Vector(6, 8)
>>> v3 = Vector(-1, 1, 1, -1)
>>> v4 = Vector(0, 0, 0)
edthrn /
Last active Apr 10, 2019
A Bash script to automate Hadoop installation.
# MIT License
# Copyright (c) 2019
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
edthrn /
Created Apr 3, 2019
Reduce PDF size from Ubuntu command-line
# From
gs \
-sDEVICE=pdfwrite \
-dCompatibilityLever=1.4 \
-dPDFSETTINGS=/default \