Skip to content

Instantly share code, notes, and snippets.

@sramam
sramam / Http-Header-Map
Created October 27, 2012 13:22
Http headers - lowercase to Http-Headercase maps. Useful to map headers from node.js to other servers.
// Http Headers listed at http://en.wikipedia.org/wiki/List_of_HTTP_header_fields
var http_headers = ["Accept",
"Accept-Charset",
"Accept-Encoding",
"Accept-Language",
"Accept-Datetime",
"Authorization",
"Cache-Control",
"Connection",
"Cookie",
function http_case(header) {
var map = {"accept":"Accept","accept-charset":"Accept-Charset","accept-encoding":"Accept-Encoding","accept-language":"Accept-Language","accept-datetime":"Accept-Datetime","authorization":"Authorization","cache-control":"Cache-Control","connection":"Connection","cookie":"Cookie","content-length":"Content-Length","content-md5":"Content-MD5","content-type":"Content-Type","date":"Date","expect":"Expect","from":"From","host":"Host","if-match":"If-Match","if-modified-since":"If-Modified-Since","if-none-match":"If-None-Match","if-range":"If-Range","if-unmodified-since":"If-Unmodified-Since","max-forwards":"Max-Forwards","pragma":"Pragma","proxy-authorization":"Proxy-Authorization","range":"Range","referer":"Referer","te":"TE","upgrade":"Upgrade","user-agent":"User-Agent","via":"Via","warning":"Warning","x-requested-with":"X-Requested-With","dnt":"DNT","x-forwarded-for":"X-Forwarded-For","x-forwarded-proto":"X-Forwarded-Proto","front-end-https":"Front-End-Https","x-att-deviceid":"X-ATT
@sramam
sramam / gist:5210145
Created March 21, 2013 02:00
checkmyip from the command line
curl -s -S http://checkip.dyndns.org | sed -n -e 's/.*Current IP Address: \([^<]*\)<.*/\1/p'
@sramam
sramam / gist:8056254
Created December 20, 2013 15:22
Python script that computes the git sha1 value, commandlinized
def git_sha1(fname):
import hashlib
with open(fname, 'r') as f:
data = f.read()
sha1 = hashlib.sha1()
sha1.update("blob %d\0%s" % (len(data), data))
return sha1.hexdigest()
@sramam
sramam / gist:8714322
Created January 30, 2014 17:44
Javascript passing by copy of reference, a simple test across closure.
var CL = function(){
config = {
field: {
key: []
}
},
add_val = function(val) {
config.field.key.push(val)
}
return {
@sramam
sramam / gist:9114208
Created February 20, 2014 14:01
installing python 2.7 on centos63
#!/bin/sh
set -e
mkdir -p ~/opt
cd ~/opt
yum groupinstall -y "Development tools"
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel
set -e
@sramam
sramam / gist:1e31b3ff9ceab38f2962
Created May 7, 2014 15:15
shell script - colored text
red='\033[0;31m'
green='\033[0;32m'
NC='\033[0m' # No Color
echo -e "${green}Some message${NC}"
@sramam
sramam / gist:9c63c6f16a871e4d7127
Created May 7, 2014 15:18
capture output of a command/script and colorize it on error
set -e
color()(set -o pipefail;"$@" 2>&1>&3|sed $'s,.*,\e[31m&\e[m,'>&2)3>&1
color script_cmd_to_run $*
@sramam
sramam / gist:6943cc3ed195f5ee3f53
Created May 7, 2014 15:18
bash directory of current script
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
@sramam
sramam / gist:4bf77853d1327e3100f6
Created May 12, 2014 16:07
Basic django app + management command configured.
rm -rf djtest
mkdir djtest
cd djtest
virtualenv .
source bin/activate
pip install django
django-admin.py startproject djtest .
django-admin.py startapp djapp1 .
mkdir -p djapp1/management/commands
touch djapp1/management/__init__.py