Skip to content

Instantly share code, notes, and snippets.

@vyznev
vyznev / dice_roll.py
Last active January 6, 2024 22:54
A simple bare-bones dice probability calculator framework, compatible with both Python 2 and Python 3
def dice_roll(die, count = 1, select = None):
"""Generate all possible results of rolling `die` `count` times, sorting
the results (according to the order of the sides on the die) and selecting
the first `select` elements of it.
The yielded results are tuples of the form `(roll, prob)`, where `roll` is a
sorted tuple of `select` values and `prob` is the probability of the result.
The first argument can be either a custom die, i.e. a tuple of `(side, prob)`
pairs, where `prob` is the probability of rolling `side` on the die, or just
from PIL import Image
import numpy as np
import itertools
flatten = itertools.chain.from_iterable
max_depth = 8
img = Image.open('David_Hilbert_postcard_edit2.png')
img = img.convert('L').resize((2**max_depth,) * 2)
img = img.point(lambda i: (1 - i/255 * 0.75) * 128 )
@vyznev
vyznev / se_hotness_estimator.user.js
Last active November 3, 2022 00:32
Adds an estimate of "hotness" to the question sidebar, calculated using the formula from http://meta.stackexchange.com/a/61343. Questions with a high hotness value may be selected for the Hot Network Questions list. Note that the hotness value displayed by this script does not include the per-site scaling factors, and so does not match the "arbi…
// ==UserScript==
// @name Stack Exchange hotness estimator
// @namespace http://vyznev.net/
// @description Estimates how highly each Stack Exchange question would rank on the Hot Network Questions list
// @author Ilmari Karonen
// @version 0.4.3
// @license Public domain
// @homepageURL https://meta.stackexchange.com/a/284933
// @downloadURL https://gist.github.com/vyznev/bb2c1adb6e96eb65a87bab3822c74e81/raw/se_hotness_estimator.user.js
// @match *://*.stackexchange.com/questions/*
@vyznev
vyznev / se_no_sticky_topbar.user.js
Last active April 4, 2022 07:57
Disable the sticky top bar on Stack Exchange sites
// ==UserScript==
// @name SE No Sticky Top Bar
// @namespace https://github.com/vyznev/
// @description Disables the sticky top bar on Stack Exchange sites
// @author Ilmari Karonen
// @version 0.3.0
// @copyright 2021-2022, Ilmari Karonen
// @downloadURL https://gist.github.com/vyznev/7c9a7ddc5c057d4c895864e460b4a88d/raw/se_no_sticky_topbar.user.js
// @homepageURL https://meta.stackexchange.com/a/368984
// @match *://*.stackexchange.com/*
@vyznev
vyznev / metacircles.user.js
Last active August 26, 2021 17:15
User script to restyle the OP's username in comments on Meta.SE so that it's circled by a red ellipse, as per http://meta.stackexchange.com/questions/229759/you-cant-see-the-question-owners-special-color/231282#231282.
// ==UserScript==
// @name Circle OP's username on Meta.SE
// @version 1.1
// @description Restyle the OP's username in comments on Meta.SE so that it's circled by a red ellipse.
// @namespace https://github.com/vyznev/
// @author Ilmari Karonen
// @license ISC (http://opensource.org/licenses/ISC)
// @match *://meta.stackexchange.com/*
// @grant none
// @run-at document-start
@vyznev
vyznev / nofollow.user.js
Last active August 26, 2021 17:14
Reveal nofollow links on Stack Exchange
// ==UserScript==
// @name Reveal nofollow links on Stack Exchange
// @version 1.3
// @namespace http://vyznev.net/
// @description Colors all links with rel=nofollow red on the Stack Exchange network. (Works on other sites too, if you edit the includes.)
// @author Ilmari Karonen
// @license ISC (http://opensource.org/licenses/ISC)
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
// @match *://*.superuser.com/*
@vyznev
vyznev / disable_display_math_in_comments.user.js
Last active August 26, 2021 17:12
User script to disable MathJax display math in comments on Stack Exchange sites
// ==UserScript==
// @name Disable display math in comments
// @namespace https://github.com/vyznev/
// @description Forces all MathJax elements in comments to be rendered inline
// @author Ilmari Karonen
// @version 1.1
// @match *://*.stackexchange.com/*
// @match *://*.mathoverflow.net/*
// @homepageURL http://meta.math.stackexchange.com/questions/23250/disable-display-math-in-comments
// @grant none
@vyznev
vyznev / se-sticky-vote-buttons.user.js
Last active August 26, 2021 17:09
Enable sticky vote buttons on Stack Exchange sites
// ==UserScript==
// @name SE Sticky Vote Buttons
// @namespace https://github.com/vyznev/
// @description Enable sticky vote buttons on Stack Exchange sites
// @author Ilmari Karonen
// @version 0.6.0
// @copyright 2018-2021, Ilmari Karonen
// @downloadURL https://gist.github.com/vyznev/607e86f3890d920f67d7cbd6c5f78e7b/raw/se-sticky-vote-buttons.user.js
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*
@vyznev
vyznev / codegolf_sorter.user.js
Created May 30, 2014 23:46
User script to add sort answers by code length on Code Golf Stack Exchange
// ==UserScript==
// @name Code Golf SE sorter
// @namespace http://vyznev.net/
// @version 0.6
// @description Add a tab to sort answers by code length
// @match *://codegolf.stackexchange.com/questions/*
// @copyright 2014, Ilmari Karonen
// @grant none
// ==/UserScript==
@vyznev
vyznev / se-bounty-bar.user.js
Last active April 11, 2021 13:33
Stack Exchange Bounty Bar user script (prototype)
// ==UserScript==
// @name Stack Exchange Bounty Bar
// @namespace https://github.com/vyznev/
// @description Shows a randomized selection of bountied questions in the Stack Exchange sidebar
// @author Ilmari Karonen
// @version 0.0.19
// @copyright 2018, Ilmari Karonen
// @license ISC; https://opensource.org/licenses/ISC
// @match *://*.stackexchange.com/*
// @match *://*.stackoverflow.com/*