Skip to content

Instantly share code, notes, and snippets.

@pranavraja
pranavraja / main.go
Created April 29, 2013 10:47
Simple logging HTTP proxy in Go
package main
import (
"fmt"
"github.com/elazarl/goproxy"
"github.com/vrischmann/termcolor"
"log"
"net/http"
)
@pranavraja
pranavraja / README.md
Last active December 16, 2015 09:28
Virtualenv helpers

Assumes pip and virtualenv, and in a project directory with requirements.txt.

Run ./deps to create a virtual environment if needed, and install dependencies from requirements.txt.

Run ./inenv [command] to run a command within the virtualenv (e.g. ./inenv python application.py).

@pranavraja
pranavraja / README
Created December 17, 2012 04:36
HTTP load testing utility in Python
virtualenv .venv --distribute
source .venv/bin/activate
pip install -r requirements.txt
python bench.py http://google.com # Sends 1 request to the googles
@pranavraja
pranavraja / generators.js
Created August 17, 2012 04:33
Node.js generators, inspired by Python
// Generators in node.js
var Generator = function (fn) {
this.results = [];
this.continuations = [];
this.yield = function (val) {
this.results.push(val);
};
this.continue = function (fn) {
@pranavraja
pranavraja / concurrent_test.py
Created August 5, 2012 06:16
Python3 concurrency
# Playing around with the `concurrent.futures` module
# Usage:
# python concurrent_test.py [number_of_requests=10]
#
from __future__ import print_function
from concurrent.futures import ThreadPoolExecutor
import requests
import time
import sys
@pranavraja
pranavraja / progress.py
Created August 2, 2012 10:30
Python progress indicator
import os, sys, time
def _term_width():
return int(os.popen('stty size').read().split()[1])
# `progress` is between 0 and 1
def print_progress_update(progress, pipe=sys.stdout):
width = _term_width() - 3
done = int(progress*width)
pipe.write('\r|%s>%s|' % (done*'=',' '*(width-done)))