Skip to content

Instantly share code, notes, and snippets.

@hypeartist
hypeartist / code.cs
Created July 16, 2022 19:21
Type instantiation (.ctor with parameters)
object obj;
var r = 0;
const int cnt = 1000000;
var constructorInfo = typeof(Class).GetConstructor(new[] { typeof(int) })!;
var hCtor = constructorInfo.MethodHandle;
RuntimeHelpers.PrepareMethod(RuntimeMethodHandle.FromIntPtr(hCtor.Value));
var pCtor = (delegate* managed<object, int, void>)hCtor.GetFunctionPointer();
@hypeartist
hypeartist / ext.cs
Last active October 7, 2022 06:43
Small IJSRuntime extension method to load CSS file at runtime
public static class Utils
{
public static async ValueTask LoadCss(this IJSRuntime jsRuntime, string cssUrl)
{
await jsRuntime.InvokeVoidAsync("eval",/*lang=javascript*/$$"""
import(URL.createObjectURL(new File([`import sheet from '{{cssUrl}}' assert { type: 'css' }; document.adoptedStyleSheets = [sheet];`], `./{{Guid.NewGuid()}}.js`, { type: "text/javascript" }))).then(_=>_);
""");
}
}
@hypeartist
hypeartist / asm.md
Last active August 9, 2023 18:48
Method calling
public class Benchmark2
{
	private Base1 _b1;
	private Base2 _b2;

	[GlobalSetup]
	public void Setup()
	{
 _b1 = new Sub1();
@hypeartist
hypeartist / shift_rotate_avx2.cpp
Created August 30, 2023 14:51 — forked from degski/shift_rotate_avx2.cpp
lane-crossing shift and rotate instructions in AVX2
// MIT License
//
// Copyright (c) 2018 degski
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
@hypeartist
hypeartist / regexbench.cs
Last active December 25, 2023 19:54
regexbench.cs
public partial class Bench
{
private const int Rep = 10_000_000;
private readonly Regex _regex = MyRegex();
private readonly string _input = "723402139283478235u7uA874-sdjw4##7fshsjs6763820XSDFww+___43333hnd";
private int _pos = 0;
[Benchmark(Baseline = true)]
public int Test1()
@hypeartist
hypeartist / IsInRange.cs
Created January 11, 2024 10:36
IsInRange bench
public class Bench
{
private const int Rep = 10_000_000;
private int[] _a = new int[Rep];
[GlobalSetup]
public void Setup()
{
Random.Shared.GetItems([..Enumerable.Range(0, Rep)], _a);
}
@hypeartist
hypeartist / MSBuildCheatSheet.xml
Created October 29, 2024 19:35 — forked from dotMorten/MSBuildCheatSheet.xml
MSBuild Cheat Sheet
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!--
How to define a variable.
Just stick a new node in a property group.
-->
<PropertyGroup>
<!-- This node in a property group will define a variable -->
<TestVariable>Test Variable Value</TestVariable>