This file contains 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
/* | |
Execute me as: | |
``` | |
dotnet tool install dotnet-script | |
dotnet sctipt https://tinyurl.com/yylj3vcp | |
``` | |
```cs */ | |
#r "nuget: Microsoft.Extensions.DependencyInjection, 2.2.0" | |
#r "nuget: Microsoft.Extensions.Options, 1.0.0" |
This file contains 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
Get-ChildItem .\ -include bin,obj -Recurse | foreach ($_) { remove-item $_.fullname -Force -Recurse } |
This file contains 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
import zio._ | |
object ZLayerPlayground { | |
case class User(id: String, name: String) | |
class MongoDb { | |
def insertUser(user: User): Task[Unit] = Task.succeed(()) <* UIO(println(s"[MongoDb]: Inserted user $user")) | |
} | |
object MongoDbLayer { |
This file contains 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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net5.0</TargetFramework> | |
<LangVersion>preview</LangVersion> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0-preview.3.20215.2" /> | |
</ItemGroup> | |
<ItemGroup> |
This file contains 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
/* | |
sources: | |
- http://www.adammil.net/blog/v111_Creating_High-Performance_Locks_and_Lock-free_Code_for_NET_.html | |
- http://badamczewski.blogspot.com/2012/08/lock-free-and-spinwait-msdn-example.html | |
A better spin lock: | |
The result is a spin lock that's quite fast — about twice as fast as locking with a Monitor (or the C# lock statement). | |
(It can be further sped up slightly by breaking the Enter method into two methods: Enter, |
This file contains 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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net472</TargetFramework> | |
</PropertyGroup> | |
<PropertyGroup> | |
<GeneratedText><![CDATA[ | |
using System%3B |
This file contains 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 ImTools; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var map = ImHashMap<string, string>.Empty; | |
var map1 = map.AddOrUpdate("a", "42"); |
This file contains 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
private DictionarySlim<TypeVal, string> _dict; | |
public DictionarySlim<TypeVal, string> DictSlim() | |
{ | |
var dict = new DictionarySlim<TypeVal, string>(); | |
foreach (var key in _keys.Take(Count)) | |
dict.GetOrAddValueRef(key) = "a"; | |
dict.GetOrAddValueRef(typeof(ImHashMapBenchmarks)) = "!"; |
This file contains 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
module EnvDemo | |
open System | |
open System.IO | |
[<Struct>] | |
type Nothing = | |
private | |
| Nothing |
This file contains 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 | |
{ | |
// M wants to get an instance via Func | |
static void M(Func<string> factory) | |
{ | |
Console.WriteLine(factory()); | |
} |