Skip to content

Instantly share code, notes, and snippets.

View Dockerfile
FROM python:3.7
RUN mkdir /app
COPY . /app
RUN apt-get update && \
apt-get install -y netcat && \
pip install Tornado
@davidblewett
davidblewett / expiring_counter.py
Last active Feb 28, 2020
Expiring Counter Implementation
View expiring_counter.py
import warnings
from collections import (
Counter, MutableMapping, OrderedDict, deque,
)
from datetime import timedelta
from tornado import gen
from tornado.ioloop import IOLoop, PeriodicCallback
class ExpiringCounter(MutableMapping):
@davidblewett
davidblewett / find_mpeg2.sh
Created Mar 13, 2015
Find all mpeg2 MKV files in my archive on my NAS, copy to local disk, transcode to h264.
View find_mpeg2.sh
for i in *.mkv; do
ffprobe -loglevel quiet -show_format -show_streams -select_streams v -print_format flat=h=0 "$i" | egrep 'codec_name="mpeg2video"|filename' | cut -d '"' -f 2 | tr '\n' '|'
echo
done | grep mpeg2video | cut -d '|' -f 2 > ~/mpeg2movies.txt
rsync -Pav --size-only --files-from=:/home/davidb/mpeg2movies.txt udun:/data/movies /Volumes/element/incoming
@davidblewett
davidblewett / lp-ssh-add.sh
Last active May 2, 2021
Allow storage of SSH private keys in LastPass, and use lpass CLI to retrieve and load into ssh-agent. The general idea is to store the private key armored ASCII in an "SSH Key" Secure Note, in a specific folder (i.e.: "Secure Notes\SSH" ).
View lp-ssh-add.sh
#!/bin/sh
#
# Import all SSH keys from LP
#
PREFIX=~
SSH_ASKPASS=$PREFIX/bin/lp-askpass.sh
export SSH_ASKPASS
# This is needed to force ssh-add to honor our SSH_ASKPASS.
DISPLAY=foo
export DISPLAY
View test_deque_pipeline.py
from collections import deque
import time
from statsd import defaults
from statsd.client import StatsClient
class DequePipeline(StatsClient):
def __init__(self, client):
self._client = client
View gist:072469030daef7778883
wget https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
--2014-06-25 19:04:08-- https://github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
Resolving github.com (github.com)... 192.30.252.129
Connecting to github.com (github.com)|192.30.252.129|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz [following]
--2014-06-25 19:04:09-- https://cloud.github.com/downloads/libevent/libevent/libevent-2.0.21-stable.tar.gz
Resolving cloud.github.com (cloud.github.com)... 205.251.215.213, 54.230.141.84, 54.230.141.185, ...
Connecting to cloud.github.com (cloud.github.com)|205.251.215.213|:443... connected.
OpenSSL: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure
View keybase.md

Keybase proof

I hereby claim:

  • I am davidblewett on github.
  • I am davidblewett (https://keybase.io/davidblewett) on keybase.
  • I have a public key whose fingerprint is ED14 1F64 7518 707E 2F44 63F7 6BF6 EFA4 3358 C9F8

To claim this, I am signing this object:

View postgresql.conf
# The following are suggested values
# They should be set in all configs,
# so that if a secondary needs to be promoted
# it will be generating the correct WAL level
wal_level = hot_standby
archive_mode = on # allows archiving to be done
# (change requires restart)
archive_command = 'cp -f %p /data/pgsql/archive/%f </dev/null' # command to use to archive a logfile segment
max_wal_senders = 5 # max number of walsender processes
# (change requires restart)
@davidblewett
davidblewett / gist:7340385
Created Nov 6, 2013
Example using streaming FLAC
View gist:7340385
from coxswain.flac import StreamingFlacAudio
from audiotools.player import Player
from audiotools.player import available_outputs
player = Player([i for i in available_outputs()][0])
flac = StreamingFlacAudio('http://path/to/my.flac')
player.open(flac)
player.play()
@davidblewett
davidblewett / gist:7340369
Created Nov 6, 2013
Simple HTTP FLAC streamer
View gist:7340369
from hashlib import md5
from audiotools.bitstream import BitstreamReader
from audiotools.flac import FlacAudio
from audiotools.flac import InvalidFLAC
from audiotools.id3 import skip_id3v2_comment
from audiotools.py_decoders import FlacDecoder
from audiotools.text import ERR_FLAC_INVALID_BLOCK
import requests