Skip to content

Instantly share code, notes, and snippets.

@akheron
akheron / PG.js
Created Nov 5, 2018
purescript-postgresql-client library monad
View PG.js
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 Jul 30, 2017
elm-make benchmark
View benchmark.md

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
i3 workspace/output helpers
View get-workspaces.sh
#!/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 Jan 24, 2021
SMTP server pytest fixture
View smtpd_fixture.py
# 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
#
View test-kafka-consumer.py
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 Mar 10, 2016
kafka-python heartbeat issue
View kafka-python.log
[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 Sep 8, 2015
Change foreign key constraints to point to a different table
View generate-alter-tables.sql
-- 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 Dec 29, 2019
My dotfiles: .gitconfig, .mailcap, .screenrc, .toprc, .tmux.conf
View .gitconfig
[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 Aug 29, 2015
My tmux config
View .tmux.conf
# 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 Sep 19, 2015
Automatically activate Git projects' virtual environments
View activate-venv.sh
# 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"`