This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Newtonsoft.Json; | |
using System; | |
using System.Text; | |
static class P | |
{ | |
static void Main() | |
{ | |
var base64 = @"e0tleSA6ICdhYmMnLCBpc0V4aXN0czogJ3RydWUnfQ=="; | |
var blob = Convert.FromBase64String(base64); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.CompilerServices; | |
using System.Runtime.InteropServices; | |
Console.WriteLine(Unsafe.SizeOf<Flags>()); // 50, it worked! | |
[StructLayout(LayoutKind.Sequential, Pack = 1)] | |
public struct Flags | |
{ | |
public ushort frameCnt; //0-1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Runtime.CompilerServices; | |
using System.Runtime.InteropServices; | |
Console.WriteLine(Unsafe.SizeOf<Flags>()); // 50, it worked! | |
[StructLayout(LayoutKind.Sequential, Pack = 1)] | |
public struct Flags | |
{ | |
public ushort frameCnt; //0-1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
static class P | |
{ | |
static void Main() | |
{ | |
var bytes = new List<byte>(); | |
bytes.AddRange(new byte[] { 0, 1, 2, 3 }); | |
bytes.AddRange(new byte[] { 4, 5 }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class Program | |
{ | |
static void Main() | |
{ | |
int z = 42; | |
int x = Foo(z); | |
Console.WriteLine($"{x}, {z}"); | |
// get: 871, 42 | |
// expected: 871, 46 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Buffers.Binary; | |
static class P | |
{ | |
static void Main() | |
{ | |
// sample taken from comtrade91.pdf section 6.6 | |
var buffer = new byte[] { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using ProtoBuf; | |
using System; | |
using System.IO; | |
static class Funchelper | |
{ | |
static void Main() | |
{ | |
var obj = new NotAForm(); | |
obj.DoTheThing(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
readonly struct Foo | |
{ | |
private readonly int[] _arr; | |
public Foo(int length) => _arr = new int[length]; | |
public int Length => _arr?.Length ?? 0; | |
public ref int this[int index] => ref _arr[index]; | |
public FooEnumerator GetEnumerator() => new FooEnumerator(_arr); | |
public struct FooEnumerator |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class Foo | |
{ | |
int _value; | |
public ref int Value => ref _value; | |
static void Main() | |
{ | |
var obj = new Foo { Value = 12 }; | |
Console.WriteLine(obj.Value); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string s = string.Join(",", Enumerable.Repeat("blah", 50)); | |
var charSpan = s.AsSpan(); | |
var vectorized = MemoryMarshal.Cast<char, Vector<ushort>>(charSpan); | |
Console.WriteLine($"vector chunks: " + vectorized.Length); | |
foreach(var v in vectorized) | |
{ | |
if (Vector.EqualsAny(v, spaces)) { ...} | |
} | |
// todo: mop up any remainded |