Skip to content

Instantly share code, notes, and snippets.

@rwarren
rwarren / pgcon2020_irc_announce,py
Last active May 28, 2020
Massive hack to automate talk announcements for pgcon 2020. There is DEFINITELY a better way to do this.
View pgcon2020_irc_announce,py
#!/usr/bin/env python
# THIS FILE IS A MAAAAAAAAAAAASSIVE HACK QUICKLY MADE FOR THE ONLINE PGCON_2020
# There is DEFINITELY a better way to do this.
import argparse
import datetime
import sched
import socket
import sys
import time
@rwarren
rwarren / get_buffer_bench.py
Created Mar 23, 2020 — forked from 1st1/get_buffer_bench.py
get_buffer_bench.py
View get_buffer_bench.py
import struct
try:
from time import perf_counter as clock
except ImportError:
from time import time as clock
import asyncio
import uvloop
asyncio.set_event_loop_policy(uvloop.EventLoopPolicy())
@rwarren
rwarren / get_ssh_client_ip.sh
Created May 4, 2019
shell function to robustly get the IP address of the currently connected ssh client (through subshells, user changes, and more)
View get_ssh_client_ip.sh
get_ssh_client_ip() {
# Returns (via stdout) the IP address for the currently connected SSH session
# - this relies on the ssh server setting the SSH_CLIENT env var (done by openssh, dropbear, etc)
pid=$$ # current pid will be checked
while [ "$pid" -ne 1 ]; do
cip=$(cat /proc/$pid/environ | tr '\0' '\n' | grep 'SSH_CLIENT=' | awk -F'[= ]' '{ print $2 }')
[ -n "$cip" ] && break # got it!
pid=$(awk '{ print $4 }' /proc/$pid/stat) # the parent pid for the next try
done
@rwarren
rwarren / dumper.py
Created Oct 10, 2018
fiddling with subprocess piping
View dumper.py
import time
import sys
DELAY = 0.2
for i in range(10):
sys.stdout.write("1")
time.sleep(DELAY)
sys.stdout.write("\r\n")
@rwarren
rwarren / qml_objectName_test.py
Last active Nov 9, 2017
demo of objectName() not working with QML (for me?)
View qml_objectName_test.py
import sys
from PyQt5 import QtCore, QtQml, QtWidgets
QML = b'''
import QtQuick 2.7
import QtQuick.Window 2.2
import QtQuick.Controls 1.4
import ObjectNameTester 1.0
Window {
View cubehelix_problem.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rwarren
rwarren / hacky_thread_pool.py
Created Oct 18, 2016
Basic thread pool example whipped up quickly for #python discussion. Don't judge me.
View hacky_thread_pool.py
import threading
import Queue
import time
QUEUE_TIMEOUT_s = 0.1
WORKER_COUNT = 200 # play with this! If switching to multiprocessing, use ncores+1 (or 2)
NUM_TASKS = 1000
SLOW_ADD_TIME_s = 0.1
done_event = threading.Event()
View resample_fun.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rwarren
rwarren / gist:e8005fe380e529ce297d
Created Feb 18, 2016
Mercurial .bashrc mod for prompt showing bookmark/rev and incoming state
View gist:e8005fe380e529ce297d
# add hg info to the prompt if it exists...
in_hg() {
# returns 0 if in a hg repo, 1 if not
d=$PWD
# Check up the path (using bash string operators) looking for .hg
while [ "${d}" != "" ]; do
if [ -d "${d}/.hg" ]; then
HG_DIR=$d/.hg
return 0
fi
@rwarren
rwarren / sys_displayhook
Created Mar 7, 2014
python displayhook for pprint by default
View sys_displayhook
#lifted from http://stackoverflow.com/questions/17248383/pretty-print-by-default-in-python-repl
import pprint
import sys
orig_displayhook = sys.displayhook
def myhook(value):
if value != None:
__builtins__._ = value
You can’t perform that action at this time.