Skip to content

Instantly share code, notes, and snippets.

@devilholk
devilholk / re_h_mod.py
Created July 6, 2020 01:59
Duckpunching python re module to add a horizontal whitespace pattern as \h
import sre_parse
h_rep, = sre_parse.parse(r'[^\S\n\v\f\r\u2028\u2029]')
def sre_parse_escape(source, escape, state):
if escape == r'\h':
return h_rep
else:
return original_sre_parse_escape(source, escape, state)
@devilholk
devilholk / test_re_h_mod.py
Created July 6, 2020 01:57
Showcase of re_h_mod
import re, re_h_mod
p1=re.compile(r'test\s+stuff')
p2=re.compile(r'test\h+stuff')
print('p1', p1)
print('\t', p1.match('test \t stuff'))
print('\t', p1.match('test \n stuff'))
print()
print('p2', p2)
print('\t', p2.match('test \t stuff'))
@devilholk
devilholk / failed_using_dwarf-1.c
Created May 26, 2020 00:32
An incomplete attempt at enumerating DW_TAG_variable from DWARF data in ELF using libdw.
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <elfutils/libdwelf.h>
#include <dwarf.h>
/*
Bottom part of `objdump -Wi t3.o´ is:
@devilholk
devilholk / pwm_test.py
Created May 24, 2020 22:43
Demonstration of concept of per pixel PWM in LED array
import local_5strip, time, math, random, colorsys
lamp = local_5strip.LocalLamp(local_5strip.lamp, '/dev/ttyUSB0', 921600, auto_connect=True)
sub_frames = 7 #Because ... why not? =D
sub_frame_frequency = 2000
#This is our internal buffer for the values for each lantern (5 lanterns, r, g, b per lantern)
lanterns = [[0, 0, 0] for l in range(5)]
@devilholk
devilholk / scheme_interface.py
Created December 14, 2019 08:49
Scheme interface for worms armageddon
import ctypes, collections, struct
weapon_info = collections.namedtuple('weapon_info', 'id name comment')
class table_index:
def __init__(self, index):
self.name = None
self.index = index
def __set_name__(self, target, name):
@devilholk
devilholk / sine.c
Created December 2, 2019 17:07
Integer sine approximation
#include <stdint.h>
#define table_length_bits 5
//full_table_index_type have to be at least table_length_bits + 2
#define full_table_index_type uint_least8_t
//table_index_type have to be at least table_length_bits
#define table_index_type uint_least8_t
#define storage_bits 15
//Output will be +/- storage_bits so 15 bits storage will be 16 bit output
@devilholk
devilholk / odt_read.py
Created December 1, 2019 14:29
Read Open Document Table and put in a list of named tuples
import xml.etree.ElementTree, re, zipfile, collections
def get_ns(tag):
ns = re.findall(r'\{(.*)\}(.*)', tag)[0] #Assume only one
return ns
def one_or_default(it, default=None):
try:
result = it.__next__()
@devilholk
devilholk / apdrivare_main.c
Created November 26, 2019 19:08
Simple test application for LED driving
#define BIT_0 6
#define BIT_1 14
#define FREQ 800000
#define NUMBER_LEDS 6
#define HUE_RANGE 0x6000U
#define HUE_SPREAD (HUE_RANGE / NUMBER_LEDS)
#define HUE_SPEED 3
@devilholk
devilholk / apdrivare_makefile
Created November 26, 2019 19:08
Makefile for a simple test of LED driving
#Project settings
PROJECT_NAME = led_böp
SOURCES = main.c
BUILD_DIR = build/
OBJECTS = $(SOURCES:%.c=$(BUILD_DIR)%.o)
MACRO_DEFS = $(SOURCES:%.c=$(BUILD_DIR)%.macro_defs)
TARGET_ELF = $(BUILD_DIR)$(PROJECT_NAME).elf
TARGET_BIN = $(TARGET_ELF:%.elf=%.bin)
@devilholk
devilholk / pa-volumes-2.py
Last active November 12, 2019 17:14
Pulseaudio volume balance monitor
#!/usr/bin/env python3
#encoding=utf-8
import subprocess, os, sys, re, signal, threading, gi
from collections import defaultdict
gi.require_version('Notify', '0.7')
from gi.repository import Notify
Notify.init("Pulseaudio volume balance monitor")
#Volumes