Skip to content

Instantly share code, notes, and snippets.

@brettcannon
brettcannon / cloudSettings
Last active June 18, 2018 21:57
Visual Studio Code Settings Sync Gist
{"lastUpload":"2018-06-18T21:57:18.905Z","extensionVersion":"v2.9.2"}
@brettcannon
brettcannon / parse-pylint-list-msgs.py
Last active March 9, 2018 19:07
Parse the Pylint message list
import pathlib
import re
SUMMARY_LINE_RE = re.compile(r':(?P<name>\S+) \((?P<code>.+?)\):( \*(?P<summary>.+)\*)?')
def parse_summary_line(line):
line_match = SUMMARY_LINE_RE.match(line)
if not line_match:
raise ValueError(f"ill-formed line: {line!r}")
@brettcannon
brettcannon / 3.5-comparison.txt
Created September 13, 2016 18:53
Performance comparison between Python 3.5.2+ & 3.6b1+
+------------------------------------+---------------+---------------+--------------+-------------------------+
| Benchmark | 3.5-perf.json | 3.6-perf.json | Change | Significance |
+====================================+===============+===============+==============+=========================+
| 2to3 | 0.68 | 0.62 | 1.09x faster | Significant (t=65.03) |
+------------------------------------+---------------+---------------+--------------+-------------------------+
| call_method | 0.02 | 0.02 | 1.07x faster | Significant (t=46.01) |
+------------------------------------+---------------+---------------+--------------+-------------------------+
| call_method_slots | 0.02 | 0.02 | 1.06x faster | Significant (t=29.45) |
+------------------------------------+---------------+---------------+--------------+-------------------------+
| call_method_un
@brettcannon
brettcannon / hglookup.py
Last active November 28, 2017 22:14
hg.python.org/lookup
# hglookup.py
#
# Lookup a revision hash in a bunch of different hgwebdir repos.
# Also includes special treatment for subversion revisions from
# the CPython repo.
#
# Written by Georg Brandl, 2010.
import io
import json
@brettcannon
brettcannon / gist:a9c9a5989dc383ed73b4
Last active September 19, 2017 10:27
Initial email about Python development process and proposed improvements

This was posted as an email to python-dev.

History lesson

Since I signed up for the python-dev mailing list way back in June 2002, there seems to be a cycle where we as a group come to a realization that our current software development process has not kept up with modern practices and could stand for an update. For me this was first shown when we moved from SourceForge to our own infrastructure, then again when we moved from Subversion to Mercurial (I led both of these initiatives, so it's somewhat a tradition/curse I find myself in this position yet again). And so we again find ourselves at the point of realizing that we are not keeping up with current practices and thus need to evaluate how we can improve our situation.

Where we are now

Now it should be realized that we have to sets of users of our development process: contributors and core developers (the latter whom can play both roles). If you take a rough outline of our cur

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@brettcannon
brettcannon / config.fish
Created August 8, 2014 19:29
My fish configuration
function fish_prompt
set_color -o red
echo -n "> "
set_color normal
end
# From https://github.com/mduvall/dotfiles/blob/master/fish_prompt.fish.
function fuller_prompt_cwd --description 'Print the current working directory, NOT shortened to fit the prompt'
if test "$PWD" != "$HOME"
printf "%s" (echo $PWD|sed -e 's|/private||' -e "s|^$HOME|~|")
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@brettcannon
brettcannon / fspath.py
Created April 13, 2016 17:08
Possibly implementations of os.fspath()
# str-only.
def fspath(path):
try:
path = path.__fspath__()
except AttributeError:
pass
if isinstance(path, str):
return path
else:
raise TypeError
@brettcannon
brettcannon / gist:6032922
Last active December 19, 2015 23:09
Calculation of the visual acuity limit for the closest distance to sit to your television. Using the defaults, if you plug in the diagonal size of your TV, the value will be (in inches) the closest you can sit to your 1080p television showing 1080p content and not see individual pixels. Equation taken from http://en.wikipedia.org/wiki/Optimum_HD…
import math
arcminute = math.tan(math.pi/10800) # tan(1/60) in radians.
def visual_acuity_seating_distance(diagonal_in_inches, *, native_horizontal_resolution=1920, native_vertical_resolution=1080,
content_vertical_resolution=1080):
"""Calculate the closest you should sit to your television, in inches."""
return (diagonal_in_inches /
(math.sqrt((native_horizontal_resolution/native_vertical_resolution)**2 + 1) * content_vertical_resolution * arcminute))