Skip to content

Instantly share code, notes, and snippets.

@fennb
fennb / gist:1124535
Created August 4, 2011 05:04
node.js proxy server in 20 lines of JS (via http://www.catonmat.net/http-proxy-in-nodejs/)
var http = require('http');
http.createServer(function(request, response) {
var proxy = http.createClient(80, request.headers['host'])
var proxy_request = proxy.request(request.method, request.url, request.headers);
proxy_request.addListener('response', function (proxy_response) {
proxy_response.addListener('data', function(chunk) {
response.write(chunk, 'binary');
});
proxy_response.addListener('end', function() {
@fennb
fennb / gist:1124285
Created August 4, 2011 01:05
Bash string manipulation example
#!/bin/bash
MYSTRING="hello there"
STRLEN=${#MYSTRING}
let STARTPOS=$[STRLEN-5]
echo "First 5: ${MYSTRING:0:5}"
echo "Last 5: ${MYSTRING:$STARTPOS:5}"