Skip to content

Instantly share code, notes, and snippets.

//see https://gist.github.com/9999years/8fd0184530fcbbe494ffc306bab8654b for more verbosity
//kinda golfed (1507 bytes)
var els = [], g = { img: document.getElementsByTagName("img"), time: 0, amt: 20,
amin: 5 /* amp */, amax: 10, ramin: 1 /* rot amp */, ramax: 50, pmin: 1 /* perio
d */, pmax: 10, rpmin: 1 /* rot period */, rpmax: 50 }; function randf(min, max)
{ return Math.random()*(max-min)+min; } function randSign() { return Math.round(
Math.random()) ? -1 : 1; } function sin(amp, period) { return amp * Math.sin((g.
time / period) * 2*Math.PI); } function randEl(arr) { return arr[Math.floor(Math
.random()*arr.length)]; } function generateVariables() { for(var i = els.length;
/* Given these variables:
*
* a: 2*b$ b: 7*d+c+2$ c: d+2$ d: 31*%e$
*
* What's the symbolic representation of a? try "a, expand;". You'll get
* 14d + 2c + 4. Evaluate it again and you'll get 2d + 434e + 8 -- oh no! One
* of the variables has been substituted for its numeric value, and it's no
* longer a value-independent *generic* equation. You'll have to evaluate that
* another 3 times to get the decimal approximation (1356.268...), and you'll
* never get a generic equation for a in terms of the other variables.
% usage: \unicode[font]{codepoint}, e.g. \unicode[\emojifont]{1F60E} or \unicode{1F47D}
% requires --shell-escape be enabled (to use \write18) and curl to be in the path
% prints something like U+XXXX § SECTION SIGN
% note that the codepoint MUST be in all-caps, due to how \symbol works
\newcommand{\unicode}[2][]
{\immediate\write18{curl https://codepoints.net/api/v1/name/#2 -o .cp#2.txt}
\texttt{U+#2} {#1\symbol{"#2}}
\texttt{\input{.cp#2.txt}}\immediate\write18{del .cp#2.txt}}
$base = "http://tinywords.com/haiku"
$ErrorActionPreference = "Stop"
$i = 363; $dates[$i..($dates.length-1)] | %{
$t = (Invoke-WebRequest "$base/$_").content
$m = [regex]::match($t, "<pre>`n((.+`n)+)`n+")
if($m.success -eq $False) { $t | out-file error.html -append -encoding UTF8
write-error "no haiku found! quitting at date $_ (index $i)!" }
else { $m = $m.groups[1].value }
echo "$($_):`t`t`t$([math]::round($i/$dates.length*100, 3))% done`r`n$m"
@9999years
9999years / math-wrappers.ps1
Last active April 18, 2017 14:11
Wrapper functions to make Powershell’s [System.Math]::Method()s easier to use
# math functions
# wrappers to make [System.Math]::Method()s easier to use
[double]$global:PI = 3.14159265358979323846
[double]$global:E = 2.71828182845904523536
function abs {
[CmdletBinding()]
Param([Parameter(ValueFromPipeline = $True)][double]$a)
Process {
import math
import re
def get_float(prompt):
return float(input(prompt))
# ok, this one is kinda complicated to describe
# scales a number val (assumed to be in the range of valmin to valmax)
# to the equivalent fractional distance from min to max
# eg if you have a percent value and you want it to be a byte val
# generates the nth iteration of the koch snowflake and outputs
# it for use in LaTeX / tikz
# sources the iteration count from the args or defaults to 0
# you could easily modify it to request a default with
# iterations = int(prompt("iterations? ") or something
import sys
# get the first numeric argument for our iteration count
iterations: int
# sign funcs
import math
# cli arguments
import argparse
# random rationals
import random
def sign(x):
return math.copysign(1, x)
import argparse
parser = argparse.ArgumentParser(
description='Print prime factors of number[s]'
)
parser.add_argument('num', type=int, nargs='*')
args = parser.parse_args()
nums = args.num
@9999years
9999years / Enable-ANSIEscapes.ps1
Last active February 5, 2020 11:42
Powershell enable ANSI / VT100 escape sequences
# This is a total of 5 logical LOC, but the API is... well hidden and highly opaque
# (magic numbers everywhere!) so it warrents a few dozen lines of comments
function Enable-ANSIEscapes {
# Enable ANSI / VT100 16-color escape sequences:
# Original discovery blog post:
# http://stknohg.hatenablog.jp/entry/2016/02/22/195644
# Esc sequence support documentation
# https://msdn.microsoft.com/en-us/library/windows/desktop/mt638032(v=vs.85).aspx