Skip to content

Instantly share code, notes, and snippets.

@cessor
cessor / testrunner.py
Last active March 19, 2024 08:12
StopwatchTestRunner
import time
import statistics
import unittest
from unittest import TextTestRunner
from django.test.runner import DiscoverRunner
class StopwatchTestResult(unittest.TextTestResult):
"""
Times test runs and formats the result
@cessor
cessor / Makefile
Last active February 26, 2022 08:54
.DEFAULT_GOAL := help
.PHONY: help
# Source (So cool, thanks): https://daniel.feldroy.com/posts/autodocumenting-makefiles
define HELP_TEXT
import re,sys;
tasks = []
for line in sys.stdin:
match = re.match(r'^([a-zA-Z0-9_\.\-]+):.*?##(.*)$$', line)
if not match: continue
tasks.append("%-10s %s" % match.groups())
@cessor
cessor / hexview.py
Created September 6, 2021 15:19
hexview.py
import argparse
import curses
import string
import sys
from curses import wrapper
from curses.textpad import rectangle
from pathlib import Path
class HexDisplay:
@cessor
cessor / hexshow.py
Last active September 6, 2021 15:15
hexshow.py
with open('png.png', 'rb') as file:
content = file.read()
for i in range(0 , len(content), 16):
# row offset
print(f'{i:08X}', end=' ')
# byte display
row = content[i:i + 16]
class Duration(object):
'''
Calculate duration with 60 FPS (16.66 ms per frame)
Make it so that the duration can be compared using >=,
so that the NEXT Frame will actually display a stimulus.
Example:
Suppose you want to display a stimulus after 225 ms. This is technically impossible on a 60hz screen with a synchronized display because each frame takes 0.0167 seconds (16.7ms) to render, and so the stimulus can either draw for 216.7ms or 233.3ms. I discussed with the product owner (Jan Rummel) that we should opt for the earlier stimulus, because otherwise the milliseconds add up.
During each frame, an update is sent to the system whether the next
/*
1. Place this file in <profile dir>/chrome/userChrome.css (about:support)
2. Enable `toolkit.legacyUserProfileCustomizations.stylesheets` (about:config)
3. Source https://amitp.blogspot.com/2021/06/firefox-89-tab-appearance.html?m=1
*/
.tab-background {
background: #585060;
border-radius: 5px 5px 0 0 !important;
margin-bottom: 0px !important;
@cessor
cessor / AutoSlugField.py
Created April 7, 2021 14:15
AutoSlugField.py
from typing import Callable
from django.core import checks
from django.db import models
from django.utils.functional import cached_property
from django.utils.text import slugify
from django.utils.translation import gettext_lazy as _
class AutoSlugField(models.SlugField):
"""
@cessor
cessor / random_article_async.py
Created March 13, 2020 08:48
Random Wikipedia Articles using Python pool.appy_async
"""
Mit __iter__ kann man komplexe Iterationen abstrahieren
- Iteratoren sind Zustandsautomaten.
- Dadurch lässt sich das iterieren vom prozessieren trennen.
- So kann man den gleichen Iterator seriell oder parallel umsetzen
"""
import json
import time
import requests
import multiprocessing
@cessor
cessor / png_chunks.py
Last active January 17, 2020 17:48
png_chunks.py
"""
Reads PNG Chunk Data.
http://www.libpng.org/pub/png/spec/1.2/PNG-Chunks.html
http://www.libpng.org/pub/png/spec/1.2/PNG-Compression.html
"""
import sys
import datetime
import pathlib
@cessor
cessor / obast.py
Created January 16, 2020 18:45
obast.py
import ast
ast = ast.parse('a = (1 + 2)\n', filename='<string>', mode='single')
statement, *_ = ast.body
def walk(node, field='', depth=0):
indent = depth * ' '
name = node.__class__.__name__
if isinstance(node, list):