Skip to content

Instantly share code, notes, and snippets.

@mrange
mrange / Example.cs
Created Dec 20, 2022
Invariant String Interpolation
View Example.cs
namespace SomeLib
{
using System.Globalization;
using System.Runtime.CompilerServices;
static partial class StringInterpolation
{
// This is to allow to use fast string interpolation
public static string FastInvariantInterpolation(ref DefaultInterpolatedStringHandler handler)
{
@mrange
mrange / Program.fs
Created Nov 28, 2022
Illustrating invalid and ambiguous dates in F#
View Program.fs
open System
open System.Globalization
let dtos =
let ts = TimeSpan(2, 0, 0)
[|
// Nothing weird about this date
DateTimeOffset(2022, 6, 22, 2, 30, 0, ts)
// This time is invalid in CEST because clock is set ahead at this date
DateTimeOffset(2022, 3, 27, 2, 30, 0, ts)
@mrange
mrange / 0_README.md
Last active Oct 11, 2022
Happy little terminal shader
View 0_README.md

Install shader

  1. Save happy.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.
{
 "profiles": {
@mrange
mrange / build.cake
Last active Oct 8, 2022
Cake model update
View build.cake
#nullable enable
#addin nuget:?package=Cake.Git&version=2.0.0
var target = Argument("target", "GithubAction");
var repoUri = "https://github.com/mrange/cake.tool.experiments.git";
record BuildData(
DirectoryPath RootPath
, DirectoryPath GithubPath
, DirectoryPath RepoPath
View Microsoft.PowerShell_profile.ps1
# Stored under My Documents\WindowsPowerShell
function global:prompt
{
"╭─ PS $($executionContext.SessionState.Path.CurrentLocation) $('+' * ($nestedPromptLevel))`n╰─$ ";
}
@mrange
mrange / commit-msg
Created Sep 26, 2022
gerrit commit hook
View commit-msg
#!/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
View FsDistanceField.fsproj
<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 Sep 21, 2022
Reactor shader inspired by Microsoft Reactor Graphics. For us in windows terminal
View 0_readme.md

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 Sep 11, 2022
Thindal Windows Terminal
View thindal.hlsl
#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 Aug 19, 2022
Examples IEnumerable implementing a fibonacci series
View 0_the_easy_way.cs
// 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);
}