Skip to content

Instantly share code, notes, and snippets.

@akheron
akheron / PG.js
Created November 5, 2018 12:36
purescript-postgresql-client library monad
exports.getSQLState = function (error) {
return error.code || ''
}
exports.getError = function (errorType) {
return function (error) {
return {
errorType: errorType,
severity: error.severity || '',
code: error.code || '',
@akheron
akheron / benchmark.md
Last active July 30, 2017 05:56
elm-make benchmark

The test

Clone rtfeldman/elm-spa-example. Download all deps: elm-package install --yes.

Then time the builds running these commands:

rm -rf elm-stuff/build-artifacts
@akheron
akheron / get-workspaces.sh
Created May 26, 2017 10:51
i3 workspace/output helpers
#!/bin/sh
usage() {
echo "usage: get-workspaces.sh OUTPUT"
echo ""
echo "Print the names of workspaces on the given output"
echo ""
exit 2
}
@akheron
akheron / smtpd_fixture.py
Last active June 30, 2021 10:26
SMTP server pytest fixture
# The SMTP server runs in a separate thread and stores sent messages in a list
#
# Usage:
#
# def test_fn(smtpd):
# host = smtpd.host
# port = smtpd.port
#
# # Run code that send email using an smtp server at host:port
#
import logging, logging.config
TOPIC_NAME = 'TOPIC-NAME'
GROUP_NAME = 'GROUP-NAME'
BOOTSTRAP_SERVERS = ['BROKER-HOST']
def setup_logging():
logging.config.dictConfig({
'version': 1,
@akheron
akheron / kafka-python.log
Created March 10, 2016 12:48
kafka-python heartbeat issue
[2016-03-10 14:34:50,186] DEBUG base 14747 139872076707584 Received successful heartbeat
[2016-03-10 14:34:50,186] DEBUG fetcher 14747 139872076707584 Adding fetch request for partition TopicPartition(topic='TOPIC-NAME', partition=0) at offset 143454
[2016-03-10 14:34:50,186] DEBUG fetcher 14747 139872076707584 Sending FetchRequest to node 1
[2016-03-10 14:34:50,187] DEBUG conn 14747 139872076707584 <BrokerConnection host=SERVER-HOSTNAME port=9092> Request 975: FetchRequest(replica_id=-1, max_wait_time=500, min_bytes=1, topics=[(topic='TOPIC-NAME', partitions=[(partition=0, offset=143454, max_bytes=1048576)])])
[2016-03-10 14:34:50,683] DEBUG consumer 14747 139872076707584 Sending offset-commit request with {TopicPartition(topic='TOPIC-NAME', partition=0): OffsetAndMetadata(offset=143454, metadata='')} to 1
[2016-03-10 14:34:50,684] DEBUG conn 14747 139872076707584 <BrokerConnection host=SERVER-HOSTNAME port=9092> Request 976: OffsetCommitRequest_v2(consumer_group='GROUP-NAME', consumer_grou
@akheron
akheron / generate-alter-tables.sql
Last active September 8, 2015 12:33
Change foreign key constraints to point to a different table
-- PostgreSQL
SELECT
'ALTER TABLE ' || source_tbl.relname || ' ' ||
'DROP CONSTRAINT '|| constr.conname ||'; ' ||
'ALTER TABLE ' || source_tbl.relname || ' ' ||
'ADD CONSTRAINT ' || constr.conname || ' ' ||
'FOREIGN KEY (' || source_col.attname || ') ' ||
'REFERENCES new_table_name (primary_key_name);'
FROM pg_constraint constr
INNER JOIN pg_class target_tbl ON constr.confrelid = target_tbl.oid
@akheron
akheron / .gitconfig
Last active December 29, 2019 06:48
My dotfiles: .gitconfig, .mailcap, .screenrc, .toprc, .tmux.conf
[alias]
st = status --short --branch
dc = diff --cached -M -B -C
typo = commit --amend
fixup = commit --amend --no-edit
logk = log --graph --pretty=\"format:%C(yellow)%h%C(red)%d%Creset %s %C(green)%an, %ar%Creset\"
ffpull = pull --ff-only
ffmerge = merge --ff-only
ri = "!f() { rev=$(git rev-parse $1 2>/dev/null) || rev=HEAD~$1; git rebase -i $rev; }; f"
rc = rebase --continue
@akheron
akheron / .tmux.conf
Last active August 29, 2015 14:20
My tmux config
# Keybindings
unbind C-b
set -g prefix C-z
bind z send-prefix
bind escape copy-mode
bind C-z last-window
bind p select-pane -t :.-1
bind n select-pane -t :.+1
@akheron
akheron / activate-venv.sh
Last active September 19, 2015 04:40
Automatically activate Git projects' virtual environments
# Automatically activate Git projects' virtual environments based on the
# directory name of the project. Virtual environment name can be overridden
# by placing a .venv file in the project root with a virtualenv name in it
function workon_cwd {
# Check that this is a Git repo
GIT_DIR=`git rev-parse --git-dir 2> /dev/null`
if [ $? == 0 ]; then
# Find the repo root and check for virtualenv name override
GIT_DIR=`\cd $GIT_DIR; pwd`
PROJECT_ROOT=`dirname "$GIT_DIR"`