Skip to content

Instantly share code, notes, and snippets.

devilholk

Block or report user

Report or block devilholk

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
@devilholk
devilholk / recursion_limiter.py
Last active Jul 3, 2019
Limit recursion with a context handler
View recursion_limiter.py
import sys, collections
class max_stack_level:
active = collections.Counter()
def __init__(self, max):
self.max = max
def __enter__(self):
frame = sys._getframe(1)
@devilholk
devilholk / our_png_save.py
Created Jun 1, 2019
Our modified PNG saver that allows custom size palette
View our_png_save.py
import PIL.PngImagePlugin
#Import all the things unless they start with two underscores. "from stuff import *" will not import things beginning with one underscore
#And we need things like _MAGIC etc
locals().update({k: v for k, v in PIL.PngImagePlugin.__dict__.items() if not k.startswith('__')})
#This function is taken from PIL.PngImagePlugin with a small change that is noted below
#In the bottom we register this modified function to be the PNG save function -devilholk
def overidden_save(im, fp, filename, chunk=putchunk):
# save an image to disk (called by the save method)
@devilholk
devilholk / test_our_png_writer.py
Created Jun 1, 2019
Testing custom PNG writer for PIL that allows non 256 size palettes
View test_our_png_writer.py
import PIL.Image, our_png_save
im = PIL.Image.new('RGB', (256, 256))
p = im.load()
for y in range(256):
for x in range(256):
p[x,y] = (x, y, (x * y) >> 8)
colors = set()
for y in range(256):
@devilholk
devilholk / slotted_pole_slider.scad
Created Nov 26, 2018
For connecting a flat piece to a slider that slides along a pole
View slotted_pole_slider.scad
/*
___ _ _ _ _ ___ _ ___ _ _ _
/ __| |___| |_| |_ ___ __| | | _ \___| |___ / __| (_)__| |___ _ _
\__ \ / _ \ _| _/ -_) _` | | _/ _ \ / -_) \__ \ | / _` / -_) '_|
|___/_\___/\__|\__\___\__,_| |_| \___/_\___| |___/_|_\__,_\___|_|
by: Mikael Lövqvist @ LED Alert Hackerspace
.-----. outer diameter: 2 × pole_shroud_thickness + pole_diameter
View bz2xml_processing_output.txt
Processed events 34.68 K @ 69.26 K/s.
Processed events 52.52 K @ 31.35 K/s.
Processed events 64.64 K @ 23.5 K/s.
Processed events 83.74 K @ 38.16 K/s.
Deflated processed 7.0 MiB @ 3.01 MiB/s.
Inflated processed 30.04 MiB @ 12.9 MiB/s.
Processed events 107.22 K @ 43.06 K/s.
Processed events 151.13 K @ 87.78 K/s.
Processed events 176.55 K @ 50.83 K/s.
Processed events 202.01 K @ 50.93 K/s.
@devilholk
devilholk / bz2xml_processing.py
Last active Jun 9, 2018
Incremental processing of bz2-compressed XML files
View bz2xml_processing.py
import bz2, time, functools, xml.etree.ElementTree
#serial reading of XML inspired by http://boscoh.com/programming/reading-xml-serially.html
#note that you can do elem.clear for every element
def format_amount(amount, precision=2, unit='B', base=1024, unit_prefix='i'):
if amount < base ** 1:
return f'{amount}{unit}'
elif amount < base ** 2:
return f'{round(amount/(base**1), precision)} K{unit_prefix}{unit}'
@devilholk
devilholk / play_with_ft.py
Created Sep 2, 2017
Using python and numpy to filter a pulse audio stream
View play_with_ft.py
import numpy, subprocess, struct, sys
#pacmd load-module module-null-sink sink_name=Python_input
#pacmd update-sink-proplist Python_input device.description="Python sound processing input"
#Note - seems we can't have spaces in description so replace with _ or something for now
# - it might be a bash thing so it might work from subprocess.call, have not tested
#figure out what monitor-stream this is and put it down there where we pamon
#also remember to redirect the source application to this sink (for instance pavucontrol)
@devilholk
devilholk / freecam.py
Created May 27, 2017
Simple free fly camera (libglfw, libGL, python3)
View freecam.py
from lowlevel_gl import *
# Test
#Kom ihåg error check för push/pop matrix
import threading
assert glfwInit() == 1
w = glfwCreateWindow(640, 480, b"Hello World!", None, None)
assert w, 'Failed to create window'
@devilholk
devilholk / test1.py
Created May 27, 2017
Outline for graphic quick replacement tool
View test1.py
from PyQt5.QtGui import QTextOption, QFont
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication, QTableView, QTableWidget, QTableWidgetItem, QMainWindow, QGridLayout, QWidget, QPlainTextEdit
import re
monospace = QFont('DejaVu Sans Mono')
monospace.setStyleHint(QFont.Monospace)
print(monospace)
@devilholk
devilholk / sound_test.py
Created May 23, 2017
Testing pulse audio using ctypes
View sound_test.py
#Run this with python3 interactively like
#python3 -i sound_test.py
#In the python interactive console you can play with
#env, wave and rb to adjust envelope, waveform and reverb settings
import ctypes, sys, math, threading
PA = ctypes.CDLL('libpulse-simple.so')
You can’t perform that action at this time.