Skip to content

Instantly share code, notes, and snippets.

View anthonyrisinger's full-sized avatar

C Anthony Risinger anthonyrisinger

View GitHub Profile
class Import:
def __init__(self, args, attr):
self.args = args
self.attr = attr
self.done = False
def __import__(self):
module = __import__(*self.args)
if not self.attr:
@anthonyrisinger
anthonyrisinger / collect.py
Last active February 23, 2017 21:40
collect.py against distlib data
# find . -name project.json | python3 collect.py
#
# total_projects: 41228
# total_projects_eq: 182
# % affected: 0.44%
# total_files: 285248
# total_files_eq: 1276
# % affected: 0.45%
# total_reqs: 642447
# total_reqs_bare: 460080
@anthonyrisinger
anthonyrisinger / animals.py
Last active December 8, 2015 05:32
Program I wrote with 1st grade son, started much simpler and grew to this
#!/usr/bin/python
# .
# |-- animals.py
# `-- sounds
# |-- cat.wav
# |-- cow.wav
# |-- dog.wav
# |-- oops.wav
# |-- sheep.wav
# `-- wolf.wav
@anthonyrisinger
anthonyrisinger / logbook_stdout_json.py
Created October 5, 2015 19:37
logbook/logstash formatter and stackable context dicts
# encoding: utf8
from __future__ import absolute_import
from __future__ import print_function
import datetime
import itertools
import json
import sys
import threading
@anthonyrisinger
anthonyrisinger / sockfun.py
Created June 25, 2015 19:46
uWSGI, Python, sockets, ...
# encoding: utf8
"""
save this as sockfun.py, then::
git clone https://github.com/unbit/uwsgi.git && cd uwsgi
python2 setup.cpyext.py build
PYTHONPATH=build/lib.linux-x86_64-2.7 python2 sockfun.py
"""
from __future__ import print_function
@anthonyrisinger
anthonyrisinger / gist:9556806
Created March 14, 2014 21:00
Function-like Modules (better control/introspection)
# encoding: utf-8
#
# modules-next
#
# C Anthony Risinger
import sys
@anthonyrisinger
anthonyrisinger / gist:7946272
Created December 13, 2013 15:48
CELERY_EVENT_SERIALIZER = 'pickle' rejected by kombu
#!/bin/bash
IFS=; shopt -s nullglob
export PIP_REQUIRE_VIRTUALENV=
export PYTHONUNBUFFERED=x
export PYTHON=$(type -p python2.7 python2.6 python2 python | head -n1)
export PIP=$(type -p pip-2.7 pip-2.6 pip2 pip | head -n1)
cat <<'EOF' > controller.py
# /usr/bin/python2 uwsgiconfig.py --clean; /usr/bin/python2 uwsgiconfig.py --build; /usr/bin/python2 uwsgiconfig.py --plugin plugins/pty default.ini pty; ./uwsgi --socket :3031 --processes 2 --pyshell="from IPython import embed; embed()" --master --plugin pty --pty-socket :5000 --pty-log --pty-input
using profile: buildconf/default.ini
detected include path: ['/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/include', '/usr/local/include', '/usr/lib/gcc/x86_64-unknown-linux-gnu/4.8.1/include-fixed', '/usr/include']
detected CPU cores: 4
configured CFLAGS: -O2 -I. -Wall -Werror -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -fno-strict-aliasing -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wno-format -Wno-format-security -DUWSGI_HAS_IFADDRS -DUWSGI_ZLIB -DUWSGI_LOCK_USE_MUTEX -DUWSGI_EVENT_USE_EPOLL -DUWSGI_EVENT_TIMER_USE_TIMERFD -DUWSGI_EVENT_FILEMONITOR_USE_INOTIFY -DUWSGI_PCRE -DUWSGI_ROUTING -DUWSGI_CAP -DUWSGI_UUID -DUWSGI_VERSION="\"1.9.15-dev-f027153\"" -DUWSGI_VERSION_BASE="1" -DUWSGI_VERSIO
@anthonyrisinger
anthonyrisinger / gist:5734859
Created June 8, 2013 11:18
uWSGI + SIGPIPE + OSError
#!/bin/bash
uwsgi --http :9000 --eval '
import sys
from time import sleep
from pprint import pformat as pf, pprint as pp
sys.excepthook = lambda *a, **k: pp(("ARGS:",a)) or pp(("KWDS",k))
@anthonyrisinger
anthonyrisinger / queue_worker.py
Created October 22, 2012 21:29
SIGSEGV when running tracebacker on loaded workers
#!/usr/bin/env python
import os
import sys
import time
import logging
logging.basicConfig()
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)