Skip to content

Instantly share code, notes, and snippets.

@mrange
mrange / tic80.lua
Last active September 23, 2023 12:08
My first TIC-80 program
function clamp(value, min, max)
return math.min(math.max(value, min), max)
end
function mix(a,b,x)
return a+(b-a)*x
end
function pmin(a,b,k)
local h = clamp(0.5+0.5*(b-a)/k, 0.0, 1.0)
@mrange
mrange / RecordArray.cs
Created May 15, 2023 12:35
RecordArray C#
namespace MyNamespace
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
@mrange
mrange / Program.cs
Last active April 18, 2023 19:08
Repo of Repos
var repoRepos = new RepositoryRepository();
var pageRepo0 = repoRepos.GetRepository<IPage>();
var pageRepo1 = repoRepos.GetRepository<IPage>();
class RepositoryRepository
{
readonly List<IBaseRepository> _repos = new();
IBaseRepository CreateRepository(Type t)
{
@mrange
mrange / Program.cs
Last active May 14, 2023 13:16
Mutate C# strings
using System.Runtime.CompilerServices;
// An "immutable" string
var x = "I am immutable";
// *Insert evil laugh here*
var y = Unsafe.As<char[]>(x);
var z = "mutable!!";
// Overwriting the string
// Might only "work" on x64 but for hackers 'Might' is good enough ;)
@mrange
mrange / README.md
Last active February 18, 2023 11:33
The joy of Shadertoy

The joy of Shadertoy

Shadertoy is an online platform where programmers can create and share shaders - small programs that run on a GPU and render graphics and animations in real-time. The platform has become popular among graphics enthusiasts and game developers, as it provides an accessible and engaging environment for exploring the capabilities of modern graphics hardware.

image shadertoy.com

The joy of Shadertoy

For those who enjoy programming and are interested in graphics, there are few experiences as rewarding as writing shaders on Shadertoy. In this blog post, we'll explore the joy of programming shaders on Shadertoy, and why it has become such a popular platform among graphics enthusiasts.

@mrange
mrange / Example.cs
Created December 20, 2022 18:30
Invariant String Interpolation
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 November 28, 2022 06:37
Illustrating invalid and ambiguous dates in F#
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 May 26, 2023 03:58
Happy little terminal shader

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 October 8, 2022 19:38
Cake model update
#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
@mrange
mrange / Microsoft.PowerShell_profile.ps1
Created September 28, 2022 07:55
mrange powershell prompt
# Stored under My Documents\WindowsPowerShell
function global:prompt
{
"╭─ PS $($executionContext.SessionState.Path.CurrentLocation) $('+' * ($nestedPromptLevel))`n╰─$ ";
}