Skip to content

Instantly share code, notes, and snippets.

View thomasballinger's full-sized avatar

Tom Ballinger thomasballinger

View GitHub Profile
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:
class Board(object):
"""
>>> Board().rows
((' ', ' ', ' '), (' ', ' ', ' '), (' ', ' ', ' '))
>>> print Board()
| |
-----
| |
-----
class Trie(object):
"""Simple Trie
>>> t = Trie()
>>> t.add('hi')
>>> t.add('hello')
>>> t.data.keys()
['h']
>>> print t.display(),
def parse_term_state(s):
"""Returns TerminalState tuple given a terminal state diagram
>>> parse_term_state('''
... label
... +-----+
... |ABC |
... +-----+
... |BC |
... |abc@ |
... | |
### current bpython session - file will be reevaluated, ### lines will not be run
class Mapping(object):
def __init__(self):
self.data = []
def add_key_value_pair(self, key, value):
self.data.append([key, value])
def get_value(self, key):
for k, value in self.data:
if k == key:
return value
### current bpython session - file will be reevaluated, ### lines will not be run
class Mapping(object):
def __init__(self):
self.dict = {}
def add_key_value_pair(self, key, value):
self.dict[key] = value
def get_value(self, key):
return self.dict[key]
def remove_key(self, key):
del self.dict[key]
""" Evidence the += method is bad:
In [4]: def plusequals():
...: s = ''
...: for x in 'asdf'*1000:
...: s += x
In [5]: plusequals()
In [6]: def joinmethod():
...: l = 'asdf'*1000