Skip to content

Instantly share code, notes, and snippets.

import tty
import termios
import sys
class Cbreak(object):
def __enter__(self):
self.original_stty = termios.tcgetattr(sys.stdin)
tty.setcbreak(sys.stdin, termios.TCSANOW)
#!/usr/bin/env python
import socket
listener = socket.socket()
listener.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listener.bind(('', 8000))
listener.listen(5)
while True:
def preview(content):
import webbrowser
import tempfile
import time
with tempfile.NamedTemporaryFile(suffix='.html') as f:
f.write(content)
f.flush()
print f.name
webbrowser.open_new_tab('file://'+f.name)
time.sleep(1)
import re
def tokenize(s):
"""
>>> tokenize("(1.1 + 2 * 3)")
['(', '1.1', '+', '2', '*', '3', ')']
"""
return re.findall("[0123456789.a-zA-Z]+|[*+/\-()=]", s)
#!/usr/bin/env python2
import sys
import urllib2
import json
def do_gist_json(s):
""" Use json to post to github. """
gist_public = False
gist_url = 'https://api.github.com/gists'
import random
def write_data(filename, num_bytes=1000000):
with open(filename, 'w') as f:
for _ in range((num_bytes / 1000) + 1):
f.write(''.join(random.choice('ab') for _ in range(1000)))
def read_chunks(filename, num_bytes=1000):
with open(filename, 'r') as f:
while True:
set-option -g default-command "reattach-to-user-namespace -l bash; echo running default command now"
unbind C-b
# I'm tempted to use C-a, but I want 'beginning of line'
set -g prefix C-q
bind-key q send-prefix
bind-key C-q send-prefix
set -g history-limit 1000000
@thomasballinger
thomasballinger / readline.diff
Created February 2, 2015 22:36
Readline diff for undo
diff --git a/libreadline.a b/libreadline.a
index 904a7ab..6c0aec9 100644
Binary files a/libreadline.a and b/libreadline.a differ
diff --git a/readline.c b/readline.c
index 3550b35..8c0a221 100644
--- a/readline.c
+++ b/readline.c
@@ -301,7 +301,7 @@ rl_set_prompt (prompt)
/* Read a line of input. Prompt with PROMPT. An empty PROMPT means
none. A return value of NULL means that EOF was encountered. */
import asyncio
import urllib.parse
import sys
import os
from oldchat import CharacterAtATime
def red_on_blue(msg):
sys.stdout.write('\x1b[31m\x1b[44m' + msg + '\x1b[49m\x1b[39m')
sys.stdout.flush()
import random
def write_data(filename, num_bytes=1000000):
with open(filename, 'w') as f:
for _ in range((num_bytes / 1000) + 1):
f.write(''.join(random.choice('ab') for _ in range(1000)))
def read_chunks(filename, num_bytes=1000):
with open(filename, 'r') as f:
while True: