Skip to content

Instantly share code, notes, and snippets.

@ncode
ncode / gsdproxy.py
Created July 10, 2011 16:01
gevent simple dynamic reverse proxy
#!/usr/bin/env python
from gevent import monkey
monkey.patch_all()
import sys
import redis
import urllib2
import traceback
from cgi import escape
# -- gsdproxy
@inklesspen
inklesspen / README.md
Last active September 6, 2023 17:11
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/

@nvie
nvie / worker_poll.py
Last active April 27, 2018 12:53
Which API is the nicest for the new RQ with concurrency?
# Alt 1: very explicit, but requires knowledge on what type of workers exist
from rq.workers.gevent import GeventWorker
w = GeventWorker(4)
# Alt 2: A bit like an "Abstract Factory", no need for knowing the implementing
# class names, backward compatible, and kind='forking' by default
from rq import Worker
w = Worker(4, kind='gevent')
# Alt 3: I don't think (2) works without really nasty tricks. This one is as
{
"event_id": 10750,
"sensor": {
"name": "snorby.org",
"interface": "eth0",
"id": 0,
"filter": null,
"encoding": null,
"detail": null
},
@jamestbrown
jamestbrown / parse-all-flow.py
Last active October 21, 2016 12:03
Parses SiLK netflow from CERT and dumps JSON objects for elastic search ingest
#!/usr/bin/python
from silk import *
import json
import random
import datetime
import time
def strTimeProp(start, end, format, prop):
stime = time.mktime(time.strptime(start, format))
etime = time.mktime(time.strptime(end, format))
from __future__ import absolute_import
import signal
import gevent
import gevent.pool
from rq import Worker
from rq.timeouts import BaseDeathPenalty, JobTimeoutException
from rq.worker import StopRequested, green, blue
from rq.exceptions import DequeueTimeout
@fabiosantoscode
fabiosantoscode / gist:bcfe7165ca6dd97ba0bf
Last active December 9, 2023 19:46
Reverse tunnel. Connect to a public host somewhere and have it redirect all connections to your machine behind a NAT or firewall
# This enables a publicly available server to forward connections to your computer behind a NAT.
# So if you access http://xx.xx.xx.xx:8080/ on your browser, traffic is redirected to your machine behind a NAT.
# on your local host, type:
ssh -R xx.xx.xx.xx:8888:localhost:80 [email protected]
# now wait for your shell, and type:
socat TCP-LISTEN:8080,FORK TCP:127.0.0.1:8888
# This command outputs nothing, just keep it running. While you don't ^C, your tunnel is up and running!
@wizardjedi
wizardjedi / create-docker-image.sh
Last active August 29, 2015 14:13
Create docker image from OS image
sudo apt-get install debootstrap dchroot
mkdir tmp-os
sudo debootstrap --arch i386 --variant=minbase stable os-tmp http://ftp.debian.org/debian/
sudo chroot os-tmp /bin/bash
apt-get update && apt-get install curl vim mc wget