Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python3
"""
Add trailing commas to multiline lists, tuples, dicts, sets, and function calls.
"""
import libcst as cst
from pathlib import Path
import sys
class TrailingCommaTransformer(cst.CSTTransformer):
@antocuni
antocuni / flamegraph-branch.html
Created September 7, 2024 12:09
scalene flamegraph
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" width="1800" height="242" onload="init(evt)" viewBox="0 0 1800 242" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<!-- Flame graph stack visualization. See https://github.com/brendangregg/FlameGraph for latest version, and http://www.brendangregg.com/flamegraphs.html for examples. -->
<defs >
<linearGradient id="background" y1="0" y2="1" x1="0" x2="0" >
<stop stop-color="#eeeeee" offset="5%" />
<stop stop-color="#eeeeb0" offset="95%" />
</linearGradient>
</defs>
@antocuni
antocuni / richards.py
Created July 12, 2024 08:48
richards.py
"""
based on a Java version:
Based on original version written in BCPL by Dr Martin Richards
in 1981 at Cambridge University Computer Laboratory, England
and a C++ version derived from a Smalltalk version written by
L Peter Deutsch.
Java version: Copyright (C) 1995 Sun Microsystems, Inc.
Translation from C++, Mario Wolczko
Outer loop added by Alex Jacoby
"""
import sys
def main():
myvar = 'hello'
print('this is line 5')
print('this is line 6')
print('this is line 7')
print('this is line 8')
print('this is line 9')
@antocuni
antocuni / hpy.h
Created May 19, 2020 12:42
HPy methods
#define METH_NOARGS 1
#define METH_O 2
typedef void* HPyContext;
typedef long HPy;
typedef HPy (*HPyMeth_NOARGS)(HPyContext, HPy);
typedef HPy (*HPyMeth_O)(HPyContext, HPy, HPy);
typedef struct {

To keep compatibility with CPython, we need to generate a trampoline for each method which uses one of HPy calling conventions, e.g.:

HPy_DEF_METH_VARARGS(add_ints)
static HPy add_ints_impl(HPyContext ctx, HPy self, HPy *args, HPy_ssize_t nargs);

After this, add_ints is a function of type HPyMeth (which is different in the CPython and the Universal cases), and can be put inside an

>>> def foo():
... try:
... print('start')
... yield 1
... yield 2
... print('bye')
... except GeneratorExit:
... print('forced exit')
...
>>> f = foo()
@antocuni
antocuni / build-wheels.sh
Created May 6, 2020 13:48
pip/manylinux bug
#!/bin/bash
set -e
# Compile wheels
PYTHONS=(
cp27-cp27m
cp27-cp27mu
)
# remove leftovers from previous builds, if any
@antocuni
antocuni / conftest.py
Last active April 16, 2019 15:33
pytest capture bug
# if you uncomment this, the test works as expected
import dummy
@antocuni
antocuni / Makefile
Created December 20, 2017 17:05
elf-experiment
main: main.c greetings.c
gcc -c greetings.c
gcc -c main.c
gcc -o main greetings.o main.o