This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def switch(item): | |
two = Default() | |
one = Case(item, two) | |
return (one, two) | |
class Case(object): | |
def __init__(self, item, default): | |
self.default = default | |
self.skip = False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Credit to daviddonna for most of this. | |
import inspect | |
def continuation(f): | |
def helper(f, args): | |
count = len(inspect.getargspec(f).args) | |
if len(args) == count: | |
return f(*args) | |
elif len(args) < count: | |
return lambda x, *eargs: helper(f, args + (x,) + tuple(eargs)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# http://stackoverflow.com/questions/11195140/python-break-or-exit-out-of-with-statement/23665658#23665658 | |
class fragile(object): | |
class Break(Exception): | |
"""Break out of the with statement""" | |
def __init__(self, value): | |
self.value = value | |
def __enter__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
[ | |
{ "keys": ["super+f"], "command": "show_panel", "args": {"panel": "find", "toggle": true} }, | |
{ "keys": ["shift+tab"], "command": "unindent"}, | |
{ "keys": ["super+g"], "command": "show_overlay", "args": {"overlay": "goto", "text": ":"} }, | |
{ "keys": ["ctrl+tab"], "command": "next_view" }, | |
{ "keys": ["ctrl+shift+tab"], "command": "prev_view" }, | |
{ "keys": ["super+h"], "command": "show_panel", "args": {"panel": "replace"} }, | |
{ "keys": ["super+shift+o"], "command": "prompt_add_folder"}, | |
{ "keys": ["super+shift+r"], "command": "toggle_setting", "args": {"setting": "word_wrap"}}, | |
{ "keys": ["tab"], "command": "indent", "context": |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python2.7 | |
import collections | |
import os | |
import re | |
import readline | |
import subprocess | |
tty_bold = '\x1b[1m' | |
tty_af = '\x1b[{}m'.format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
def slice_when(iterable, predicate): | |
""" | |
Chunk `iterable` between elements that satisfy `predicate`. | |
This method splits each chunk by passing adjacent elements from the iterable into `predicate`. | |
Splits occur where `predicate` returns true for adjacent elements. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
branch_name=$(git rev-parse --abbrev-ref HEAD) | |
if [[ "$branch_name" == "master" ]]; then | |
git branch --merged | grep -v "\*" | xargs -n 1 git branch -d | |
echo "Done!" | |
else | |
echo "Must be on master, not $branch_name!" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try: | |
y = reversed(enumerate(range(5, 15, 2))) | |
except TypeError: | |
print("A problem.") | |
class enumerate(enumerate): | |
def __init__(self, iterable, start=0): | |
self.iterable = iterable | |
self.start = start |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print("Oh crap") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import plusplus | |
import module | |
module.main() |
OlderNewer