Skip to content

Instantly share code, notes, and snippets.

@Aran-Fey
Aran-Fey / good_lru_cache.py
Last active January 8, 2018 22:15
lru_cache that interacts correctly with default parameters
import functools, inspect
def proper_cache(*lru_args, **lru_kwargs):
def deco(func):
signature = inspect.signature(func)
# if the function has no default parameters, return a normal lru_cache
if all(p.default is inspect.Parameter.empty for p in signature.parameters.values()):
import sys
import inspect
import re
def called_with_wrong_args(func, locals=None, exc_info=None):
"""
Finds out whether an exception was raised because invalid arguments were passed to a function.
@Aran-Fey
Aran-Fey / auto-__all__.py
Created February 19, 2018 18:14
Auto-detects objects defined in the current module and generates a suitable `__all__`-list.
"""
Auto-detects objects defined in the current module and generates a
suitable `__all__`-list.
Must be called at the bottom of the file, after everything has been defined.
"""
import sys
import types
import inspect
@Aran-Fey
Aran-Fey / SO_dupehammer_stopwatch.user.js
Last active May 9, 2018 09:37
A userscript that displays how long it took for a StackOverflow question to be closed as a duplicate.
// ==UserScript==
// @name StackOverflow hammer stopwatch
// @description Displays how long it took for a question to be closed as duplicate
// @version 1.2
// @author Paul Pinterits
// @include *://*.stackexchange.com/questions/*
// @include *://meta.serverfault.com/questions/*
// @include *://meta.stackoverflow.com/questions/*
// @include *://meta.superuser.com/questions/*
// @include *://serverfault.com/questions/*
@Aran-Fey
Aran-Fey / simple_video_transcoder_gui.py
Created May 9, 2018 16:50
A very, very simple GUI that lets you transcode videos/gifs. Depends on ffmpeg, which must either be installed or dropped in the same directory as this script. If you want to work with gifs, also install gifsicle in the same manner.
debug = False
debug_output = False
def dbg(*args):
if not debug:
return
print(*args)
import os
// ==UserScript==
// @name SE reorder favorite tags
// @version 1.0.1
// @description Allows you to reorder your favorite tags with drag'n'drop
// @author Paul Pinterits
// @include *://*.stackexchange.com/questions/tagged/*
// @include *://meta.serverfault.com/questions/tagged/*
// @include *://meta.stackoverflow.com/questions/tagged/*
// @include *://meta.superuser.com/questions/tagged/*
// @include *://serverfault.com/questions/tagged/*
@Aran-Fey
Aran-Fey / access_builtins.py
Last active September 26, 2018 08:28
Showcasing how to gain access to the builtins from a simple literal, proving that eval and exec can always be exploited no matter which safeguards you put in place. (Tested in python 3.7)
"""
This code gains access to the builtins from a simple literal. As a consequence,
we can conclude that `eval` and `exec` are insecure even if the evaluated code
has no (direct) access to the builtins or globals.
Of course, there are ways to break this particular exploit - for example,
executing
import abc
del abc.__loader__
will prevent it from working. But that only protects you against this particular
@Aran-Fey
Aran-Fey / SO_textarea_resizer.user.js
Last active October 2, 2018 13:11
Changes the default size of the answer box (and the question box) on StackOverflow
// ==UserScript==
// @name StackExchange bigger text boxes
// @description Changes the default size of the answer box (and the question box) on StackExchange
// @version 1.3
// @author Paul Pinterits
// @include *://*.stackexchange.com/questions/*
// @include *://meta.serverfault.com/questions/*
// @include *://meta.stackoverflow.com/questions/*
// @include *://meta.superuser.com/questions/*
// @include *://serverfault.com/questions/*
@Aran-Fey
Aran-Fey / SOchat_mcve_shortcut.user.js
Last active July 3, 2019 14:46
Userscript that enables the [mcve] shortcut in the StackOverflow chat
// ==UserScript==
// @name SOchat [mcve] shortcut
// @description Enables the [mcve] shortcut in StackOverflow chat
// @version 1.1.3
// @author Paul Pinterits
// @include *://chat.stackoverflow.com/rooms/*
// @grant none
// @updateURL https://gist.github.com/Aran-Fey/e5a3fbd5de70d093e7b490ad46117819/raw/SOchat_mcve_shortcut.user.js
// @downloadURL https://gist.github.com/Aran-Fey/e5a3fbd5de70d093e7b490ad46117819/raw/SOchat_mcve_shortcut.user.js
// ==/UserScript==
// ==UserScript==
// @name StackOverflow auto edit
// @description Automatically detects low quality questions and attempts to improve them
// @version 1.1.11
// @author Paul Pinterits
// @include *://*.stackexchange.com/questions/*
// @include *://meta.serverfault.com/questions/*
// @include *://meta.stackoverflow.com/questions/*
// @include *://meta.superuser.com/questions/*
// @include *://serverfault.com/questions/*