Skip to content

Instantly share code, notes, and snippets.

View sumeet's full-sized avatar

Sumeet Agarwal sumeet

  • San Francisco, CA
View GitHub Profile
@sumeet
sumeet / hello_timer.py
Created June 1, 2010 05:58
An artie timer example.
from artie.applications import timer
@timer(10)
def hi(irc):
"""
Sends a message to every channel the bot is in every 10 seconds.
"""
for channel in irc.channels:
irc.msg(channel, 'hi i am artie')
@sumeet
sumeet / find.py
Created July 11, 2010 17:47
Python find
import os
import re
def find(expression, path='.', type='df'):
"""
Find files or directories.
>>> list(find(r'.*\.py$', type='f'))
['./find.py']
"""
@sumeet
sumeet / mate-server.py
Created September 14, 2010 00:29
TextMate over sshfs server and client
#!/usr/bin/env python
"""
HTTP server listens for GET requests on `PORT` with query *filename* and
opens *~/filename* with TextMate.
"""
import BaseHTTPServer
import os
import urlparse
@sumeet
sumeet / highlight.py
Created November 6, 2010 00:53
Highlight terms in stdin with different colors.
#!/usr/bin/env python
"""
# highlight
Highlight terms in stdin with different colors.
Example usage:
$ tail -f /some/log_file | highlight batch3 slave master darwin
"""
@sumeet
sumeet / gist:723145
Created December 1, 2010 08:05
String concatenation in CPython 2.7 and PyPy 1.4
(12:01a) (sumeet@shanoa:~)$ `which python2.7` ./timethese.py string_concat.py 10000000
# Running code block #1
assert ''.join(('abc', 'def', 'ghi')) == 'abcdefghi'
Took 2.855692 seconds to run 10000000 times.
# Running code block #2
assert 'abc' + 'def' + 'ghi' == 'abcdefghi'
@sumeet
sumeet / clipboarder.go
Created March 30, 2011 23:17
Copy remote Vim's visual selections to a remote Mac.
package main
import (
"http"
"exec"
)
func Copy(response http.ResponseWriter, request *http.Request) {
@sumeet
sumeet / gist:939527
Created April 24, 2011 12:53
A scripted test in the new artie
class PRIVMSGTestCase(IRCClientTestCase):
"""Test a garbage response to a private message.
SERVER: :Angel!wings@irc.org PRIVMSG Wiz :Are you receiving this message ?
CLIENT: u said "Are you receiving this message ?"
"""
@sumeet
sumeet / stopwatch.py
Created August 3, 2011 21:48
A Python timer class.
import time
class Stopwatch(object):
"""A stopwatch utility for timing execution that can be used as a regular
object or as a context manager.
NOTE: This should not be used an accurate benchmark of Python code, but a
way to check how much time has elapsed between actions. And this does not
account for changes or blips in the system clock.
@sumeet
sumeet / important.vim
Created January 27, 2012 02:59
Super important.
" for typos
map :W :w
map :E :e
@sumeet
sumeet / go_away_help.vim
Created February 18, 2012 00:55
For crappy keyboards.
map <F1> <Esc>
imap <F1> <Esc>