Skip to content

Instantly share code, notes, and snippets.

View btbytes's full-sized avatar

Pradeep Gowda btbytes

View GitHub Profile
@btbytes
btbytes / couchdb_nginx_rewrite.markdown
Created February 4, 2011 01:27
Couchdb + nginx + rewrite

Three things to remember while configuring a couchapp to run as a web facing application. Below, I document the steps I took to deploy the example pages app from couchapp.org.

  1. set the vhost in /etc/couchdb/local.ini.

    [vhosts] home.btbytes.com = /pages/_design/pages/_rewrite

  2. add vhosts entry to couchdb by visiting configuration page in futon app and adding a new section:

#! /bin/sh
### BEGIN INIT INFO
# Provides: redis-server
# Required-Start: $syslog
# Required-Stop: $syslog
# Should-Start: $local_fs
# Should-Stop: $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: redis-server - Persistent key-value db
### MATPLOTLIBRC FORMAT
# This is a sample matplotlib configuration file - you can find a copy
# of it on your system in
# site-packages/matplotlib/mpl-data/matplotlibrc. If you edit it
# there, please note that it will be overridden in your next install.
# If you want to keep a permanent local copy that will not be
# over-written, place it in HOME/.matplotlib/matplotlibrc (unix/linux
# like systems) and C:\Documents and Settings\yourname\.matplotlib
# (win32 systems).
DL_DIR = "${HOME}/sources"
BBFILES := "/home/stuff/openembedded/recipes/*/*.bb"
# Use the BBMASK below to instruct BitBake to _NOT_ consider some .bb files
# This is a regular expression, so be sure to get your parenthesis balanced.
# BBMASK = "/(nonworking|obsolete)/"
# Comment this if your host distribution does not provide the
# help2man tool.
ASSUME_PROVIDED += "help2man-native"
$ cat bootstrap.sh
#!/bin/sh
cat <<EOF > requirements.txt
whisper==0.9.7
carbon==0.9.7
graphite-web==0.9.7c
gunicorn
EOF
@btbytes
btbytes / kill_idle_pg.sh
Created April 6, 2011 14:17
Kill the oldest postgresql idle transaction if there are more than 5 such processes.
/usr/bin/test `/usr/bin/pgrep -f 'idle in transaction' | \
/usr/bin/wc \-l ` \-gt 5 && /usr/bin/pkill \-o \-f 'idle in transaction'
@btbytes
btbytes / wildcard_dns_sub_domains.mkd
Created April 7, 2011 19:52
WILDCARD DNS AND SUB DOMAINS

#WILDCARD DNS AND SUB DOMAINS

http://ma.tt/2003/10/wildcard-dns-and-sub-domains/

What follows is what I consider to be best practice for my personal sites and a guide for those who wish to do the same. Months ago I dropped the www. prefix from my domain in part because I think it’s redundant and also because I wanted to experiment with how Google treated valid HTTP redirect codes. The experiment has been a great success. Google seems to fully respect 301 Permanent Redirects and the change has taken my previously split PageRank has been combined and now I am at 7. There are other factors that have contributed to this, of course, and people still continue to link to my site and posts with a www. (or worse) in front of it, but overall it just feels so much cleaner to have one URI for one resource, all the time. I’m sure that’s the wrong way to say that, but the feeling is there nonetheless.

Now for the meat. What’s a good way to do this? Let’s look at our goals:

  • No links should break.
  • Visitors should b
def parse_payload(data):
assert data, "Invalid data to parse, it's empty."
length, extra = data.split(':', 1)
length = int(length)
payload, extra = extra[:length], extra[length:]
assert extra, "No payload type: %r, %r" % (payload, extra)
payload_type, remain = extra[0], extra[1:]
assert len(payload) == length, "Data is wrong length %d vs %d" % (length, len(payload))
@btbytes
btbytes / couchdb-tunnel.pl
Created May 17, 2011 15:23
A SysV init script to run a SSH Tunnel. A useful example of using Perl to write init scripts.
#!/usr/bin/perl
# CouchDB Tunnel Tool for MacOS X and Linux
# Copyright (c) 2010 Linode, LLC
# Author: Philip C. Paradis <pparadis@linode.com>
# Modifications: Sam Kleinman <sam@linode.com>
# Usage: couchdb-tunnel.pl [start|stop]
# Access a CouchDB database instance by way of an SSH tunnel.
##
@btbytes
btbytes / bestof_edw519.html
Created May 19, 2011 18:49
The best of edw519
<h2>The Best of edw519</h2>
<h2>A Hacker News Top Contributor</h2>
<p>&nbsp;</p>
<h2>by Ed Weissman</h2>
<p><p /><p /><p /></p>