Skip to content

Instantly share code, notes, and snippets.

@versusvoid
versusvoid / libpython.py.patch
Created April 9, 2022 14:38
Show slotted attributes and modules when debuging python with gdb
--- a/libpython.py 2022-03-23 18:38:36.000000000 +0300
+++ b/libpython.py 2022-04-09 17:34:59.590014916 +0300
@@ -370,10 +370,14 @@
'frozenset' : PySetObjectPtr,
'builtin_function_or_method' : PyCFunctionObjectPtr,
'method-wrapper': wrapperobject,
+ 'module': PyModuleObjectPtr,
}
if tp_name in name_map:
return name_map[tp_name]
@versusvoid
versusvoid / qnd.sh
Created March 25, 2022 05:43
Quck and dirty qemu linux image from linux
#!/bin/sh
# initially empty image with 8GiB max size
truncate -s 8GiB sda.img
# make dos (mbr) table with one partition
cfdisk sda.img
# mount image as loopback
DEV=$(sudo losetup --find --show --partscan sda.img)
# make root fs
@versusvoid
versusvoid / base16-alacritty.fish
Created November 3, 2021 15:17
base16 fish coloring matching alacritty base16 theme
# actually displayed colors corresponding to black, white, magenta etc.
# are changed by alacritty
if status --is-interactive; and test $TERM = alacritty
# the completion itself, i.e. the proposed rest of the string
set fish_pager_color_completion normal
# background of the selected completion
set fish_pager_color_selected_background --background=bryellow
# the completion description
set fish_pager_color_description brblack
@versusvoid
versusvoid / aborting.py
Last active November 24, 2021 05:18
Abort WSGI request processing on client disconnect (gunicorn, gevent + sqlalchemy, psycopg2)
import sys
import gevent
import gevent.local
import gunicorn.app.wsgiapp
import psycopg2
import psycopg2.errors
import psycopg2.extensions
import sqlalchemy.util
@versusvoid
versusvoid / zipstream.py
Last active October 27, 2021 16:28
Flask stream generated .zip file
import zipfile
class StreamedBytesIO(object):
def __init__(self):
self._b = bytearray()
self._pos = 0
def seek(self, *args):
raise AttributeError('sorry')
@versusvoid
versusvoid / 61-microsoft-4000.hwdb
Last active October 24, 2021 04:14
Scroll with Microsoft Natural® zoom slider
# installed in /etc/udev/hwdb.d/
# after installing run
# $ sudo udevadm hwdb --update
# $ sudo udevadm control --reload
# Microsoft Natural Ergonomic Keyboard 4000
evdev:input:b0003v045Ep00DB*
KEYBOARD_KEY_c022d=scrollup # zoomin
KEYBOARD_KEY_c022e=scrolldown # zoomout
@versusvoid
versusvoid / integrals.sage
Last active November 7, 2019 10:08
SageMath expression "linearization". Incomplete, inaccurate, but works to the first order :-)
# vi: ft=python
from sage.symbolic.operators import add_vararg, mul_vararg
from sage.symbolic.integration.integral import definite_integral, indefinite_integral
w0, w1, w2, w3 = map(SR.wild, range(4))
definite_integral_pattern = integrate(w0, w1, w2, w3)
indefinite_integral_pattern = integrate(w0, w1)
@versusvoid
versusvoid / build.sh
Last active April 16, 2019 19:07
WebAssebly misaligned load test
clang -cc1 -emit-llvm-bc -triple=wasm32-unknown-unknown-wasm -std=c11 test.c
llc -filetype=obj test.bc -o test.o
wasm-ld --no-entry test.o -o test.wasm --export=aligned --export=misaligned --import-memory
wasm2wat test.wasm
@versusvoid
versusvoid / CA.cnf
Last active October 2, 2019 11:56
Generate CA and certificate with subjectAltName for HTTPS
[req]
distinguished_name = req_distinguished_name
x509_extensions = v3_req
prompt = no
[req_distinguished_name]
C = RU
ST = Москва
L = Москва
O = Секурные разработки
@versusvoid
versusvoid / radix.py
Last active January 14, 2019 17:59
python "compressed" radix tree (in plain arrays)
def radix_tree_push_last_subtree_down(tree, level, segment_index):
prev_word_old_segment, prev_word_old_next_child_pos = tree[level][-1]
assert segment_index < len(prev_word_old_segment)
prev_word_new_segment_prefix = prev_word_old_segment[:segment_index]
prev_word_new_segment_suffix = prev_word_old_segment[segment_index:]
tree[level][-1] = (prev_word_new_segment_prefix, prev_word_old_next_child_pos)
old_next_level = tree[level + 1][prev_word_old_next_child_pos:]
tree[level + 1] = tree[level + 1][:prev_word_old_next_child_pos]