Skip to content

Instantly share code, notes, and snippets.

View Mikael-Lovqvist's full-sized avatar

Mikael Lövqvist Mikael-Lovqvist

View GitHub Profile
@Mikael-Lovqvist
Mikael-Lovqvist / identity_tracking_demo.py
Last active September 15, 2021 20:07
2021-09-15 Video Log - identity tracking in Python
#This is a demo for VLOG entry https://youtu.be/LfRFxkombTw "Python - track object identities [short]"
greek_alphabet = ['Άλφα', 'Βήτα', 'Γάμμα', 'Δέλτα', 'Έψιλον', 'Ζήτα', 'Ήτα', 'Θήτα', 'Ιώτα', 'Κάππα', 'Λάμβδα', 'Μυ', 'Νυ', 'Ξι', 'Όμικρον', 'Πι', 'Ρώ', 'Σίγμα', 'Ταυ', 'Ύψιλον', 'Φι', 'Χι', 'Ψι', 'Ωμέγα']
class identity_reference:
def __init__(self, target):
self.target = target
self.id = id(target)
try:
@Mikael-Lovqvist
Mikael-Lovqvist / trace_task.py
Last active October 7, 2021 22:57
Python script for gdb, uses procfs to monitor task state then stores timestamp and backtrace to file
import pathlib, re, time
line_pattern = re.compile(r'(.*?):\s+(.*)')
'''
Example usage, note that MODULE is this file and is in the directory you run gdb from
Note that gdb needs root privs
# gdb /bin/subl3 -p $(pidof subl3)
@Mikael-Lovqvist
Mikael-Lovqvist / clamscan.py
Last active January 7, 2022 18:20
Helper script to utilize multiple processes when scanning. Will divy up files, starting with the biggest ones to give an even workload.
import argparse, multiprocessing, subprocess, pathlib, tempfile
scanner_tool = ('clamscan', '--no-summary', '--quiet')
log_arg = '-l'
log_prefix = 'log-'
file_list_arg = '-f' #Set this to something false-like in order to use file lists as command line arguments instead
file_list_name = 'file-list' #Must not be matching log_prefix
process_count = multiprocessing.cpu_count()
def process_file_list(files):
@Mikael-Lovqvist
Mikael-Lovqvist / PKGBUILD
Created February 10, 2022 03:05
openocd patch for building from upstream git repos
# Maintainer: Filipe Laíns (FFY00) <lains@archlinux.org>
# Contributor: Sergej Pupykin <arch+pub@sergej.pp.ru>
# Contributor: Bartłomiej Piotrowski <bpiotrowski@archlinux.org>
# Contributor: Matthias Bauch <matthias.bauch@gmail.com>
# Contributor: Laszlo Papp <djszapi2 at gmail com>
# Contributor: Samuel Tardieu <sam@rfc1149.net>
_features=(amtjtagaccel armjtagew buspirate ftdi gw16012 jlink oocd_trace opendous osbdm
parport presto_libftdi remote-bitbang rlink stlink ti-icdi ulink usbprog vsllink
aice cmsis-dap dummy jtag_vpi openjtag_ftdi usb-blaster-2 usb_blaster_libftdi)
@Mikael-Lovqvist
Mikael-Lovqvist / PKGBUILD
Last active March 11, 2022 05:49
PKGBUILD for my fork of zimwiki
_pkgname=zim
pkgname=${_pkgname}-git
pkgver=0.74.3.r41.f4c98c2c
pkgrel=1
pkgdesc="A WYSIWYG text editor that aims at bringing the concept of a wiki to the desktop. Mikael Lövqvist's Git Version"
arch=(any)
license=('GPL' 'PerlArtistic')
url="http://zim-wiki.org/"
depends=('python')
conflicts=('zim')
@Mikael-Lovqvist
Mikael-Lovqvist / conditional_with.py
Created May 12, 2022 23:24
Defying the rejection of PEP 377
import sys
def dummy_trace(frame, event, *args):
pass
class CancelExecutionException(Exception):
pass
class alternative_execution:
@Mikael-Lovqvist
Mikael-Lovqvist / dict_filter.py
Created June 1, 2022 08:59
A simple class for filtering mappings
class dict_filter:
def __init__(self, key=None, value=None, key_condition=None, value_condition=None):
self.key = key
self.value = value
self.key_condition = key_condition
self.value_condition = value_condition
def __call__(self, source):
K, V, KC, VC = self.key, self.value, self.key_condition, self.value_condition
@Mikael-Lovqvist
Mikael-Lovqvist / mount_qcow2.md
Created August 27, 2022 20:00 — forked from shamil/mount_qcow2.md
How to mount a qcow2 disk image

How to mount a qcow2 disk image

This is a quick guide to mounting a qcow2 disk images on your host server. This is useful to reset passwords, edit files, or recover something without the virtual machine running.

Step 1 - Enable NBD on the Host

modprobe nbd max_part=8
@Mikael-Lovqvist
Mikael-Lovqvist / mvln.sh
Last active September 23, 2022 02:15
Move files to a target location and then symlink them back. If there is a lot of files and expansion would be too long for the command line you can use single quotes such as: mvln '*.json' /path/to/target
#!/bin/bash
#The file system may of course change during these operations but at least the stage test is likely to prevent a half run but not guaranteed
#Out of laziness we may not add flags here and instead make a python script for more advanced use
# https://stackoverflow.com/a/33271194/19961748
target=${@:$#}
files=${*%${!#}}
function stage_file {
@Mikael-Lovqvist
Mikael-Lovqvist / secret_santa.py
Created December 14, 2022 16:30
Secret Santa matching script
import random
participants = '''
Curie
Einstein
Faraday
Maxwell
Newton
Tesla