Skip to content

Instantly share code, notes, and snippets.

View encukou's full-sized avatar

Petr Viktorin encukou

View GitHub Profile

A printer-friendly style for the PyCon US 24 schedule pages, taken from Hugo's blog post.

Paste the following into the browser console. (You might get a warning about not pasting code you don't understand -- it's there for the same reasons why I don't like installing browser extensions that someone recommends to me.)

The style will only change when you print (or do a print preview).

var sheet = document.createElement("style");
sheet.innerHTML = `
 @media print {
@encukou
encukou / nazev_jednoducheho_cisla.c
Created March 21, 2024 16:21
nazev_jednoducheho_cisla.c
// vraci staticky retezec, nevolat free()
char *nazev_jednoducheho_cisla(int n) {
switch (n) {
case 0: return "nula";
case 1: return "jedna";
case 2: return "dva";
case 3: return "tri";
case 4: return "ctyri";
case 5: return "pet";

A function may be shadowed by a static inline function or macro with the same behavior. Typically, this allows better performance for C/C++.

Shadowing example

To provide a static inline equivalent to an exported function, write something like:

import unicodedata
def get_components(char):
name = unicodedata.name(char).removeprefix('BOX DRAWINGS ')
result = []
for part in name.split(' AND '):
part = part.replace(' DASH', '-DASH')
directions = []
for word in part.split():
match word:
import inspect
import sys
import functools
def trace(f):
signature = inspect.signature(f)
indent = ''
@functools.wraps(f)
def decorated(*a, **ka):

Python Vendor Configuration

Currently, several Python distributors modify the Python install layout. Making such modifications requires them to patch multiple standard library modules. The install layout is currently not meant to be a configurable option in a Python installation, but Python developers, distro packagers and module authors all have conflicting certain assumptions in this area. This has presented itself as problematic because Python distributors, understandably, fail to correctly modify all places required to satisfy all these assumptions, resulting in incoherent or straight-out broken Python distributions

# Generator for: https://youtu.be/xeL_Ifngcbo
# Save student code as obrazky/*.py and run this
import sys
import importlib
from pathlib import Path
import turtle
import time
import itertools
import dataclasses
https://github.com/encukou/piskvorky
# Shaped clock, adapted from:
# https://doc.qt.io/qt-6/qtwidgets-widgets-shapedclock-example.html
# pip install pyside6
from PySide6 import QtWidgets, QtCore, QtGui
app = QtWidgets.QApplication([])
class ShapedClock(QtWidgets.QWidget):
def __init__(self):
# pip install pyglet
import pyglet
window = pyglet.window.Window(
style=pyglet.window.Window.WINDOW_STYLE_BORDERLESS,
resizable=True,
)
label = pyglet.text.Label('Zavřít ', font_name=['Fira Mono', 'Courier New'])