Skip to content

Instantly share code, notes, and snippets.

View jwosty's full-sized avatar

John Wostenberg jwosty

View GitHub Profile
# Jwosty's powershell profile
Import-Module 'C:\tools\poshgit\dahlbyk-posh-git-9bda399\src\posh-git.psd1'
# Start emacs in no-window mode (CLI mode)
function Private:emacs()
{
& emacs -nw $args
}
type Mock =
// poor man's Moq, for individual functions!
static member SetupFunction (funcName, funcImpl) =
let mutable argsState = []
let theMockFunc arg =
argsState <- argsState @ [arg]
funcImpl arg
theMockFunc, {|
calledOnce =
fun () ->
@jwosty
jwosty / AsyncFail.fs
Created July 11, 2023 19:16
F# async fail
let f (x: int) =
let y = x / 0
async {
return y
}
let g = async {
let! x = Async.Catch (f 42)
()
}
open System
open System.Diagnostics
open System.IO
open System.Runtime.ExceptionServices
module ThirdPartyLibrary =
// Represents some low-level async "primitive" which is used in many many places and which may fail. This type of
// method/function is not typically what you're interested in when examining stacktraces.
// Example: a database query function from a thid-party library
let doWorkAsync crash = ExtraTopLevelOperators.async {
@jwosty
jwosty / PhongToonLighting.hlsl
Created April 19, 2026 06:26
Simple toon shading lighting model used in Sheep, Inc.
float Quantize(float value, float n) {
return n <= 0 ? value : floor((value*(n-1.0))+0.5)/(n-1.0);
}
float3 Quantize(float3 value, float n) {
return float3(Quantize(value.x,n), Quantize(value.y,n), Quantize(value.z,n));
}
/**
* Lighting contribution of a single directional light source via Phong illumination.