Skip to content

Instantly share code, notes, and snippets.

View ForNeVeR's full-sized avatar
🦑

Friedrich von Never ForNeVeR

🦑
View GitHub Profile
@ForNeVeR
ForNeVeR / Program.cs
Created December 5, 2023 21:39
Thread abort in modern .NET.
// See https://aka.ms/new-console-template for more information
using System.Collections;
using System.Runtime;
internal class Program
{
public static void Main(string[] args)
{
var task = StartWork();
@ForNeVeR
ForNeVeR / Union.cs
Last active April 25, 2022 15:22
A showcase of union in C#. Ha-ha.
using System;
using System.Runtime.InteropServices;
namespace ConsoleApp77
{
class User
{
public string Name { get; set; }
public string Surname { get; set; }
public string Password { get; set; }
@ForNeVeR
ForNeVeR / Zombify.fs
Last active November 30, 2023 09:48
open System
let mutable debug = true
type T = T with
static member inline ($) (T, arg: unit) = ()
static member inline ($) (T, arg: int) = 0 // mandatory second terminal case; is unused in runtime but is required for the code to compile
static member inline ($) (T, func: ^a -> ^b): ^a -> ^b =
fun (_: 'a) -> T $ Unchecked.defaultof<'b>
@ForNeVeR
ForNeVeR / DynamicCallee.cs
Created July 3, 2020 16:49
Call __arglist method with Reflection.Emit
using System;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
namespace ConsoleApp4
{
public class Program
{
public static void Callee(__arglist)
@ForNeVeR
ForNeVeR / InitializerOrder.cs
Last active July 30, 2020 07:31
C# class constructor/initializer call order
using System;
namespace ConsoleApp5
{
class Base
{
private int _baseField = PrintAndReturnLength("Base class field init");
protected Base()
{
Console.WriteLine("Base ctor");
@ForNeVeR
ForNeVeR / DeclareAsMath.cs
Last active April 27, 2022 16:16
Declare an object as an instance of System.Math.
using System;
using System.Linq;
using System.Reflection;
class Program
{
class MyClass
{
}
@ForNeVeR
ForNeVeR / InterfaceMaps.cs
Last active April 27, 2022 16:17
Shows how interface maps work for implicit and explicit interface implementations in C#.
using System;
using System.Reflection;
public interface ITest
{
void TestFun(int arg);
}
public class TestClass : ITest
{
@ForNeVeR
ForNeVeR / DelegateConverter.fs
Last active April 27, 2022 16:22
Mystical delegate converter in F#
open System
type Del = delegate of int -> int
let convert1 (d: Func<int, int>): Del = (# "" d : Del #)
let convert2 (d: Func<int, int>): Del = Del(fun x -> d.Invoke x)
[<EntryPoint>]
let main argv =
let x = Func<int, int>(fun x -> x)
@ForNeVeR
ForNeVeR / w3g_actions.txt
Last active November 11, 2019 08:48 — forked from stattrak-dragonlore/w3g_format.txt
WarCraft III Replay file format description
*******************************************************************************
* WarCraft III Replay action format description *
* *
* document version: 1.01 *
* document date : 2006-03-25 *
* document authors: blue, nagger *
* *
* For more informtion about w3g file format, please visit: *
* http://w3g.deepnode.de *
* *
@ForNeVeR
ForNeVeR / Barbeque.cs
Created October 21, 2016 07:32
Bool not equal to true neither to false.
using System;
using System.Runtime.InteropServices;
namespace ConsoleApplication2
{
[StructLayout(LayoutKind.Explicit)]
internal struct Barbeque
{
[FieldOffset(0)] public int Barbe;
[FieldOffset(0)] public bool Que;