Skip to content

Instantly share code, notes, and snippets.

View onyxmaster's full-sized avatar
💭
NO TO WAR! 🕊

Aristarkh Zagorodnikov onyxmaster

💭
NO TO WAR! 🕊
View GitHub Profile
using MongoDB.Driver;
using MongoDB.Driver.Linq;
var filter = Builders<Document>.Filter.Gt(v => v.S, 1);
var settings = MongoClientSettings.FromConnectionString("mongodb://localhost:27017");
foreach (var provider in Enum.GetValues<LinqProvider>())
{
settings.LinqProvider = provider;
Console.Write($"Provider {provider}: ");
try
[Fact]
public void DictionaryPreservesInsertionOrder()
{
var dictionary = new Dictionary<int, int>();
dictionary.Add(0, 0);
dictionary.Add(1, 1);
dictionary.Remove(0);
dictionary.Add(2, 2);
Assert.Equal(new int[] { 1, 2 }, dictionary.Keys);
}
// Filter only active items
record Item(DateTime ActiveUntil);
IReadOnlyCollection<Item> GetActiveItems(IEnumerable<Item> items) => items.Where(item => item.ActiveUntil > DateTime.Now).ToArray();
/* ******************************************************************** */
// Robustly perform an [idempotent] request until timeout is reached
void PerformRequestRobustly(TimeSpan timeout)
{
var retryUntil = DateTime.UtcNow + timeout;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
namespace OrderedDictionary
{
internal class OrderedDictionary<TKey, TValue> : IDictionary<TKey, TValue> where TKey : notnull
{
private readonly Dictionary<TKey, LinkedListNode<KeyValuePair<TKey, TValue>>> _dictionary = new();
private readonly LinkedList<KeyValuePair<TKey, TValue>> _linkedList = new();
@onyxmaster
onyxmaster / WriteFrameworkVersions.cmd
Created November 21, 2018 14:35
A simple tool to write out target framework for a project, handles legacy (TargetFrameworkVersion) and new (TargetFramework) projects
@"%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\amd64\MSBuild.exe" /nologo /clp:DisableConsoleColor;NoSummary /v:m /p:TargetProject="%~f1" "%~dp0%WriteFrameworkVersions.targets"
/// <summary>
/// Represents a 64-bit entity identifier.
/// </summary>
///
/// <typeparam name="TEntity">The entity type.</typeparam>
///
/// <threadsafety static="true" instance="true" immutable="true"/>
[System.ComponentModel.TypeConverter(typeof(EntityIdConverter))]
public struct EntityId<TEntity> : IEquatable<EntityId<TEntity>>, IComparable<EntityId<TEntity>>
where TEntity : class
diff --git a/src/PerfView/CommandProcessor.cs b/src/PerfView/CommandProcessor.cs
index cda121c..1d71717 100644
--- a/src/PerfView/CommandProcessor.cs
+++ b/src/PerfView/CommandProcessor.cs
@@ -562,17 +562,22 @@ namespace PerfView
ClrPrivateTraceEventParser.Keywords.Stack
));
- // Used to determine what is going on with tasks.
- var netTaskStacks = stacksEnabled;
using System;
using System.Collections.Generic;
using System.Reflection;
using Dnet.Reflection;
using SimpleInjector;
using SimpleInjector.Diagnostics;
namespace Dnet.Composition.Composition
public interface IA
{
Task F();
}
public class A : IA
{
public async Task F() => await Task.Delay(0).ConfigureAwait(false);
}
@onyxmaster
onyxmaster / netcore2.config
Last active August 17, 2017 09:22
An Amazon Elastic Beanstalk .ebextensions config to get .NET Core 2.0 working on existing AMIs (http://xm.x-infinity.com/2017/08/net-core-20-in-aws-elasticbeanstalk.html)
files:
"C:\\Users\\Administrator\\Documents\\installnetcore2.ps1":
content: |
if (!(Test-Path -path 'C:\Program Files\dotnet\shared\Microsoft.NETCore.App\2.0.0\')) {
$url = "https://download.microsoft.com/download/B/1/D/B1D7D5BF-3920-47AA-94BD-7A6E48822F18/DotNetCore.2.0.0-WindowsHosting.exe"
$path = "C:\Users\Administrator\Downloads\DotNetCore.2.0.0-WindowsHosting.exe"
(New-Object System.Net.WebClient).DownloadFile($url, $path)
&$path /quiet
Start-Sleep -s 5
Remove-Item $path