Skip to content

Instantly share code, notes, and snippets.

View JonathonReinhart's full-sized avatar

Jonathon Reinhart JonathonReinhart

View GitHub Profile
@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 May 23, 2023 23:44
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
@JonathonReinhart
JonathonReinhart / search.c
Created March 14, 2017 20:13
Places "goto" can improve C code
void *search_without_goto(const char *key)
{
int i;
void *result;
for (i = 0; i < some_length; i++) {
if (strcmp(some_collection[i].key, key) == 0)
break;
}
if (i == some_length)
@JonathonReinhart
JonathonReinhart / pystartup.py
Created February 18, 2017 18:17
Default hex output in Python interactive console
# Display integers as hex and decimal
import sys
def displayhook(item):
if isinstance(item, int) and not isinstance(item, bool):
print '0x{0:X} ({0})'.format(item)
elif isinstance(item, long):
print '0x{0:X}L ({0}L)'.format(item)
elif item is not None:
print repr(item)
sys.displayhook = displayhook