Skip to content

Instantly share code, notes, and snippets.

View L3viathan's full-sized avatar
🦊

Jonathan Oberländer L3viathan

🦊
View GitHub Profile
@L3viathan
L3viathan / conceal-type-hints.vim
Last active August 19, 2022 12:21
Conceal type hints
set conceallevel=2
syntax match Normal '\v ?(:|-\>) ?[^,):]+' conceal
" this doesn't always work, only with simple types (not stuff with commas in them)
" if you know how to deal with those (virtual text?), tell me please
@L3viathan
L3viathan / pass.py
Created February 4, 2022 22:10
body-free loops :)
for type(
type.__name__,
(),
{
type.__name__: type(
type.__name__,
(),
{
"__{0}__".format(
type({0}).__name__
import fishhook
split_map = {"w": "v"}
@fishhook.hook(str)
def __getitem__(self, something):
if not isinstance(something, slice):
return fishhook.orig(self, something)
start, stop, step = something.start, something.stop, something.step
split_start = start % 1 == 0.5 if start else False
@L3viathan
L3viathan / atomic_contextmanager.py
Last active May 2, 2024 11:49
Go backwards in time when something went wrong
import os
import sys
import inspect
import signal
from contextlib import contextmanager
def _kill_self(signum, frame):
os._exit(0)
@contextmanager
@L3viathan
L3viathan / alias_of.py
Created December 14, 2021 23:39
Class attribute aliases
class AliasableMeta(type):
aliases = {}
class Aliasable(metaclass=AliasableMeta): pass
class AliasOfMeta(type):
def __getattr__(self, value):
return self(value)
class alias_of(metaclass=AliasOfMeta):
def __init__(self, other=None):
@L3viathan
L3viathan / demo.py
Created November 24, 2021 19:50
Allow changing tuple elements
>>> import mutable_tuples
>>> t = (1, 2, 3)
>>> t[1] = 23
>>> t
(1, 23, 3)
@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