Skip to content

Instantly share code, notes, and snippets.

View ambv's full-sized avatar
🐍
CPython Dev in Residence

Łukasz Langa ambv

🐍
CPython Dev in Residence
View GitHub Profile
@ambv
ambv / tessel.py
Last active July 28, 2022 17:51
A tessellation inspired by the Alhambra. The exercise only made me appreciate the original piece of art more.
from turtle import *
WIDTH = 1280
HEIGHT = 800
RADIUS = 50
def init():
setup(WIDTH, HEIGHT)
setworldcoordinates(0, 0, WIDTH, HEIGHT)
@ambv
ambv / run_hypo.py
Last active July 17, 2021 11:38
Use Hypothesis for smoketests of https://github.com/python/cpython/pull/27091
"""
Runs PBTs on `bytes.count` and `bytes.find`. Also confirms results match Python 3.9.
How to use:
- build CPython 3.11 from source
- run ./python.exe -m ensurepip
- run ./python.exe -m pip install hypothesis
- run ./python.exe run_hypo.py # this file
Note: `MAX` value below generates tests that on my machine execute between

Python 3.8.10, 3.9.5, and 3.10.0b1 are now available

This has been a very busy day for releases and on behalf of the Python development community we're happy to announce the availability of three new Python releases.

Python 3.10 is now in Beta

Python 3.10 is still in development. 3.10.0b1 is the first of four planned beta release previews. Beta release previews are intended to give the wider community the opportunity to test new features and bug fixes and to prepare their projects to support the new feature release.

We strongly encourage maintainers of third-party Python projects to test with 3.10 during the beta phase and report issues found to the Python bug tracker as soon as possible. While the release is planned to be feature complete entering the beta phase, it is possible that features may be modified or, in rare cases, deleted up until the start of the release candidate phase (Monday, 2021-08-02). Our goal is have no ABI changes after beta 4 and as few code

@ambv
ambv / img_to_ascii.py
Last active March 23, 2022 17:18
Happy Atheist Day!
import base64
import bz2
from dataclasses import dataclass
from pathlib import Path
import pickle
from typing import Iterable, Iterator
try:
from rich.color import Color
from rich.console import Console, ConsoleOptions, RenderResult
@ambv
ambv / gist:98c7ebbbe8f610d1ae5f9f37a83b8a94
Created December 27, 2020 12:49
Tracker Chord Notation
Sus2 027
Sus2 #5 028
DimTriad 036
Min 037
Maj 047
AugTriad 048
Sus4 057
Stack4 05A
Open4 05C
Sus #4 067
@ambv
ambv / martin.py
Created September 25, 2020 14:58
Turns Agnes Martin paintings into numbers
#!/usr/bin/env python3
# for Disquiet 0456: https://llllllll.co/t/disquiet-junto-project-0456-line-up/36613/
"""
martin - converts an image with horizontal lines into JSON with a list of lists of numbers
Usage:
martin <file>
martin --help
@ambv
ambv / PythonFormatLinter.php
Created September 26, 2018 19:36
How to integrate Black with Arcanist
<?php
final class PythonFormatLinter extends ArcanistFutureLinter {
public function getLinterName() {
return 'BLACK';
}
protected function getFuturesLimit() {
return 8;
}
@ambv
ambv / tokenize.diff
Last active April 23, 2018 00:34
Unified diff between Lib/tokenize.py and Lib/lib2to3/pgen2/tokenize.py
--- Lib/tokenize.py 2018-04-22 17:33:48.000000000 -0700
+++ Lib/lib2to3/pgen2/tokenize.py 2018-04-22 17:32:55.000000000 -0700
@@ -31,14 +31,15 @@
import itertools as _itertools
import re
import sys
-from token import *
+from .token import *
cookie_re = re.compile(r'^[ \t\f]*#.*?coding[:=][ \t]*([-\w.]+)', re.ASCII)
@ambv
ambv / config.cson
Created January 7, 2017 00:08
File-type specific Atom configuration
'.gfm.source':
'editor':
'softWrap': true
'tabLength': 4
'preferredLineLength': 72
@ambv
ambv / repro.sh
Created December 20, 2016 19:54
Demonstrates how `ignore = ` overrides the default ignore list, implicitly re-enabling optional warnings in bugbear. Note the line "Overriding default value of". Change bugbear version to 16.12.2 to see the workaround in action (note the line "Optional warning B950").
#!/bin/bash -e
# Create the environment
rm -rf .v # remove old stuff if present
python3 -m venv .v
source .v/bin/activate
cd .v
pip install flake8==3.2.1
pip install flake8-bugbear==16.12.1 # the newer version works around the issue