Skip to content

Instantly share code, notes, and snippets.

@mrange
mrange / commit-msg
Created September 26, 2022 09:28
gerrit commit hook
#!/bin/sh
# From Gerrit Code Review 2.12.3
#
# Part of Gerrit Code Review (https://www.gerritcodereview.com/)
#
# Copyright (C) 2009 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@mrange
mrange / FsDistanceField.fsproj
Last active September 24, 2022 10:42
F# Distance Field
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
@mrange
mrange / 0_readme.md
Last active May 26, 2023 03:58
Reactor shader inspired by Microsoft Reactor Graphics. For us in windows terminal

Install shader

Note: Doesn't work on latest preview of windows terminal (2022-09-15) but should work on later previews.

  1. Save reactor.hlsl to disk, note the path for later.
  2. Open Windows terminal settings
  3. Open settings as JSON
  4. Add a custom shader to the default profile, see excerpt below.
@mrange
mrange / thindal.hlsl
Created September 11, 2022 10:38
Thindal Windows Terminal
#define WINDOWS_TERMINAL
Texture2D shaderTexture;
SamplerState samplerState;
// --------------------
#if defined(WINDOWS_TERMINAL)
cbuffer PixelShaderSettings {
float Time;
float Scale;
@mrange
mrange / 0_the_easy_way.cs
Last active January 1, 2024 22:12
Examples IEnumerable implementing a fibonacci series
// Example on the "easy" way to generate the fibonacci sequence
// https://en.wikipedia.org/wiki/Fibonacci_number
// Take the first 20 fibonacci numbers and print them
// the "easy" way.
foreach(var n in Fibonacci().Take(20))
{
Console.WriteLine(n);
}
namespace CsDI
{
partial record DI
{
IY? _singletonOf_IY;
IZ? _singletonOf_IZ;
public void Get(out IX v)
{
@mrange
mrange / GenAll.cs
Last active June 12, 2022 05:27
T4 template to generate all version of a model
namespace CsGenAll
{
using System.Diagnostics;
// BooleanValue - BEGIN
// Kind: IsEnum
public enum BooleanValue
{
@mrange
mrange / GenAll.tt
Last active June 11, 2022 05:31
GenAll T4
<#@ assembly name ="System.Core" #>
<#@ import namespace ="System.Linq" #>
<#
var model = new []
{
Union(
"BooleanValue"
, Case("False")
@mrange
mrange / Benchmark.fsproj
Last active June 9, 2022 19:28
Testing Fusion vs Fission in F#
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
@mrange
mrange / 0_README.md
Last active September 2, 2022 09:56
FsGenAll - Generate all possible values for an F# type

FsGenAll - Generate all possible values for an F# type

writing test code I often use FsCheck. However, sometimes I want to generate each possible value for a test model and check the properties for that.

My typical use case is something like this:

  1. Create an ADT that models what I want to test
  2. Generate all possible values of this test model
  3. Generate test data from the test model
  4. Run the function under test that produces a result