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 |
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 StackExchange.Redis; | |
| using System; | |
| static class P | |
| { | |
| static void Main() | |
| { | |
| // this is a simpler runtime check if you don't have redis handy | |
| // Pipelines.Sockets.Unofficial.SocketConnection.AssertDependencies(); | |
| try |
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 BenchmarkDotNet.Attributes; | |
| using BenchmarkDotNet.Running; | |
| using System; | |
| using System.Buffers; | |
| using System.Buffers.Text; | |
| using System.Runtime.CompilerServices; | |
| using System.Text; | |
| public static class P | |
| { |
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
| public async Task<Token> WaitOneAsync() | |
| { | |
| /* There are two types of semaphore examples for redis; the simple ones don't | |
| * properly account for differences in the system clocks of different clients; | |
| * the more advances ones *do*, but are much more complex. But if we're using | |
| * Lua, we can get the *server* to make the time decisions, then the clock of | |
| * the client is *irrelevant*, and we can use the simple versions. Yay! | |
| * | |
| * Now; normally in redis Lua/EVAL you are not allowed to access the system time, | |
| * as that will behave differently during replication; so: we use the |
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; | |
| using System.Linq; | |
| using System.Linq.Expressions; | |
| using System.Reflection; | |
| class Foo | |
| { | |
| [SomeAttrib] | |
| public EntityLocalizer A { get; set; } |
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
| # option 1: | |
| **stop using Y/N** - there is a "bit" type that is intended for storing booleans | |
| # option 2: | |
| cast in the database during the select | |
| select cast(case SomeColumn when 'Y' then 1 when 'N' then 0 else null end as bit) as [SomeColumn] |
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.Reflection; | |
| using System.Linq; | |
| using System.Data; | |
| static class P | |
| { | |
| static void Main() | |
| { | |
| ShowClassesWithEquality(typeof(string).Assembly); |
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 EpicAttribute : Attribute | |
| { | |
| public string Name { get; set; } | |
| } | |
| [Epic(Name = "awesome!")] | |
| static class P | |
| { | |
| static void Main() { |