Skip to content

Instantly share code, notes, and snippets.

@jsbueno
jsbueno / pyproject.toml
Created January 23, 2024 15:33
Minimal pyproject.toml to use with setuptools and having a working, locally installable, package
[build-system]
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
[project]
name = "mypackage"
version = "1.0"
[tool.setuptools]
packages = ["mypackage"]
@jsbueno
jsbueno / build.sh
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 https://github.com/mypaint/mypaint.git
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 https://stackoverflow.com/questions/75915644/call-decorator-only-once-in-a-nested-class-function/75915738#75915738
from functools import wraps
from threading import RLock
import contextvars
RUNONCE = contextvars.ContextVar("RUNONCE", default=None)
class RunOnceDecorator:
@jsbueno
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
jsbueno / lgm_mazinator.py
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)
#!/usr/bin/python
# -*- 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
jsbueno / gist:e4378521ead8f9dbb40565fb5cacd0b9
Created January 6, 2023 15:59
Snippets for advanced generator research I used when figuring out an answer for https://stackoverflow.com/questions/74922314/yield-from-vs-yield-in-for-loop
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
jsbueno / day15_2022.py
Created December 16, 2022 18:06
advent_!5_2022
"""
SPOILER ALERT
Puzzle at: https://adventofcode.com/2022/day/15
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
jsbueno / advent_14_2022.py
Created December 14, 2022 17:47
Advent of code 2022 - day 14
"""
SPOILER ALERT!
Problem at: https://adventofcode.com/2022/day/14
I guess, no special comments this time.
Just that terminedia.V2 is truly great!
"""
import terminedia as TM
"""
SPOILER ALERT!
Problem at: https://adventofcode.com/2022/day/13
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,
@jsbueno
jsbueno / advent_12_2022.py
Last active December 13, 2022 20:19
Advent of Code, day 12 - 2022
"""
SPOILER ALERT
Advent of Code, day 12 - 2022
At least, I am using terminedia for something
beyond the 2D vectors -
"""