Skip to content

Instantly share code, notes, and snippets.

# Python3
>>> try:
... raise ValueError()
... except ValueError:
... raise IndexError()
...
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
ValueError
➜ ~ cat foo.py
x = tuple(set(["a", "b"]))
y = tuple(set(["b", "a"]))
print(x == y)
➜ ~ python3.5 foo.py
False
➜ ~ python3.5 foo.py
False
➜ ~ python3.5 foo.py
True
"""
Example state machine with conditions.
"""
from functools import partialmethod
" Possible states."
WORK = 'Work'
TRAVEL = 'Travel'
"""
Simple module for microservices.
"""
import configparser
import json
import os
from routes import Mapper
import waitress
from functools import partial
import sched
import time
class Scheduler:
"""
A wrapper around a scheduler class providing
a simple API for recurring events.
"""
def make_url(base, *fragments):
"""
>>> make_url('http://example.com', '1', '2', '3.html')
'http://example.com/1/2/3.html'
"""
path = str(pathlib.Path(*fragments))
return urllib.parse.urljoin(base, path)
# Idea shamelessly stolen from pyramid.
# utils.py
from collections import Mapping
from functools import wraps
from flask import has_request_context, render_template
def render_dict_template(template):
"""
Super simple construction free roam RPG.
"""
from itertools import product
import os
import sys
from getch import getch
from random import SystemRandom
random = SystemRandom()
INPUT_FILE = '6944719-tree-sunset-reflection.bmp'
OUTPUT_FILE = 'glitch.bmp'
with open(INPUT_FILE, 'rb') as rh:
with open(OUTPUT_FILE, 'wb') as wh:
>>> a = 1,
>>> assert (1,) == a
>>> a
(1,)
>>> l = []
>>> l.append(a)
>>> l
[(1,)]
>>> l.append(1,)
>>> l