Skip to content

Instantly share code, notes, and snippets.

View ionelmc's full-sized avatar
🙃
wat

Ionel Cristian Mărieș ionelmc

🙃
wat
View GitHub Profile
import array
import tracemalloc
from contextlib import contextmanager
@contextmanager
def tracemem(msg):
tracemalloc.start()
snapshot1 = tracemalloc.take_snapshot()
yield
snapshot2 = tracemalloc.take_snapshot()
anonymous
anonymous / partialable.py
Created September 13, 2014 10:22
import inspect
class n_partialable(object):
@staticmethod
def arity_evaluation_checker(function):
is_class = inspect.isclass(function)
if is_class:
function = function.__init__
@ionelmc
ionelmc / cmd-proxy.py
Created August 14, 2012 08:44
Command line http proxy (for benchmarking)
#!/usr/bin/env python
import os
import tornado.httpserver
import tornado.ioloop
import tornado.web
import subprocess
import shlex
import fcntl
import errno
from cStringIO import StringIO
@jezdez
jezdez / common [stash] fields.py
Created December 1, 2012 15:07 — forked from thomasyip/common [stash] fields.py
Updated version of Django BigInt Patch for 64bit Primary Keys
"""
module mydjangolib.bigint_patch
A fix for the rather well-known ticket #399 in the django project.
Create and link to auto-incrementing primary keys of type bigint without
having to reload the model instance after saving it to get the ID set in
the instance.
Logs:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Build a pip-compatible sdist for the flit package in the current directory.
"""
import flit, zipfile, os.path
def build_sdist():
# build wheel
@ionelmc
ionelmc / .travis.tmpl.yml
Last active December 13, 2015 15:46
This might be outdated. Updated samples here: https://github.com/ionelmc/python-nameless/tree/generative
language: python
python: '3.5'
sudo: false
env:
global:
LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so
matrix:
- TOXENV=check
{% for env, config in tox_environments|dictsort %}
- TOXENV={{ env }}{% if config.cover %},extension-coveralls,coveralls,codecov{% endif %}
@OddBloke
OddBloke / nose_checker.py
Created September 24, 2013 08:07
A pylint plugin to fix nose.tools import errors
# The MIT License (MIT)
#
# Copyright (c) 2013 Daniel Watkins <daniel@daniel-watkins.co.uk>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the Software), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#!/bin/bash -eEx
if ! which gpg-agent; then
sudo apt-get install gnupg-agent
fi
if ! which pull-lp-source; then
sudo apt-get install ubuntu-dev-tools
fi
gpg-agent || eval `gpg-agent --daemon`
@ionelmc
ionelmc / settings.py
Last active December 27, 2015 12:49
Dead-simple Django SQL logging
import sys
try:
from sqlparse import format as sqlformat
except ImportError:
sqlformat = lambda s, reindent=None: s
from traceback import format_stack
class WithStacktrace(object):
def __init__(self, skip=[], limit=5):
self.skip = [__name__, 'logging']
@markshannon
markshannon / dynattr.py
Created November 30, 2014 22:06
Dynamic attribute module
import sys
import warnings
from types import ModuleType
from importlib import import_module
try:
basestring
except NameError:
basestring = str