Skip to content

Instantly share code, notes, and snippets.


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 / failed_using_dwarf-1.c
Created May 26, 2020
An incomplete attempt at enumerating DW_TAG_variable from DWARF data in ELF using libdw.
View failed_using_dwarf-1.c
#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 /
Created May 24, 2020
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 /
Created Dec 14, 2019
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): = None
self.index = index
def __set_name__(self, target, name):
devilholk / sine.c
Created Dec 2, 2019
Integer sine approximation
View sine.c
#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 /
Created Dec 1, 2019
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):
result = it.__next__()
devilholk / apdrivare_main.c
Created Nov 26, 2019
Simple test application for LED driving
View apdrivare_main.c
#define BIT_0 6
#define BIT_1 14
#define FREQ 800000
#define NUMBER_LEDS 6
#define HUE_RANGE 0x6000U
#define HUE_SPEED 3
devilholk / apdrivare_makefile
Created Nov 26, 2019
Makefile for a simple test of LED driving
View apdrivare_makefile
#Project settings
PROJECT_NAME = led_böp
SOURCES = main.c
BUILD_DIR = build/
MACRO_DEFS = $(SOURCES:%.c=$(BUILD_DIR)%.macro_defs)
TARGET_BIN = $(TARGET_ELF:%.elf=%.bin)
devilholk /
Last active Nov 12, 2019
Pulseaudio volume balance monitor
#!/usr/bin/env python3
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")
devilholk /
Last active Nov 12, 2019
Get volumes from pulseaudio using pactl
#Requires python 3.6 or up (tested on 3.7.4
import subprocess, os, sys, re
from collections import defaultdict
volume_pattern = re.compile(r'^\s*volume:\s+(.*)', re.I)
sink_id_pattern = re.compile(r'^\s*sink\s+#(.*)', re.I)
description_pattern = re.compile(r'^\s*description:\s+(.*)', re.I)
volume_entry_pattern = re.compile(r'(^|\s+)(?P<name>.*?):\s+(?P<volume_raw>.*?)\s*/\s*(?P<volume_percent>.*?)\%\s*/\s*(?P<volume_db>.*?)\s+db', re.I)
def run_command(*cmd):
devilholk /
Created Oct 12, 2019
Renames spaces to underscore in current working directory
import os, argparse
parser = argparse.ArgumentParser()
parser.add_argument("--dry-run", help="Just say what we would do", action="store_true")
settings = parser.parse_args()
for filename in os.listdir(os.getcwd()):
if ' ' in filename:
new_filename = filename.replace(' ', '_')
if settings.dry_run:
You can’t perform that action at this time.