Skip to content

Instantly share code, notes, and snippets.

View sethmlarson's full-sized avatar
🛡️
Keeping the Python ecosystem safe!

Seth Michael Larson sethmlarson

🛡️
Keeping the Python ecosystem safe!
View GitHub Profile

Keybase proof

I hereby claim:

  • I am sethmlarson on github.
  • I am sethmlarson (https://keybase.io/sethmlarson) on keybase.
  • I have a public key whose fingerprint is EDD5 6765 A9D8 4653 CBC8 A134 51B0 6736 1740 F5FC

To claim this, I am signing this object:

@sethmlarson
sethmlarson / yahoo-http2-issue.py
Last active January 28, 2020 20:28
Code that reproduces Yahoo's HTTP/2 issue.
"""
Code that reproduces Yahoo's HTTP/2 issue.
Requires you to run `python -m pip install h2` before executing.
Example output:
```
Testing 'google.com' with 'send_unknown_setting=False'...
Result: <ResponseReceived stream_id:1, headers:[(b':status', b'301'), (b'location', b...
@sethmlarson
sethmlarson / urllib3-2.7.x-downloads.md
Created March 14, 2020 17:20
urllib3 2.7.x Downloads
Python Version # of Downloads % of 2.7.x Downloads % of All Downloads
<2.7.9 133029 11.84% 4.06%
>=2.7.9 990229 88.16% 30.21%
2.7.x 1123258 100% 34.27%
All 3277817 N/A 100%
  • This data was gathered from the PyPI dataset for March 11, 2020.
@sethmlarson
sethmlarson / elasticsearch-orjson-serializer.py
Last active March 11, 2024 10:08
JSON serializer for Elasticsearch Python client that uses the 'orjson' library for performance
"""JSON serializer for Elasticsearch Python client that
uses the 'orjson' library for performance.
https://github.com/ijl/orjson
"""
# Implement the Serializer.loads() and .dumps() APIs w/ orjson:
import orjson
from elasticsearch import SerializationError, JSONSerializer

PyPI TUF Key Generation and Signing Ceremony

Attesting that I was watching and listening to the live stream of the ceremony on Youtube for the entire duration of the broadcast without interruption. Notes were taken as I went with a stopwatch keeping track of relative timestamps from the start of the ceremony.

All times are of my viewing of the ceremony, not necessarily as the ceremony actually occurred due to delay between real events and the stream.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@sethmlarson
sethmlarson / warning-stacklevel.py
Last active February 11, 2022 14:20
Dynamically determine stacklevel for use with warnings.warn(..., stacklevel=X)
import inspect
import sys
from pathlib import Path
def warn_stacklevel() -> int:
"""Dynamically determine stacklevel for warnings based on the call stack"""
try:
# Grab the root module from the current module '__name__'
module_name = __name__.partition(".")[0]
@sethmlarson
sethmlarson / brotlipy-0.7.0-abi3.diff
Created September 2, 2021 17:51
Diff between brotlipy 0.7.0 tag and the source for building the abi3 compatible wheels
diff --git a/setup.py b/setup.py
index f804932..12ae724 100644
--- a/setup.py
+++ b/setup.py
@@ -1,11 +1,43 @@
#!/usr/bin/env python
+import platform
+import sys
from setuptools import find_packages, setup
+from setuptools.command.build_ext import build_ext
@sethmlarson
sethmlarson / business-card-http-client.py
Last active February 14, 2022 14:00
HTTP client on a business card
import asyncio as A,urllib.parse as U,re;B,C,I,S=b"",b"\r\n",int,lambda*A:re.match(*A,24).groups()
async def request(m,u,h,b):
s,_,a,_,q,_=z=U.urlparse(u);T,E,d,N=s!=b"http",0,B,z.hostname;r,w=await A.open_connection(N,I(z.port or 80+363*T),ssl=T,server_hostname=[None,N][T]);w.write(m+b" "+(a or b"/")+[b"?"+q,B][q==B]+b" HTTP/1.0"+C+C.join([b"%b:%b"%W for W in h]+[B,b]));await w.drain()
while c:=await r.read():
if C*2in(d:=d+c)*(E==0):E,d=d.split(C*2,1);t,o=S(b"HTTP/.+? (\d+).*?%b(.*)"%C,E);o=[S(rb"([^\s]+):\s*(.+?)\s*$",x)for x in o.split(C)]
w.close();return I(t),o,d
import ssl
import requests
from requests.adapters import HTTPAdapter
import truststore
class TruststoreAdapter(HTTPAdapter):
def init_poolmanager(
self, *args, **kwargs
):
ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)