Skip to content

Instantly share code, notes, and snippets.

rwarren

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
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
@rwarren
rwarren / tc_remaster.sh
Last active Dec 18, 2015
handy tinycore remastering script from coreplayer2 (see http://goo.gl/c6uQh). Takes the tedium out of it.
View tc_remaster.sh
#!/bin/sh
. /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.