Skip to content

Instantly share code, notes, and snippets.

@jkotas
jkotas / gist:a21de87b790e06979635
Created January 6, 2016 00:37
Strong name signing utilitity
using System;
using System.IO;
using System.Reflection.PortableExecutable;
using System.Security.Cryptography;
using System.Runtime.InteropServices;
using System.Collections.Immutable;
static class ImmutableArrayHelpers
{
// Avoid unnecessary copy
@jkotas
jkotas / gist:6fb00a78442c72440963
Last active January 10, 2016 07:34
Thread id scalability test
using System;
using System.Runtime.CompilerServices;
using System.Threading;
class Program
{
static void Work()
{
ManagedThreadId.Current.ToString();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static bool IsUrlSafeChar(char ch)
{
/*
if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9')
return true;
switch (ch)
{
case '-':
@jkotas
jkotas / gist:8cf994304c56b7d5ec6e54d8ed0e585f
Created August 12, 2016 07:18
NativeCallableAttribute + AddOf intrinsic
using System;
using System.Runtime.InteropServices;
namespace System.Runtime.InteropServices
{
[AttributeUsage(AttributeTargets.Method)]
public sealed class NativeCallableAttribute : Attribute
{
public string EntryPoint;
public CallingConvention CallingConvention;
using System;
struct MyStruct<A,B>
{
public static void foo(int depth)
{
MyStruct<A,B>[] a = null;
Array.Resize(ref a, 1);
if (depth-- == 0) return;
MyStruct<MyStruct<A,B>,B>.foo(depth);
using System;
using System.Threading;
using System.Buffers;
class Program
{
#if false
static byte[] AcquireBuffer()
{
return new byte[4096];
using System;
using System.Threading;
using System.Reflection;
using System.Runtime.Loader;
class MyALC : AssemblyLoadContext
{
protected override Assembly Load(AssemblyName name)
{
return null;
@jkotas
jkotas / gist:132e2b8fbe29b69622b322b806635504
Created January 4, 2017 15:22
Path normalization perf test
using System;
using System.Text;
using System.IO;
class My {
static void Test(string name, string path)
{
int start = Environment.TickCount;
int count = 200000000 / path.Length;
using System;
class MyG<T,U>
{
static Lazy<MyG<T,U>> s_lazy = new Lazy<MyG<T,U>>();
public static void foo(int depth)
{
if (s_lazy.IsValueCreated) return;
using System;
using System.Collections.Generic;
struct MyG<T,U> : IEquatable<MyG<T,U>>
{
static bool visited;
public static void foo(int depth)
{
if (visited) return;