Skip to content

Instantly share code, notes, and snippets.

View L3viathan's full-sized avatar
🦊

Jonathan Oberländer L3viathan

🦊
View GitHub Profile
@L3viathan
L3viathan / wurstfact.js
Last active August 29, 2015 14:00
daily wurst fun fact, js edition (v1)
function pickRandomProperty(obj) {
// from http://stackoverflow.com/questions/2532218/pick-random-property-from-a-javascript-object
var result;
var count = 0;
for (var prop in obj)
if (Math.random() < 1/++count)
result = prop;
return result;
}
@L3viathan
L3viathan / SML quine
Last active August 29, 2015 14:01
Shortest SML quine I could come up with
(fn y=>(fn x=>(print(x^y^x^y))))(implode[chr(34)])"(fn y=>(fn x=>(print(x^y^x^y))))(implode[chr(34)])"
@L3viathan
L3viathan / kinox
Last active August 27, 2018 01:38
Using the undocumented kinox.to API, extract stream URLs from a query.
#!/bin/sh
# Get stream URLs for the second episode of the seventh season of futurama:
# kinox.sh futurama 7 2
# for shows with spaces, insert a plus sign instead:
# kinox.sh it+crowd 3 1
# grab the stream by searching for the show on kinox.to, filtering to only show english versions, and extracting the internal show name
export stream_page=$(curl -sL "http://kinox.to/Search.html?q=$1" | pcregrep -M 'lng\/2\.png(\n|.)+?class="Title"' | pcregrep -o1 'Stream\/(.+?)\.html' | head -n 1)
# get the show's page, with the undocumented additional parameters for season and episode, and grab the "rel" attribute of the hoster list
@L3viathan
L3viathan / abdomination.tex
Created January 28, 2015 18:37
Subtly increase the length of a document by 15–20%
\clubpenalty = 10000·
\widowpenalty = 10000·
\displaywidowpenalty = 10000
\setlength\parindent{2.5em}
\setlength\parskip{0.3\baselineskip}·
\usepackage{geometry}
\addtolength{\oddsidemargin}{.3in}
@L3viathan
L3viathan / multichat
Created May 24, 2015 17:37
Request for Comments: Rules and Operators for multi-level chat communication
[version 1.1]
Chatting happens in different levels, which allows for multi-threaded conversations.
The different conversation levels are marked with a number of parantheses.
Example 1:
A: How are you?
A: (And how is your family?)
B: Fine (and fine, too).
@L3viathan
L3viathan / nummagic.py
Created January 5, 2016 14:51
Shenanigans abusing magic methods
import random
import math
class Num(object):
def __init__(self, val):
self.value = val
self.bit = False
def __repr__(self):
return str(self.value)
def __abs__(self):
return self
@L3viathan
L3viathan / gettermagic.py
Last active August 31, 2016 07:02
Horrible abuse of Python's magic methods to make a more magic version of itemgetter/attrgetter
import operator as op
from functools import partial
class _getter(object):
def __init__(self, *, is_original=True):
self.is_original=is_original
self.__ops = []
def __call__(self, something):
''' Maybe eventually extend to act like methodcaller, but problems exist'''
@L3viathan
L3viathan / .block
Created September 18, 2017 11:47 — forked from mbostock/.block
Labeled Force Layout
license: gpl-3.0
@L3viathan
L3viathan / weighted_edit_distance.py
Created September 21, 2017 14:55
Super-simple length-independent word-based Levenshtein distance
def weighted_distance(x, y):
x, y = x.split(), y.split()
length = len(x+y)/2
return editdistance.eval(x, y)/length
@L3viathan
L3viathan / README.md
Created December 15, 2017 20:08
Underhanded Python

Underhanded Python

To test:

>>> from underhanded import login
>>> login("l3viathan", "12345678")
0