Skip to content

Instantly share code, notes, and snippets.

View milesrout's full-sized avatar

Miles Rout milesrout

View GitHub Profile
@milesrout
milesrout / gist:1264e8af3ce3b47200ca6f21a0b96bd9
Last active August 24, 2017 07:15
Variable-length encoding of integers up to 64-bit integer encoding - worst case is an extra byte for numbers over 2^56. I plan to use this for string length-prefixing, so that's just never ever relevant.
0xxxxxxx 7
10xxxxxx xxxxxxxx 14
110xxxxx xxxxxxxx xxxxxxxx 21
1110xxxx xxxxxxxx xxxxxxxx xxxxxxxx 28
11110xxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx 35
111110xx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx 42
1111110x xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx 49
11111110 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx 56
11111111 xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx xxxxxxxx 64
{(a ^ b)} |- (a ^ b):
(assume (a ^ b))
{(a ^ (b ^ c))} |- ((a ^ b) ^ c):
(conj-intro
(conj-intro
(conj-elim-l (assume (a ^ (b ^ c))))
(conj-elim-l (conj-elim-r (assume (a ^ (b ^ c))))))
(conj-elim-r (conj-elim-r (assume (a ^ (b ^ c))))))
* Error: The above package list contains packages which cannot be
* installed at the same time on the same system.
(dev-util/gdbus-codegen-2.50.3:0/0::gentoo, ebuild scheduled for merge) pulled in by
dev-util/gdbus-codegen required by (gnome-base/gvfs-1.30.4:0/0::gentoo, ebuild scheduled for merge)
>=dev-util/gdbus-codegen-2.48 required by (x11-libs/gtk+-3.22.15:3/3::gentoo, ebuild scheduled for merge)
(dev-libs/glib-2.52.2:2/2::gentoo, ebuild scheduled for merge) pulled in by
>=dev-libs/glib-2.40:2=[dbus] required by (sys-auth/consolekit-1.1.0-r1:0/0::gentoo, installed)
>=dev-libs/glib-2.38.2-r1:2[abi_x86_32(-)?,abi_x86_64(-)?,abi_x86_x32(-)?,abi_mips_n32(-)?,abi_mips_n64(-)?,abi_mips_o32(-)?,abi_ppc_32(-)?,abi_ppc_64(-)?,abi_s390_32(-)?,abi_s390_64(-)?]
from math import sqrt
class Dedent:
@classmethod
def method(cls, f=None, *, name=None):
def decorator(f):
setattr(cls, name if name is not None else f.__name__, f)
if f is not None:
decorator(f)
else:
(define (do-read sock n)
(linux/do-syscall 'read (sock n 'linux/onoblock)))
(define (read sock n)
(let ((result (do-read sock n)))
(if (equal? result 'linux/ewouldblock)
(call-with-current-continuation
(lambda (cc)
(wait sock cc))
result)))
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
milesrout@mac:~ $ python3
Python 3.6.0 (default, Dec 24 2016, 08:01:42)
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.42.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> f = open('DATA.txt', 'r')
>>> data = f.read()
>>> data
'01011001 01101111 01110101 00100000\n01101010 01110101 01110011 01110100\n00100000 01110111 01100001 01110011\n01110100 01100101 01100100 00100000\n01111001 01101111 01110101 01110010\n00100000 01110100 01101001 01101101\n01100101 00101110\n'
>>> data.split()
['01011001', '01101111', '01110101', '00100000', '01101010', '01110101', '01110011', '01110100', '00100000', '01110111', '01100001', '01110011', '01110100', '01100101', '01100100', '00100000', '01111001', '01101111', '01110101', '01110010', '00100000', '01110100', '01101001', '01101101', '01100101', '00101110']
from typing import Iterable, Pattern
def scanner(src: string, regexes: Iterable[(str, Pattern)]) -> Iterable[(string, string)]:
"""Takes source code, and a list of tuples of the form (token_name,
token_regex). Yields pairs (token_name, token_literal)."""
import x
from y import x
from a.z.b import q
from .....a import q
from x import (a, b, c, d)
import a, b, z, d, fe, q
import a.ce, efa.f, ae.e
def hello(world):
def foo():
import x
from y import x
from a.z.b import q
from .....a import q
from x import (a, b, c, d)
import a, b, z, d, fe, q
import a.ce, efa.f, ae.e
def hello(world):
def foo():