Skip to content

Instantly share code, notes, and snippets.

Carl Meyer carljm

Block or report user

Report or block carljm

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View simplified.diff
diff --git a/mypy/semanal.py b/mypy/semanal.py
index 7bac809..33d798f 100644
--- a/mypy/semanal.py
+++ b/mypy/semanal.py
@@ -2943,21 +2943,9 @@ class SemanticAnalyzer(NodeVisitor):
if isinstance(base.node, TypeInfo):
# C.bar where C is a class
type_info = base.node
- elif isinstance(base.node, Var) and self.function_stack:
- # check for self.bar or cls.bar in method/classmethod
View transaction_middleware.py
class TransactionMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
with transaction.atomic():
response = self.get_response(request)
if response.status_code == 500:
transaction.set_rollback()
return response
@carljm
carljm / envsettings.py
Created Apr 13, 2016
Django settings from env.
View envsettings.py
"""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
@carljm
carljm / jinja2backend.py
Created Jun 14, 2015
Django Jinja2 backend subclass with context processor support
View jinja2backend.py
class Jinja2Backend(jinja2backend.Jinja2):
def __init__(self, params):
self.context_processors = [
import_string(p)
for p in params['OPTIONS'].pop('context_processors', [])
]
super(Jinja2Backend, self).__init__(params)
@carljm
carljm / test.py
Created Mar 24, 2015
playing with logging
View test.py
from logging.config import dictConfig
import logging
initial = {
'version': 1,
'disable_existing_loggers': False,
'handlers': {
'console': {
'class': 'logging.StreamHandler',
},
@carljm
carljm / patch.diff
Created Feb 12, 2015
draft patch for --fake-initial doc updates
View patch.diff
diff --git a/docs/topics/migrations.txt b/docs/topics/migrations.txt
index a0dc365..fae87a0 100644
--- a/docs/topics/migrations.txt
+++ b/docs/topics/migrations.txt
@@ -148,6 +148,13 @@ developers (or your production servers) check out the code, they'll
get both the changes to your models and the accompanying migration at the
same time.
+.. versionadded:: 1.8
+
@carljm
carljm / test_ws.py
Last active Apr 22, 2019
Establishing a websocket connection to SocketIO 1.x from Python
View test_ws.py
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
View gist:e4fbf46d51c311834926
$ ./tests/runtests.py migrations
Testing against Django installed in '/home/carljm/projects/django/django/django/django'
Creating test database for alias 'default'...
Creating test database for alias 'other'...
..................................................................................................................................s...............................EE.EE.E..........s.......................................
======================================================================
ERROR: test_squashmigrations_squashes (migrations.test_commands.SquashMigrationsTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/carljm/projects/django/django/django/django/test/utils.py", line 187, in inner
@carljm
carljm / greatest.py
Created Aug 21, 2014
GREATEST() of aggregates, in the Django ORM.
View greatest.py
class Greatest(object):
"""A pseudo- (or meta-) aggregate; returns highest of sub-aggregates.
This has to be inserted directly into the Query internals; it can't go
through the usual ``qs.annotate(...)`` or ``qs.aggregate(...)`` path
(because that leads to ``Query.add_aggregate(...)`` which makes assumptions
we can't meet).
To use, instantiate ``Greatest`` with one or more normal aggregates, and
call ``greatest_instance.add_to_qs(queryset, 'name')``
@carljm
carljm / db.py
Last active Nov 21, 2019
SQLAlchemy and Postgres autocommit
View db.py
"""
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
You can’t perform that action at this time.