Skip to content

Instantly share code, notes, and snippets.

Louis Warren louisswarren

Block or report user

Report or block louisswarren

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@milesrout
milesrout / characters.py
Created Mar 26, 2018
Gives the characters of any literary work
View characters.py
print(__import__('random').choice(__import__('sys').stdin.read().strip()))
@louisswarren
louisswarren / clarinet.py
Last active Jun 1, 2017
A clarinet is a pipe with a reed; clarinet.py reads from a named pipe.
View clarinet.py
#!/usr/bin/env python3
import os
import sys
import textwrap
import time
def usage():
print(textwrap.dedent("""
Usage: {} <pipepath>
@louisswarren
louisswarren / lazydict.py
Last active Sep 18, 2017
Lazily evaluated dictionary generator
View lazydict.py
class LazyDict:
'''Use a 2-tuple generator as a lazily-evaluated dictionary.'''
def __init__(self, gen):
self.gen = gen
self.dict = {}
def _generate_to(self, key):
while key not in self.dict:
found_key, found_val = next(self.gen)
self.dict[found_key] = found_val
@louisswarren
louisswarren / open.py
Created May 15, 2017
Search for a file and open it with xdg-open
View open.py
#!/usr/bin/env python3
import re
import subprocess
import sys
if len(sys.argv) < 2:
print("Usage: {} <findregex> [pythonregex]...")
sys.exit()
View testable.py
import builtins
def testable(f):
def run_test(test):
print(test.__doc__)
args = {name: value for (name, value) in test.__annotations__.items()
if name != 'return'}
assert f(**args) == test.__annotations__['return']
return test
f.test = run_test
@louisswarren
louisswarren / edrename.py
Last active Feb 5, 2018
Batch rename files using your editor
View edrename.py
#!/usr/bin/env python3
import os
import subprocess
import tempfile
EDITOR = os.environ.get('EDITOR', 'vim')
def input_new_names(old_names):
with tempfile.NamedTemporaryFile(suffix='.tmp') as fname_file:
@louisswarren
louisswarren / youtube-terminal.py
Last active May 11, 2017
Play audio from a youtube search in the terminal
View youtube-terminal.py
#!/usr/bin/env python3
from os import system
from sys import argv
# Example:
# youtube-terminal.py foo bar baz
# calls youtube-dl 'ytsearch:foo bar baz' --max-downloads 1 -o - | cvlc - --no-video
call_str = 'youtube-dl "ytsearch:{}" --max-downloads 1 -o -'
call_str += ' | cvlc - --no-video --play-and-exit'
@louisswarren
louisswarren / easy_passwords.py
Last active May 24, 2018
Generate passwords which are easy to type
View easy_passwords.py
# Generate passwords which can be typed without using any finger to press two
# different keys in a row.
# For each finger, write the letters *you* type with that finger.
finger_classes = [
'qaz',
'wsx',
'edc',
'rfvtgbc',
'yhnujmb',
View pyaccum.py
import functools
def accumulate(accum_type):
def outer_wrapper(f):
@functools.wraps(f)
def inner_wrapper(*args, **kwds):
return accum_type(iter(f(*args, **kwds)))
return inner_wrapper
return outer_wrapper
You can’t perform that action at this time.