Skip to content

Instantly share code, notes, and snippets.

View carljm's full-sized avatar

Carl Meyer carljm

View GitHub Profile
diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst
index b2dd32f925e..09396b87245 100644
--- a/Doc/library/functions.rst
+++ b/Doc/library/functions.rst
@@ -1780,6 +1780,13 @@ are always available. They are listed here in alphabetical order.
the second argument is a type, ``issubclass(type2, type)`` must be true (this
is useful for classmethods).
+ When called directly within an ordinary method of a class, both arguments may
+ be omitted ("zero-argument :func:`super`"). In this case, *type* will be the
void _PyST_Dump(PySTEntryObject* ste, PyObject* prefix)
{
const char *blocktype;
switch(ste->ste_type) {
case FunctionBlock: blocktype = "FunctionBlock"; break;
case ClassBlock: blocktype = "ClassBlock"; break;
case ModuleBlock: blocktype = "ModuleBlock"; break;
case AnnotationBlock: blocktype = "AnnotationBlock"; break;
case TypeVarBoundBlock: blocktype = "TypeVarBoundBlock"; break;
case TypeAliasBlock: blocktype = "TypeAliasBlock"; break;
@carljm
carljm / db.py
Last active May 1, 2023 00:54
SQLAlchemy and Postgres autocommit
"""
SQLAlchemy, PostgreSQL (psycopg2), and autocommit
See blog post: http://oddbird.net/2014/06/14/sqlalchemy-postgres-autocommit/
"""
from contextlib import contextmanager
from sqlalchemy import create_engine, event
from sqlalchemy.orm import sessionmaker, Session as BaseSession
mainopt.json
============
Performance version: 1.0.6
Report on Linux-5.15.0-1028-aws-x86_64-with-glibc2.31
Number of logical CPUs: 72
Start date: 2023-02-13 15:59:52.702512
End date: 2023-02-13 16:37:24.927583
ic2opt.json
@carljm
carljm / postactivate
Created July 12, 2011 18:21
Yo dawg, I heard you like Ruby...
#!/bin/bash
# This hook is run after every virtualenv is activated.
export OLD_GEM_HOME=$GEM_HOME
export GEM_HOME=$VIRTUAL_ENV/gems/
export GEM_PATH=
export PATH=$VIRTUAL_ENV/gems/bin:$PATH
@carljm
carljm / test_ws.py
Last active November 10, 2022 20:05
Establishing a websocket connection to SocketIO 1.x from Python
import json
import requests
from websocket import create_connection
BASE = 'localhost:3000/socket.io/?EIO=3'
# First establish a polling-transport HTTP connection to get a session ID
url = 'http://%s&transport=polling' % BASE
~$ bench-jobs compare req-compile-bench-1664914413-esnow req-compile-bench-1664903905-esnow
All benchmarks:
===============
+-------------------------+------------------------------------------------------------------+------------------------------------------------------------------+
| Benchmark | req-compile-bench-1664914413-esnow/pyperformance-results.json.gz | req-compile-bench-1664903905-esnow/pyperformance-results.json.gz |
+=========================+==================================================================+==================================================================+
| unpickle | 13.7 us | 13.2 us: 1.04x faster |
+-------------------------+------------------------------------------------------------------+------------------------------------------------------------------+
@carljm
carljm / staticmethod.py
Created June 27, 2012 14:55
pure Python implementation of the staticmethod decorator
class StaticMethod(object):
def __init__(self, func):
self.func = func
def __get__(self, obj, cls):
return self.func
def staticmethod(func):
@carljm
carljm / runner.py
Created December 9, 2011 04:07
Unittest2 test discovery and real dotted-path named test selection for Django
"""
An alternative Django ``TEST_RUNNER`` which uses unittest2 test discovery from
a base path specified in settings, rather than requiring all tests to be in
``tests`` module of an app.
If you just run ``./manage.py test``, it'll discover and run all tests
underneath the ``TEST_DISCOVERY_ROOT`` setting (a path). If you run
``./manage.py test full.dotted.path.to.test_module``, it'll run the tests in
that module (you can also pass multiple modules).
@carljm
carljm / envsettings.py
Created April 13, 2016 19:07
Django settings from env.
"""Utility for pulling settings from the environment."""
import os
from urllib.parse import urlparse
class EnvParser:
"""Utility for getting settings from the OS environ.
Instantiate with the name of an env var to get the current mode from (that
env var should be set to one of VALID_MODES, or not set), then call the