Skip to content

Instantly share code, notes, and snippets.

@9999years
9999years / currency.ps1
Created December 14, 2017 20:17
powershell currency conversion
function currency {
Begin {
# make sure we can use Web.HttpUtility
Add-Type -AssemblyName System.Web
}
Process {
$encoded = [Web.HttpUtility]::UrlEncode($args -join " ")
$response = Invoke-WebRequest `
"https://google.com/search?q=$encoded"
// these are usually defined in math.h ...
#define NAN 0.0
// actually a bit smaller than DBL_MAX
#define INFINITY 1e+308
/**
* atof as described in ISO/IEC 9899:2011 (the C11 standard)
*
* case-insensitive input syntax EBNF:
*
" add all builtin keywords and methods/attributes to syntax
" put in $VIM/vimfiles/after/syntax/python.vim
if exists('b:loaded_pythoncustomsyntax')
finish
endif
let b:loaded_pythoncustomsyntax=1
syn keyword pythonExceptions ModuleNotFoundError
function run {
Start-Process $args[0] -ArgumentList (
$args[1..$args.Length] -join " "
)
}
@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
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
# sign funcs
import math
# cli arguments
import argparse
# random rationals
import random
def sign(x):
return math.copysign(1, x)
# 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
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