Skip to content

Instantly share code, notes, and snippets.

View voronoipotato's full-sized avatar
🏠
Working from home

Alan Ball voronoipotato

🏠
Working from home
  • NC
View GitHub Profile
let twister (n: float) =
let n = min n 100.
let n = max 0. n
let a = n * 2.
//if a < 50 then 1 else 0
let a' =
let x = min (n-50.) 0.
let y = min -x 1.
y
let b = (100. - n) * 2.
@voronoipotato
voronoipotato / latency.markdown
Created August 19, 2024 17:42 — forked from hellerbarde/latency.markdown
Latency numbers every programmer should know

Latency numbers every programmer should know

L1 cache reference ......................... 0.5 ns
Branch mispredict ............................ 5 ns
L2 cache reference ........................... 7 ns
Mutex lock/unlock ........................... 25 ns
Main memory reference ...................... 100 ns             
Compress 1K bytes with Zippy ............. 3,000 ns  =   3 µs
Send 2K bytes over 1 Gbps network ....... 20,000 ns  =  20 µs
SSD random read ........................ 150,000 ns  = 150 µs

Read 1 MB sequentially from memory ..... 250,000 ns = 250 µs

open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
open BenchmarkDotNet.Jobs
open System
open Microsoft.FSharp.NativeInterop
type Chars () =
static member chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ".AsSpan()
let chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
let b36Unfold (number: int) =
let unfoldFunc n =
@voronoipotato
voronoipotato / fsharp.json
Last active August 16, 2024 22:34
some simple F# snippets for vscode
{
// Place your snippets for fsharp here. Each snippet is defined under a snippet name and has a prefix, body and
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the
// same ids are connected.
// Example:
// "Print to console": {
// "prefix": "log",
// "body": [
// "console.log('$1');",

Totality

all operations are 'T -> 'T
counter example: for rational numbers sqrt(2) produces an irrational number

Associativity

(a * b) * c = a * (b * c)
counter example: (a - b) - c <> a - (b - c)

Identity

there exists some data where the operation does nothing
counter example: 
addition for the natural numbers. 
@voronoipotato
voronoipotato / gpg-guide.sh
Last active May 23, 2023 15:27
A brief guide for using GPG to sign files
# This guide is a living document, if you see something outdated please fix it.
# To make a key use this.
# Defaults used to be not so good, but now they're okay for most people.
# It may not be a bad idea though to select an expiration date so that in the future you can make a new key with updated encryption
# Make sure to provide an email and proper name that people will know you as.
# If you're using this for more than just sending gossip between friends make sure to use a passphrase.
gpg --full-generate-key
# To write the signature you can use this
# I'm vopo, so if you see that, it's me. You can put your own name in there
@voronoipotato
voronoipotato / readme.md
Created December 9, 2022 04:03 — forked from josefnpat/readme.md
Going from Lua 5.2 to PICO-8's Lua

This information applies to the PICO-8 0.1.6 release.

This document is here to help folks with a proficiency in Lua understand the limitations and discrepencies between Lua and PICO-8's Lua.

You can always view the manual or yellowafterlife's extended 0.1.1 manual.

General

  • anything written in uppercase the PICO-8 editor or .p8 is made lowercase by the editor. → editing the .p8 file directly can work
  • print(function() end) outputs the string function instead of the string function: 0x0000000.
// Link: http://fssnip.net/7U0
// Posted: 5 years ago
// Author: Evgeniy Andreev
// Tags: #active patterns , #srtp
let inline (|HasLength|) x =
fun () -> (^a: (member Length: int) x)
// `this` is optional here, just for demonstration of `as` pattern
let inline length (HasLength f as this) = f()
@voronoipotato
voronoipotato / srtp.fsx
Created October 15, 2022 17:22 — forked from michaeloyer/srtp.fsx
F# SRTP Example
// SRTP: Statically Resolved Type Parameters
// https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/generics/statically-resolved-type-parameters
// SRTP Allows for pulling members out of types that where the member is named and typed the same
// In this example SRTP will be used to pull out the 'First: string' and 'Last: string' members
// from different types
// One example of SRTP in the F# Base Class Library is the (+) operator.
// You'll see that it has this type signature:
@voronoipotato
voronoipotato / hex2text.fsx
Created September 2, 2022 22:04
script that is both a powershell script, and a f# script, that invokes the F# script
#if false
return dotnet fsi --quiet --exec --use:"$(Get-Location)\$($MyInvocation.MyCommand.Name)" -- $args
#endif
// <#
//the first argument is the script name, so we get the tail
let args : string array = fsi.CommandLineArgs |> Array.tail
let hexByteToAscii (s:string) =
System.Convert.ToByte(s,16)
|> System.Convert.ToChar