Skip to content

Instantly share code, notes, and snippets.

View L3viathan's full-sized avatar
🦊

Jonathan Oberländer L3viathan

🦊
View GitHub Profile
@L3viathan
L3viathan / yp.py
Created November 20, 2021 08:45
Python palindrome detector that consists of palindromes. cat yp.py | python yp.py
exec("\n".join(l[:len(l)//2+1].strip().replace("X"," "*4)for l in"""ni l rof)4*" ","X"(ecalper.)(pirts.]1+2//)l(nel:[l(nioj."n\"(cexe
import sysys tropmi
for l in sys.stdin.readlines():)(senildaer.nidts.sys ni l rof
XL=l.rstrip("\\n");print(L==L[::-1])]1-::[L==L(tnirp;)"n\\"(pirtsr.l=LX
))]1-:1[)"n\"(tilps.""".split("\n")[1:-1]))
@L3viathan
L3viathan / tagesschau-redesign.user.css
Created January 27, 2021 09:39
Undo some of the mayhem caused by the recent tagesschau.de redesign.
@-moz-document domain("tagesschau.de") {
.teasergroup {
display: flex;
flex-wrap: wrap;
}
.teaser:not(.teaser--top) {
flex-basis: 50%;
}
\usepackage{xparse}
\ExplSyntaxOn
\NewExpandableDocumentCommand{\cmidrulez}{m}
{
\noalign { \__leviathan_cmidrulez:n { #1 } }
\tl_use:N \g__leviathan_cmidrulez_tl
}
\tl_new:N \g__leviathan_cmidrulez_tl
@L3viathan
L3viathan / redo.py
Created May 4, 2020 19:28
Instead of break or continue, allow to do "redo". Kind-of.
def redoable(iterable):
do_redo = False
def redo():
nonlocal do_redo
do_redo = True
for item in iterable:
yield redo, item
while do_redo:
do_redo = False
yield redo, item
@L3viathan
L3viathan / mailweird.py
Last active November 22, 2019 10:59
Email addresses as valid python
class Mail:
def __init__(self, **bindings):
self.bindings = bindings
def send(self, **bindings):
self.bindings.update(bindings)
return """Sending email with:
{}""".format(
"\n ".join(f"{key}: {val}" for key,
val in self.bindings.items())
)
@L3viathan
L3viathan / composable.py
Created October 8, 2019 11:08
Composable functions
from functools import wraps
def composable(f1):
@wraps(f1)
def wrapper(*args, **kwargs):
if not kwargs and len(args) == 1 and callable(args[0]):
f2 = args[0]
@wraps(f2)
@L3viathan
L3viathan / blackify.vim
Last active March 28, 2019 11:59
black, but as an operator
function! Blackify(type, ...)
let sel_save = &selection
let &selection = "inclusive"
let reg_save = @@
silent exe "'[,']!black --quiet -"
let &selection = sel_save
let @@ = reg_save
endfun
@L3viathan
L3viathan / bindings.py
Last active January 7, 2019 10:19
Metaclass to bake hybrid class/instance binding decorators into subclasses
def bind(clsname, first, second=None):
if second is None: # class binding
cls = globals()[clsname]
fn = first
name = fn.fget.__name__ if isinstance(fn, property) else fn.__name__
setattr(cls, name, fn)
else: # instance binding
self = first
fn = second
name = fn.fget.__name__ if isinstance(fn, property) else fn.__name__
@L3viathan
L3viathan / demo.py
Created August 18, 2018 15:57
Abusing Type Annotations (inspired by zmitchell)
# inspiration: https://tinkering.xyz/abusing-type-annotations/
from __future__ import annotations
from typeanno import restrict
@restrict
class Test:
x: 0 < x < 10
def __init__(self, x):
self.x = x
@L3viathan
L3viathan / curry.py
Last active June 15, 2018 07:13
Currying decorator
from functools import partial
def curry(fn, argcount=None):
if not callable(fn):
return partial(curry, argcount=fn)
argcount = argcount or fn.__code__.co_argcount
if argcount < 2:
return fn
def wrapper(first):
return curry(partial(fn, first), argcount-1)