Skip to content

Instantly share code, notes, and snippets.


Block or report user

Report or block rwarren

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
rwarren /
Created May 4, 2019
shell function to robustly get the IP address of the currently connected ssh client (through subshells, user changes, and more)
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
rwarren /
Created Oct 10, 2018
fiddling with subprocess piping
import time
import sys
DELAY = 0.2
for i in range(10):
rwarren /
Last active Nov 9, 2017
demo of objectName() not working with QML (for me?)
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 /
Created Oct 18, 2016
Basic thread pool example whipped up quickly for #python discussion. Don't judge me.
import threading
import Queue
import time
WORKER_COUNT = 200 # play with this! If switching to multiprocessing, use ncores+1 (or 2)
NUM_TASKS = 1000
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 / 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
# Check up the path (using bash string operators) looking for .hg
while [ "${d}" != "" ]; do
if [ -d "${d}/.hg" ]; then
return 0
rwarren / sys_displayhook
Created Mar 7, 2014
python displayhook for pprint by default
View sys_displayhook
#lifted from
import pprint
import sys
orig_displayhook = sys.displayhook
def myhook(value):
if value != None:
__builtins__._ = value
rwarren /
Last active Dec 18, 2015
handy tinycore remastering script from coreplayer2 (see Takes the tedium out of it.
. /etc/init.d/tc-functions
# Use this script to extract and re-package core.gz, core64.gz or corepure64.gz
# Note
# When repackaging a x86_64 core, use this script on same type system (core64 or corepure64)
# How to..
You can’t perform that action at this time.