Skip to content

Instantly share code, notes, and snippets.

@yashh
yashh / demo.py
Created June 21, 2011 03:26 — forked from ericmoritz/demo.py
webtail
import eventlet
from eventlet import GreenPool
from eventlet.green import urllib2
import logging
log = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)
class Reader(object):
def __init__(self, i):
@yashh
yashh / nginx
Created May 7, 2011 07:39
Nginx proxy configuration to proxy requests to different backends and init script to start nginx
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
@yashh
yashh / nginx.conf
Created April 27, 2011 04:12
nginx conf
user www-data www-data;
worker_processes 2;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
@yashh
yashh / countries.txt
Created April 27, 2011 03:46
A list of countries to use for forms
# Written by Alisdair Sullivan
STATE_OR_PROVINCE_CHOICES = [
('AB', 'Alberta'),
('BC', 'British Columbia'),
('MB', 'Manitoba'),
('NB', 'New Brunswick'),
('NL', 'Newfoundland'),
('NS', 'Nova Scotia'),
('NT', 'Northwest Territories'),
@yashh
yashh / SSH Terminal Colors
Created January 10, 2011 20:49
Automatically set your terminal color upon SSH to a host
# Full credit to: http://jeffmiller.github.com/2011/01/10/ssh-host-color
#!/bin/bash
#
# ssh into a machine and automatically set the background
# color of Mac OS X Terminal depending on the hostname.
#
# Installation:
# 1. Save this script to /some/bin/ssh-host-color
# 2. chmod 755 /some/bin/ssh-host-color
@yashh
yashh / gunicorn vs bjoern
Created December 24, 2010 07:26
Benchmark a flask hello world app
apt-get install python-setuptools python-pip
pip install Flask gunicorn
ab -n 5000 -c 50 http://ec2-50-16-28-212.compute-1.amazonaws.com/
worker = 1
Concurrency Level: 50
Time taken for tests: 53.365 seconds
@yashh
yashh / Python force_unicode
Created December 14, 2010 02:55
pulled from django
def force_unicode(s, encoding='utf-8', errors='ignore'):
"""
Returns a unicode object representing 's'. Treats bytestrings using the
'encoding' codec.
"""
import codecs
if s is None:
return ''
try:
@yashh
yashh / Solr EdgeNGramFilterFactory
Created October 25, 2010 22:31
Using Solr to perform substring match right from start of a word
## http://www.mail-archive.com/solr-user@lucene.apache.org/msg31768.html
Hi Ahmet,
Well after some more testing I am now convinced that you rock :)
I like the solution because its obviously way less hacky and more importantly I
expect this to be a lot faster and less memory intensive, since instead of a
facet prefix or terms search, I am doing an "equality" comparison on tokens
(albeit a fair number of them, but each much smaller). I can also have more
control over the ordering of the results. I can also make full use of the
#
# bash completion support for core Git.
#
# Copyright (C) 2006,2007 Shawn O. Pearce <spearce@spearce.org>
# Conceptually based on gitcompletion (http://gitweb.hawaga.org.uk/).
# Distributed under the GNU General Public License, version 2.0.
#
# The contained completion routines provide support for completing:
#
# *) local and remote branch names
#!/usr/bin/python
import os
from datetime import date
pem_file = '/path/to/file.pem'
cert_file = '/path/to/cert-file.pem'
user_id = 'xxxxxxxx'
platform = 'i386' # change this on large instance