Skip to content

Instantly share code, notes, and snippets.

@rwarren
rwarren / tc_remaster.sh
Last active December 18, 2015 19:49
handy tinycore remastering script from coreplayer2 (see http://goo.gl/c6uQh). Takes the tedium out of it.
#!/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..
@rwarren
rwarren / sys_displayhook
Created March 7, 2014 20:54
python displayhook for pprint by default
#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 / gist:e8005fe380e529ce297d
Created February 18, 2016 20:38
Mercurial .bashrc mod for prompt showing bookmark/rev and incoming state
# 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
Loading
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 October 18, 2016 16:21
Basic thread pool example whipped up quickly for #python discussion. Don't judge me.
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()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@rwarren
rwarren / qml_objectName_test.py
Last active November 9, 2017 02:52
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 {
@rwarren
rwarren / dumper.py
Created October 10, 2018 21:25
fiddling with subprocess piping
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 / get_ssh_client_ip.sh
Created May 4, 2019 05:48
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
done
@rwarren
rwarren / get_buffer_bench.py
Created March 23, 2020 13:56 — forked from 1st1/get_buffer_bench.py
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())