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 itertools
>>> [
... 'queue_%s' % '_'.join(str(node) for node in combination)
... for combination in itertools.chain(*[
... itertools.combinations(range(4), i) for i in range(1, 5)
... ])
... ]
['queue_0', 'queue_1', 'queue_2', 'queue_3', 'queue_0_1', 'queue_0_2', 'queue_0_3', 'queue_1_2', 'queue_1_3', 'queue_2_3', 'queue_0_1_2', 'queue_0_1_3', 'queue_0_2_3', 'queue_1_2_3', 'queue_0_1_2_3']
@ionelmc
ionelmc / tasktree.py
Created June 7, 2013 08:34
task tree
import sys
from celery import Celery
from celery.canvas import group
from kombu import Queue, Exchange
celery = Celery(
broker="amqp://test:test@localhost:5672/test"
)
celery.conf.update(
CELERY_RESULT_BACKEND = "mongodb",
@ionelmc
ionelmc / profiled_decorator.py
Last active February 19, 2017 09:49
Profiling decorator that generates kcachegrind output.
import cProfile
import os
import pstats
import time
from datetime import datetime
from functools import wraps
from io import StringIO
from logging import getLogger
logger = getLogger(__name__)
import sys
import os
import imp
class OverlayImporter(object):
def __init__(self, path):
self.path = path
def find_module(self, name, _path=None):
names = name.split('.')
@ionelmc
ionelmc / manhole.py
Last active December 19, 2015 00:49
from __future__ import print_function
from logging import getLogger
logger = getLogger(__name__)
import thread
import threading
import traceback
import socket
import struct
import sys
@ionelmc
ionelmc / timo.py
Last active December 19, 2015 03:09
__all__ = 'TimeMeasurement', 'CummulativeTimeMeasurement', 'MeasurementContext'
from datetime import datetime
from itertools import chain
class MeasurementBase(object):
def __init__(self):
self.stack = []
def __call__(self, event_name):
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
#include <pthread.h>
#include <sys/signalfd.h>
#include <sys/time.h>
#include <sys/types.h>
#define handle_error(msg) \
"""
Converts a dict containing a mongo query to a lambda. Doesn't support all the mongo
query $keywords, probably differs the result in subtle ways.
It only supports querying flat structures: dicts with no lists or other dicts in
them (aka subdocuments).
"""
from __future__ import print_function
import sys
import tempfile
@ionelmc
ionelmc / build.diff
Last active December 20, 2015 23:58
replacing pip bundle with pip wheels
#!/bin/bash -eE
-pip bundle -r requirements.txt --timeout=60 --download-cache=.pip-cache --use-mirrors deps.zip
+(
+ tempdir=$(mktemp -d /tmp/wheelhouse-XXXXX)
+ trap 'rm -rf "$tempdir"' EXIT QUIT
+ pip wheel -r requirements.txt --timeout=60 --download-cache=.pip-cache --use-mirrors --wheel-dir=$tempdir
+ cwd=`pwd`
+ (cd "$tempdir"; tar -cjvf "$cwd/deps.tar.bz2" *)
+)

Reproduce bug run:

pypy pypy-bug.py                                                                                                                                                                                

then:

cat output  

You will see something like: