Skip to content

Instantly share code, notes, and snippets.

# Object-oriented API
#
# Memory usage (iteration, object count, memory size)
# 100 5637 1562216
# 200 5529 1491528
# 300 5422 1426264
# 400 5758 1587376
# 500 5422 1426288
# 600 5416 1440456
# 700 5610 1515056
import gevent
import gevent.pool
class GroupWithExceptionCatching(gevent.pool.Group):
def __init__(self, *args):
super(GroupWithExceptionCatching, self).__init__(*args)
self._error_handlers = {}
def _wrap_errors(self, func):
"""Wrap a callable for triggering error handlers
* Generate classes like WhereNot automatically with class decorator?
* Haskell style deconstruction, perhaps like:
@pmatch
def count(first_arg=Match(x=Head, *xs=Rest)):
print x, xs
Will require some nasty hacks like https://github.com/smcq/python-inject
* Implement boolean operators for stuff like:
@pmatch
@sprig
sprig / pextend.sh
Last active December 19, 2015 14:18
Add a given path component to a given path variable
## Add a given path component ($2) to the given path variable ($1).
pextend ()
{
local pvar=$1
local p=$(eval "echo \$$pvar")
local dname=$2
if [ -d $dname ] ; then
case $p in
*${dname}* ) return ;;
* ) eval "${pvar}=\"${dname}:${p}\"" ;;
@sprig
sprig / reinstall-tree
Created July 20, 2013 17:48
Reinstall the whole tree a given package depends on.
#!/bin/bash
set -o errexit
## Some packages kill the proces sdue to cyclic dependencies, etc.
IGNORE="<[-.a-zA-Z0-9]*> dpkg perl-base libaudit1 libdb5.1"
## User entered packages to search dependencies for.
DEPS=$@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Topmenu and the submenus are based of the example found at this location http://blog.skeltonnetworks.com/2010/03/python-curses-custom-menu/
# The rest of the work was done by Matthew Bennett and he requests you keep these two mentions when you reuse the code :-)
# Basic code refactoring by Andrew Scheller
import curses, os #curses is the interface for capturing key presses on the menu, os launches the files
screen = curses.initscr() #initializes a new window for capturing key presses
curses.noecho() # Disables automatic echoing of key presses (prevents program from input each key twice)
curses.cbreak() # Disables line buffering (runs each key as it is pressed rather than waiting for the return key to pressed)
@sprig
sprig / select-session.sh
Last active December 21, 2015 21:08
Select a tmux session from a given server and attach to it.
## Select a tmux session from a given tmux server and attach to it.
TSERVER=$1
SSTRING=$(if [ $TSERVER ]; then echo "-L $TSERVER"; else echo ""; fi)
SESSIONS=$(tmux $SSTRING ls|sed -E 's/^(.*?): .*/\1/'|xargs echo)
TSERVER=$(if [ $TSERVER ]; then echo $TSERVER; else echo "the default server"; fi)
echo "Available sessions on $TSERVER:"
select opt in $SESSIONS "Quit"; do
case $opt in
@sprig
sprig / .README.md
Created September 10, 2013 19:57 — forked from tarruda/.README.md

Some scripts/configurations that greatly improve tmux/vim workflows. The shell scripts target zsh but should be adaptable without much effort for other unix shells.

Features:

  • Transparently move between tmux panes and vim windows
  • Using the shell, open files in one vim instance per project or directory
  • Fully integrated copy/paste between tmux, vim and x11 using simple keybinds(need to install the xclip program)
  • Easily send text to any tmux pane without breaking your edit workflow(needs slimux

'vim-tmux-move.zsh', '.vimrc' and '.tmux.conf' cooperate so you can move transparently between tmux panes and vim windows using ALT + (arrow keys or jkhl). It was based on this gist

How to inform Eclipse and other Mac applications of the command line PATH

  1. Update Mac OS X's notion of PATH.
$ defaults write ~/.MacOSX/environment PATH "`echo $PATH`"
$ echo "setenv PATH $PATH" | sudo tee /etc/launchd.conf
  1. Restart Mac OS X.
@sprig
sprig / reflect.py
Created March 7, 2014 11:29 — forked from huyng/reflect.py
#!/usr/bin/env python
# Reflects the requests from HTTP methods GET, POST, PUT, and DELETE
# Written by Nathan Hamiel (2010)
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from optparse import OptionParser
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):