Skip to content

Instantly share code, notes, and snippets.

@vyznev
vyznev / apgdecode.py
Last active February 4, 2019 01:04
Golly script for loading apgcodes as patterns
#! /usr/bin/python
# apgdecode.py v0.2
# A script for loading apgcodes (http://conwaylife.com/wiki/Apgcode) as Golly (http://golly.sourceforge.net/) patterns.
# Supports extended and multistate apgcodes. (Multistate handling may still have bugs. Let me know if you find any.)
# Copyright 2019 Ilmari Karonen. Released under the WTFPL (http://www.wtfpl.net/).
import golly as g
import re
@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
@vyznev
vyznev / throttle_steering.ks
Created September 2, 2020 12:40
kOS script for differential throttle augmented steering
// This script sets up a background trigger that automatically adjusts engine throttle according to the yaw / pitch / roll
// commands of the kOS built-in steering manager. This can allow a vessel to be controlled even without any reaction wheels,
// gimbals or control surfaces, and can also provide additional control authority and stability on top of normal steering
// especially for vessels with asymmetric thrust.
//
// The operation of the trigger is controlled by a number of global variables:
//
// * Setting dt_flag to false will terminate the trigger loop.
// * The loop will adjust throttle on any engines listed in dt_engines (by default, all engines on the vessel).
// * The baseline thrust limit on all controlled engines, in the absence of steering input, is set to dt_base percent.
@vyznev
vyznev / etcsl_charenc_fix.user.js
Last active March 31, 2021 22:08
The ETCSL website sometimes loses track of the selected encoding. This script fixes it and makes switching between Unicode and ASCII easy.
// ==UserScript==
// @name ETCSL charenc fix
// @namespace https://github.com/vyznev/
// @description The ETCSL website sometimes loses track of the selected encoding. This script fixes it and makes switching between Unicode and ASCII easy.
// @author Ilmari Karonen
// @version 1.1
// @match *://etcsl.orinst.ox.ac.uk/*
// @homepageURL https://gist.github.com/vyznev/b078af6b3574f80879f93675f59d8c86
// @downloadURL https://gist.github.com/vyznev/b078af6b3574f80879f93675f59d8c86/raw/etcsl_charenc_fix.user.js
// @run-at document-start
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_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/*