Skip to content

Instantly share code, notes, and snippets.

@devilholk
devilholk / rename_stuff.py
Created October 12, 2019 22:43
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:
@devilholk
devilholk / pa-volumes-1.py
Last active November 12, 2019 16:04
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
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
@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 / 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 / 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 / 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 / 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 / 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 / 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: