Skip to content

Instantly share code, notes, and snippets.

View svick's full-sized avatar

Petr Onderka svick

View GitHub Profile
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Running;
using BenchmarkDotNet.Toolchains.CsProj;
using static Modified.Extensions;
public class Program
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.11.0" />
<PackageReference Include="Microsoft.NET.HostModel" Version="3.1.16" />
using System.Text.Json;
using System.Text.Json.Serialization;
string json = """
{
"ISBN:9780544003415": {
"bib_key": "ISBN:9780544003415",
"info_url": "https://openlibrary.org/books/OL26885115M/The_lord_of_the_rings"
}
}
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Diagnosers;
using BenchmarkDotNet.Running;
public class Program
{
static void Main() => BenchmarkRunner.Run<Benchmark>();
using var stream = File.OpenText(@"C:\Users\Svick\Desktop\iso-639-3.tab");
using var reader = new CsvReader(stream, new(CultureInfo.InvariantCulture) { Delimiter = "\t" });
var dict = reader.GetRecords(new { Id = "", Ref_Name = "" }).ToDictionary(x => x.Id, x => x.Ref_Name);
CultureInfo.GetCultures(CultureTypes.NeutralCultures)
.Where(c => c.TwoLetterISOLanguageName.Length > 2 && (!dict.TryGetValue(c.TwoLetterISOLanguageName, out string isoName) || isoName != c.EnglishName))
.Select(c => new { c.Name, c.TwoLetterISOLanguageName, c.EnglishName, IsoName = dict[c.TwoLetterISOLanguageName] })
.Dump();
void Main()
{
using var context = new WarehouseContext();
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
var apple = new Product { Name = "Apple" };
var pear = new Product { Name = "Pear" };
context.Products.AddRange(apple, pear);
using System;
var x = new S3Options { Bucket = "root" };
var y = new S3Options { I = 42 };
Console.WriteLine(y.Bucket);
public struct S3Options
{
public string Bucket { get; init; }
public int I { get; init; } = 0;
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Build" Version="16.11.0" ExcludeAssets="runtime" />
<PackageReference Include="Microsoft.Build.Locator" Version="1.4.1" />
@svick
svick / CallerInfoAttibuteNet4.cs
Created October 9, 2014 08:29
How to use caller info attributes on .Net 4.0
using System;
using System.Runtime.CompilerServices;
namespace System.Runtime.CompilerServices
{
class CallerMemberNameAttribute : Attribute
{ }
}
namespace ConsoleApplication1
#nullable enable
public static class JavaScriptExtensions
{
public static IEnumerator<(string name, object? value)> GetEnumerator(this object js)
{
var properties = js.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public);
foreach (var property in properties)
{
yield return (property.Name, property.GetValue(js));