Skip to content

Instantly share code, notes, and snippets.

@maxcountryman
maxcountryman / kaa.py
Created November 15, 2010 01:35
A very simple non-blocking IRC bot using gevent
import gevent
from gevent import socket, queue
from gevent.ssl import wrap_socket
import logging
logger = logging.getLogger('irc')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
(defun search-all-buffers (regexp prefix)
"Searches file-visiting buffers for occurence of REGEXP. With
prefix > 1 (i.e., if you type C-u \\[search-all-buffers]),
searches all buffers."
(interactive (list (grep-read-regexp)
current-prefix-arg))
(message "Regexp is %s; prefix is %s" regexp prefix)
(multi-occur
(if (member prefix '(4 (4)))
(buffer-list)
"""The :mod:`zmq` module wraps the :class:`Socket` and :class:`Context` found in :mod:`pyzmq <zmq>` to be non blocking
"""
__zmq__ = __import__('zmq')
from gevent.hub import _threadlocal
from gevent.socket import wait_read, wait_write
__patched__ = ['Context', 'Socket']
globals().update(dict([(var, getattr(__zmq__, var))
for var in __zmq__.__all__
if not (var.startswith('__')
@karussell
karussell / backup.sh
Created July 10, 2011 20:05
Backup ElasticSearch with rsync
# TO_FOLDER=/something
# FROM=/your-es-installation
DATE=`date +%Y-%m-%d_%H-%M`
TO=$TO_FOLDER/$DATE/
echo "rsync from $FROM to $TO"
# the first times rsync can take a bit long - do not disable flusing
rsync -a $FROM $TO
# now disable flushing and do one manual flushing
@zacharyvoase
zacharyvoase / dynerror.py
Created February 10, 2012 01:15
Can't believe how hacky this is. Can't believe it kinda works.
"""
Dynamic pattern matching in except clauses.
You can use `ABCMeta` and `__subclasshook__` to implement pattern matching in
except clauses. For this demo we're doing two things: first, we're creating
exception classes dynamically by overridding `__getattr__` on a metaclass,
which itself inherits from `abc.ABCMeta`. This allows us to do this:
>>> Errno
<class 'dynerror.Errno'>
@schmir
schmir / setup-gevent-dotgit
Created February 12, 2012 13:51
helper script for gevent git repository
#! /bin/sh
# helper script for gevent .git repository
# setup private ignore file and a custom script to build a versioned sdist
test -e gevent/__init__.py -a -e .git || exit "run this inside the gevent git repository"
cat >.git/make-sdist <<'EOF'
#! /bin/sh -e
test -e gevent/__init__.py -a -e .git || exit "run this inside the gevent git repository"
@flub
flub / greenlet_issue14_test.py
Created June 21, 2012 09:10
Demo script which makes greenlet raise SystemError
import random
import sys
import threading
import time
import dpkt
import eventlet
import eventlet.xthread
from eventlet.green import socket
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@agleyzer
agleyzer / gist:3859749
Created October 9, 2012 16:04
Download infoq video
#!/usr/bin/env python
# Looking for MP4 videos in infoq content.
#
# <div style="width: 320px; height: 265px; float: left; margin-right: 10px;">
# <video poster="/styles/i/logo_scrubber.png" id="video" controls="controls" width="320" height="265">
# <source src="http://d1snlc0orfrhj.cloudfront.net/presentations/12-mar-lockfreealgorithms.mp4" />
# </video>
# </div>
anonymous
anonymous / gist:3931398
Created October 22, 2012 12:59
from twisted.trial.unittest import TestCase
from twisted.internet.defer import Deferred
from twisted.internet import reactor
class TestWhyDoesThisWork(TestCase):
def test_return_deferred_pass(self):
d = Deferred()
d.addCallback(self.assertEqual, 10)
reactor.callLater(0.1, d.callback, 10)