Skip to content

Instantly share code, notes, and snippets.

View asfaltboy's full-sized avatar

Pavel Savchenko asfaltboy

View GitHub Profile
@asfaltboy
asfaltboy / foo2.py
Created November 21, 2016 21:37
example of exception raised in daemon thread
from datetime import datetime
from Queue import Queue
import threading
import time
def worker(q):
while True:
item = q.get()
@asfaltboy
asfaltboy / TrelloAPI.json
Last active October 2, 2018 19:48
[WIP]: generated swagger of trello api docs
{
"info": {
"termsOfService": "https://trello.com/legal",
"description": "This document describes the REST API of Trello as published by Trello.com. <a href='https://trello.com/docs/index.html' target='_blank'>Official Documentation</a>",
"license": {
"url": "https://trello.com/legal",
"name": "Trello : Terms of Service"
},
"title": "Trello API",
"contact": {
@asfaltboy
asfaltboy / argparse_email_type.py
Created October 9, 2016 17:48
EmailType: a custom argparse type to validate email addresses
"""
A custom type for argparse, to facilitate validation of email addresses.
Inspired by this SO question: http://stackoverflow.com/questions/14665234/argparse-choices-structure-of-allowed-values
and this gist: https://gist.github.com/gurunars/449edbccd0de1449b71524c89d61e1c5
"""
import re
import argparse
@asfaltboy
asfaltboy / req_to_curl.py
Last active November 23, 2022 14:58
Django HTTP Request to curl command (for replay)
"""
Convert a Django HTTPRequest object (or dictionary of such a request) into a
cURL command.
"""
import json
import sys
required_fields = ['META', 'META.REQUEST_METHOD', 'META.SERVER_NAME', 'META.PATH_INFO']
@asfaltboy
asfaltboy / README.md
Created August 2, 2016 16:04 — forked from inklesspen/README.md
Fast and flexible unit tests with live Postgres databases and fixtures

(This gist is pretty old; I've written up my current approach to the Pyramid integration on this blog post, but that blog post doesn't go into the transactional management, so you may still find this useful.)

Fast and flexible unit tests with live Postgres databases and fixtures

I've created a Pyramid scaffold which integrates Alembic, a migration tool, with the standard SQLAlchemy scaffold. (It also configures the Mako template system, because I prefer Mako.)

I am also using PostgreSQL for my database. PostgreSQL supports nested transactions. This means I can setup the tables at the beginning of the test session, then start a transaction before each test happens and roll it back after the test; in turn, this means my tests operate in the same environment I expect to use in production, but they are also fast.

I based my approach on [sontek's blog post](http://sontek.net/blog/

@asfaltboy
asfaltboy / py-env-guide.rst
Last active September 25, 2016 08:10
Multiple python versions with PyEnv

Multiple python versions

Reasoning and use cases

There are often scenarios when we would need to install multiple versions of python.

On on our development machine, we might want to work on many projects, some using different python versions, or maybe we're working on a package that we want to support on multiple

@asfaltboy
asfaltboy / Instructions.md
Last active October 26, 2017 10:00
Log all cronjob output to syslog and send errors to sentry

Log cronjob output to syslog and send errors to sentry

The wonderful [cron-sentry][1] takes care of sending an event for program errors to sentry. To uniformy log everything outputted, we pipe both stderr and stdout to [logger][2] (should be available on most linux distros)

How to use

Download script, add execution perm and move to a directory on PATH

$ wget https://gist.githubusercontent.com/asfaltboy/23a7f963bbfcb48ce510307ec8cb8737/raw/49ebca20004211a16c85a61a77db7d0883ddf31c/log-and-sentry

$ chmod +x log-and-sentry

@asfaltboy
asfaltboy / processpoolexecutorrequests.log
Last active March 4, 2016 11:46
requests-futures with a ProcessPoolExecutor
# Without callback
2016-03-04 12:43:26,342 - 6782 - DEBUG - root : Executing session.request in child process
2016-03-04 12:43:26,346 - 6782 - DEBUG - root : Executing session.request in child process
2016-03-04 12:43:26,347 - 6782 - DEBUG - root : Executing session.request in child process
2016-03-04 12:43:26,347 - 6782 - DEBUG - root : Executing session.request in child process
2016-03-04 12:43:26,375 - 6823 - INFO - requests.packages.urllib3.connectionpool : Starting new HTTP connection (1): test.dev
2016-03-04 12:43:26,375 - 6824 - INFO - requests.packages.urllib3.connectionpool : Starting new HTTP connection (1): test.dev
2016-03-04 12:43:26,427 - 6824 - DEBUG - requests.packages.urllib3.connectionpool : "GET / HTTP/1.1" 404 None
2016-03-04 12:43:26,428 - 6823 - DEBUG - requests.packages.urllib3.connectionpool : "GET / HTTP/1.1" 404 None
2016-03-04 12:43:26,432 - 6824 - INFO - requests.packages.urllib3.connectionpool : Starting new HTTP connection (1): test.dev
@asfaltboy
asfaltboy / command.js
Last active October 27, 2017 17:15
(Backtick command) Add mono-space shortcut in confluence editor
tinyMCE.activeEditor.addShortcut("ctrl+alt+m","monospace","confMonospace")