Skip to content

Instantly share code, notes, and snippets.

View rstropek's full-sized avatar

Rainer Stropek rstropek

View GitHub Profile
package main
import (
"fmt"
"reflect"
"golang.org/x/exp/constraints"
)
type lentil struct {
@rstropek
rstropek / schmetterling.html
Created August 17, 2021 06:04
Schmetterling für CoderDojo
<svg id="image" width="1000" height="600" viewBox="0 10 204 172" xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg">
<path
style="stroke:#000000;stroke-width:0.26458332"
d="m 57.689061,177.30516 -1.322038,-1.27428 v -2.39378 c 0,-4.72344 0.752353,-6.81971 3.876257,-10.80038 2.740707,-3.49237 3.313525,-4.67695 3.476135,-7.18865 0.18245,-2.81838 -0.0568,-3.72771 -1.113367,-4.23155 -0.660939,-0.31518 -1.024009,-0.77362 -1.475642,-1.86327 -1.204124,-2.90516 -4.311168,-5.43947 -7.561902,-6.16797 -1.868945,-0.41884 -1.946892,-0.54011 -1.937708,-3.01464 0.01312,-3.53625 -0.554286,-4.97955 -2.676408,-6.80787 l -1.3514,-1.1643 0.702152,-2.37566 c 0.737253,-2.49444 1.119261,-6.24769 0.805899,-7.91805 -0.10387,-0.55368 -0.587443,-1.41998 -1.124399,-2.01433 l -0.94215,-1.04285 0.122894,-4.29918 c 0.131294,-4.59312 0.355483,-5.59373 1.355352,-6.04931 0.407268,-0.18556 0.75003,-0.67976 0.961154,-1.38581 0.84977,-2.8418 3.337573,-5.83147 5.426157,-6.52076 0.510294,-0.16842 0.936522,-0
using System;
var o = new TypeA("FooBar", 42);
Console.WriteLine(o);
public abstract record BaseRecord(string Name)
{
public sealed override string ToString() => Name;
}
#nullable enable
using System;
Err err;
// Note that we can now mix declaration and tuple deconstruction
(var ret1, err) = GetAnswer();
if (err == null) Console.WriteLine(ret1);
using System;
using System.Collections.Generic;
var heroes = new List<IHero>
{
new Hero("Homelander", new(true, true)),
new Hero("Stormfront", new(true, false)),
};
// Old: if (heroes[0] is Hero { Flying: { CanFlyInSpace: true } })
using System;
using System.Collections.Generic;
var heroes = new List<Hero>
{
new("Superman", int.MaxValue),
new("The Tick", 10),
};
if (heroes is { { MaxJumpDistance: > 1000 }, { MaxJumpDistance: < 100, Name: var snd } })
using System;
using System.Collections.Generic;
var numbers = new List<int>() { 1, 2, 3, 5, 8 };
// List pattern
if (numbers is { 1, 2, 3, 5, 8 })
{
Console.WriteLine("Fibonacci");
}
using System;
const string s1 = $"abc";
const string s2 = $"{s1}edf";
Console.WriteLine(s2);
DoSomething_Old(42);
DoSomething_VeryOld(42);
[Obsolete($"Use {nameof(DoSomething_New)} instead")]
#nullable enable
using System;
using System.Runtime.CompilerServices;
var x = 5;
Verify.Lower(x * 2, Convert.ToInt32(Math.Floor(Math.PI)));
public static class Verify
{
using System;
var app = new EndpointConventionBuilder();
// Traditional way of defining a function with an attribute
[HttpGet("/")] int GetAnswer() => 42;
app.MapAction((Func<int>)GetAnswer);
// Now, we can remove the type cast:
app.MapAction(GetAnswer);