Skip to content

Instantly share code, notes, and snippets.

@Aran-Fey
Aran-Fey / always_python_3_docs.user.js
Last active December 17, 2019 21:08
Ever visited the python 2 documentation on accident? Ever got linked to the python 3.2 docs by google? Install this userscript to be automatically redirected to the version 3 docs whenever you visit docs.python.org.
// ==UserScript==
// @name always python 3 docs
// @description Automatically redirects from python 2 or python 3.x documentation to the latest python 3 documentation
// @version 1.3.4
// @author Paul Pinterits
// @include /https?://docs\.python\.org/[\d.]+/.*/
// @grant none
// @run-at document-start
// @updateURL https://gist.github.com/Aran-Fey/ecb80a7d3b3a955c9841bd6bea60d515/raw/always_python_3_docs.user.js
// @downloadURL https://gist.github.com/Aran-Fey/ecb80a7d3b3a955c9841bd6bea60d515/raw/always_python_3_docs.user.js
@Aran-Fey
Aran-Fey / SO_documentation_links.user.js
Last active October 16, 2019 15:04
A userscript that automatically turns text surrounded by quotation marks like ?foo? or ?foo.bar? into links to the documentation for "foo" or "foo.bar". A short user manual can be found in the code.
@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==
@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 / 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
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 / 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()):