Skip to content

Instantly share code, notes, and snippets.

@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)))
@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 / 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 / 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 / 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 / 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 / objcmethods.py
Created May 31, 2013 01:59
Count length of methods in iOS codebases
import sys
from collections import defaultdict
def name_of_method(signature):
start_method_name = signature.find(')') + 1
end_method_name = signature.rfind('{')
return signature[start_method_name:end_method_name]
if __name__ == '__main__':
if len(sys.argv) <= 1:
@pranavraja
pranavraja / main.go
Last active December 20, 2015 07:39
Caching proxy for the npm registry
package main
import (
"github.com/golang/groupcache"
"github.com/gorilla/mux"
"github.com/pranavraja/front/cache"
"bytes"
"flag"
"io/ioutil"
@pranavraja
pranavraja / main.go
Created February 27, 2014 03:32
Go proxy server
package main
import (
"flag"
"fmt"
"io"
"net/http"
"net/url"
"strings"
)
@pranavraja
pranavraja / main.go
Created June 12, 2014 08:30
Environment variable helper
// Build this using `go build` and put it in your PATH
package main
import (
"encoding/json"
"os"
"os/exec"
"strings"
)