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 / 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
devilholk / pwm_test.py
Created May 24, 2020
Demonstration of concept of per pixel PWM in LED array
View pwm_test.py
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 Dec 14, 2019
Scheme interface for worms armageddon
View scheme_interface.py
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 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
devilholk / odt_read.py
Created Dec 1, 2019
Read Open Document Table and put in a list of named tuples
View odt_read.py
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 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_SPREAD (HUE_RANGE / NUMBER_LEDS)
#define HUE_SPEED 3
@devilholk
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/
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 Nov 12, 2019
Pulseaudio volume balance monitor
View pa-volumes-2.py
#!/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
@devilholk
devilholk / pa-volumes-1.py
Last active Nov 12, 2019
Get volumes from pulseaudio using pactl
View pa-volumes-1.py
#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
devilholk / rename_stuff.py
Created Oct 12, 2019
Renames spaces to underscore in current working directory
View rename_stuff.py
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.