Skip to content

Instantly share code, notes, and snippets.

@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/[email protected]/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 <[email protected]>
# 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

GitHub Javascript Strategy

Unless otherwise necessary (such as mobile development), the GitHub javascript codebase is based off jQuery. You can safely assume it will be included on every page.

File naming

  • All jquery plugins should be prefixed with jquery, such as jquery.facebox
  • All github-specific jquery plugins should be prefixed with jquery.github. Like jquery.github.repo_list.js
  • All page-specific files (that only run on ONE page) should be prefixed with page. page.billing.js
"""
Emulating Ruby-style code blocks in Python.
This example was demonstrated in the PyCon'10 talk titled "Python Metaprogramming".
"""
import sys
import types
def receive_block(func):
"""
Simple python program demonstrating how certain blocking syscalls can be offloaded to a thread-pool and
then be able to fetch the results from these system calls in a non-blocking way by doing select() on
a pipe between the main thread and the threads in the pool.
This is the technique being used by node.js to offer a unified non-blocking Javascript API even for
things like file I/O which is traditionally done via blocking syscalls. This idea was described by
Ryan Dahl at JSConfEU 2009.
-- Harish Mallipeddi - Dec 3 2009
#! /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