Skip to content

Instantly share code, notes, and snippets.

View JonathonReinhart's full-sized avatar

Jonathon Reinhart JonathonReinhart

View GitHub Profile
@JonathonReinhart
JonathonReinhart / compatrand.py
Last active September 1, 2020 00:46
Python 2.7, 3 compatible random seeding
from __future__ import print_function
import random
import sys
class CompatibleRandom(random.Random):
# Inspired by https://stackoverflow.com/a/55800424/119527
def seed(self, a):
if sys.version_info >= (3, 2):
super(CompatibleRandom, self).seed(a, version=1)
else:
@JonathonReinhart
JonathonReinhart / ve.sh
Created August 18, 2020 01:07
Bash function for easy virtualenv activation
# Put this in your .bashrc or .bash_aliases
# List virtual envs
function list-virtualenvs() {
for d in *; do
if [[ -d "${d}" && -f "${d}/bin/activate" ]]; then
echo "${d}"
fi
done
}
@JonathonReinhart
JonathonReinhart / check_gofmt.sh
Last active April 17, 2020 21:25
Run gofmt in CI
#!/bin/bash
PATHS='*.go internal'
# Run from project root
cd "$(dirname "${BASH_SOURCE[0]}")"
output="$(gofmt -l $PATHS)"
if [ ! -z "$output" ]; then
echo -e "The following files are not properly formatted:\n"
@JonathonReinhart
JonathonReinhart / human_size.py
Created March 29, 2019 01:52
Python human file size
#!/usr/bin/env/python3
import math
def round_down(n, d=8):
# https://stackoverflow.com/a/43533589/119527
d = 10 ** d
return math.floor(n * d) / d
def human_size(n, decimal_places=2):
n = float(n)
@JonathonReinhart
JonathonReinhart / ctypes_struct_array.py
Last active March 30, 2018 02:24
Populating an array member of a ctypes structure
#!/usr/bin/env python3
import sys
from ctypes import *
assert sys.version_info >= (3,5)
class Struct(LittleEndianStructure):
_fields_ = [
('a', c_uint32),
('b', c_uint32),
@JonathonReinhart
JonathonReinhart / Program.cs
Created February 18, 2018 23:12
Gotta catch 'em all: Last-chance exception handling in .NET with WinForms
using System;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using WinformsExceptions;
static class Program
{
/// <summary>
@JonathonReinhart
JonathonReinhart / pipe_client.py
Last active August 8, 2024 12:27
Named Pipes between C# and Python
import time
import struct
f = open(r'\\.\pipe\NPtest', 'r+b', 0)
i = 1
while True:
s = 'Message[{0}]'.format(i).encode('ascii')
i += 1
@JonathonReinhart
JonathonReinhart / rename-svn-repo.sh
Created February 18, 2018 22:38
Rename SVN repository
#!/bin/bash
if [[ $# -lt 2 ]]; then
echo "Usage: `basename $0` oldrepo newrepo"
exit 1
fi
# http://stackoverflow.com/q/1848415/
OLDREPO=${1%/}
NEWREPO=$2
@JonathonReinhart
JonathonReinhart / ctypes_structs_example.py
Last active November 4, 2022 13:39
Using Python ctypes to manipulate binary data
#!/usr/bin/env python3
from __future__ import print_function
from tempfile import TemporaryFile
from binascii import hexlify
from ctypes import *
class StructHelper(object):
def __get_value_str(self, name, fmt='{}'):
val = getattr(self, name)
@JonathonReinhart
JonathonReinhart / 20171128_radeon_lockup.txt
Created November 29, 2017 03:06
Radeon driver lockup
Nov 28 21:24:06.432882 kernel: radeon 0000:01:00.0: ring 0 stalled for more than 10092msec
Nov 28 21:24:06.441917 kernel: radeon 0000:01:00.0: GPU lockup (current fence id 0x0000000001ff9744 last fence id 0x0000000001ff9755 on ring 0)
Nov 28 21:24:06.455092 kernel: radeon 0000:01:00.0: ring 4 stalled for more than 10104msec
Nov 28 21:24:06.455374 kernel: radeon 0000:01:00.0: GPU lockup (current fence id 0x000000000100a400 last fence id 0x000000000100a401 on ring 4)
Nov 28 21:24:06.655161 kernel: radeon 0000:01:00.0: ring 3 stalled for more than 10080msec
Nov 28 21:24:06.655451 kernel: radeon 0000:01:00.0: GPU lockup (current fence id 0x0000000000d334fd last fence id 0x0000000000d3350e on ring 3)
Nov 28 21:24:06.935108 kernel: radeon 0000:01:00.0: ring 0 stalled for more than 10596msec
Nov 28 21:24:06.935390 kernel: radeon 0000:01:00.0: GPU lockup (current fence id 0x0000000001ff9744 last fence id 0x0000000001ff9755 on ring 0)
Nov 28 21:24:06.959090 kernel: radeon 0000:01:00.0: ring 4 stalled for more than 106