Skip to content

Instantly share code, notes, and snippets.

jsbueno /
Created June 14, 2024 04:45
POC: wrapper for a function that can either run sychrnously or be awaited in an asyncio context:
# here, the function that can work "either way" is the nested "payload".
# The external ^morphix_in_thread" can be a decorator, and "payload" the decorated function
def morphix_in_thread():
loop = asyncio.get_running_loop()
except RuntimeError:
loop = None
def payload():
jsbueno / pyproject.toml
Created January 23, 2024 15:33
Minimal pyproject.toml to use with setuptools and having a working, locally installable, package
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
name = "mypackage"
version = "1.0"
packages = ["mypackage"]
jsbueno /
Created November 22, 2023 16:35
Shell command sequence to compile and install mypaint from GIT, as of november 2023, with Python 3.11
# this is not a script - more like a curated command sequence from my history
# after succesfully installing mypaint.
export $PREFIX=/home/<user>/mypaint-git
sudo dnf install swig # fedora/redhat specific. One also will need Python3-dev and other Linux packages
git clone
cd mypaint
~/.pyenv/versions/3.11.4/bin/python -m venv env311 # or use other cPython interpreter of preference
#original code written as an answer to
from functools import wraps
from threading import RLock
import contextvars
RUNONCE = contextvars.ContextVar("RUNONCE", default=None)
class RunOnceDecorator:
jsbueno / README.MD
Created March 28, 2023 18:10
"bicycle repair man"

"Bicycle Repair Man" script showing a "zope-esque" prototype in less than 200 LoC using multiple inheritance and mixins.

This prototype was presented in Python Brasil 2011 in Sao Paulo, explaining at once a bit about what Zope does (did), and showng the capabilities of multiple inheritance.

(and likely not touched since).

Unfortunatelly I think the video for this lecture had not being made, or not survived -

jsbueno /
Created March 11, 2023 06:28
Python + Pygame maze animation program - using generators as co-routines before it was trendy. (written in 2010, at LGM Brussels)
# -*- coding: utf-8 -*-
# Author: Jo?o S. O. Bueno
# Copyright: Jo?o 2010 -
# Created at LibreGraphicsMeeting 2010, Brussels
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
jsbueno / gist:e4378521ead8f9dbb40565fb5cacd0b9
Created January 6, 2023 15:59
Snippets for advanced generator research I used when figuring out an answer for
class VerboseItBase:
def __new__(cls, gen, method):
if method == "from":
cls = VerboseItFrom
elif method == "explicit":
cls = VerboseItExplicit
return super().__new__(cls)
def __init__(self, gen, method):
self.gen = gen
self.method = method
jsbueno /
Created December 16, 2022 18:06
Puzzle at:
Part 2 could be brute-forced with the use of "part1" in less
than 10 minutes, I guess.
I opted for a rectangle-splitting approach, and checking if
jsbueno /
Created December 14, 2022 17:47
Advent of code 2022 - day 14
Problem at:
I guess, no special comments this time.
Just that terminedia.V2 is truly great!
import terminedia as TM
Problem at:
This one was made quite easy by using Python's native comparison heuristics
along with operator overloading.
Part 2 was ready without a single new line of code on the class- just adding the markers,