Skip to content

Instantly share code, notes, and snippets.

View AArnott's full-sized avatar

Andrew Arnott AArnott

View GitHub Profile
@AArnott
AArnott / repack.ps1
Last active February 23, 2022 22:57
Repack a NuGet package with a new ID
<#
.SYNOPSIS
Creates a package with the same content as another package, but with a new ID.
.PARAMETER Id
The original ID of the package to download.
.PARAMETER NewId
The ID of the package to create.
.PARAMETER Version
The version of the package to download.
.PARAMETER OutDir
[alias]
co = checkout
nb = checkout -b
b = branch
ci = commit
fix = commit --amend --no-edit
cp = cherry-pick
undo = reset --soft HEAD^
st = status
f = fetch origin
@AArnott
AArnott / NativeMethods.txt
Last active December 16, 2024 10:28
How to kill child processes when the parent process dies
CreateJobObject
JOBOBJECT_EXTENDED_LIMIT_INFORMATION
SetInformationJobObject
AssignProcessToJobObject
@AArnott
AArnott / etlsteps.md
Last active March 15, 2021 14:00
Steps to collect an ETL trace
  1. Download the PerfView tool (for free) from https://github.com/Microsoft/perfview/blob/master/documentation/Downloading.md
  2. Once you have it open, you can see "Collect" in the menu bar at the top. Click on "Collect" and then "Run". Note this may re-launch PerfView in an elevated process, in which case you may need repeat this step in the elevated window.
  3. The "Collecting ETW Data while running a command" dialog will pop up. In the Command section, put in the full path for Visual Studio. It'll look like this: "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe" Don't forget to add in the quotation marks!
  4. Change the Current Dir field to a directory where the ETL trace files should be created.
  5. Below the "Current Dir" section, you can see "Thread Time." Please make sure it's checked.
  6. Ensure the "Zip" checkbox is checked.
  7. Expand "Advanced Options". Ensure the "No V3.X NGEN Symbols" checkbox is checked.
  8. Click "Run Command"
  9. This will start an instance of Visual Studio.

Keybase proof

I hereby claim:

  • I am aarnott on github.
  • I am aarnott (https://keybase.io/aarnott) on keybase.
  • I have a public key whose fingerprint is 1E96 8D82 6520 35A8 73DF E2B2 A9B9 910C DCCD A441

To claim this, I am signing this object:

@AArnott
AArnott / AzureKeyVaultSample.cs
Last active May 23, 2023 15:37
A sample of how to obtain a secret value from Azure Key Vault using implicit auth via ADAL and your AD account
using System;
using System.Configuration;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.KeyVault; // Install-Package Microsoft.Azure.KeyVault
using Microsoft.IdentityModel.Clients.ActiveDirectory; // Install-Package Microsoft.IdentityModel.Clients.ActiveDirectory
namespace KeyVaultSample
{
class Program
@AArnott
AArnott / ThrottleParallelWork.cs
Created May 11, 2017 15:55
Sample of a method that throttles concurrent work to avoid flooding the threadpool queue
Task ThrottleParallelWorkAsync(IEnumerable<T> data, Action<T> worker)
{
TaskScheduler scheduler = new ConcurrentExclusiveSchedulerPair(
TaskScheduler.Default, // schedule work to the ThreadPool
Environment.ProcessorCount * 2) // Schedule enough to keep all threads busy, with a queue to quickly replace completed work
.ConcurrentScheduler; // We only use the concurrent member of this scheduler "pair".
return Task.WhenAll(
data.Select(v => Task.Factory.StartNew(() => worker(v), CancellationToken.None, TaskCreationOptions.None, scheduler)));
}
@AArnott
AArnott / UnboundedThreadPoolQueueWithTracking.cs
Last active May 11, 2017 15:12
Simple example of highly concurrent work that is tracked
Task PerformConcurrentWorkAsync<T>(IEnumerable<T> data, Action<T> worker)
{
return Task.WhenAll(data.Select(v => Task.Run(() => worker(v))));
}
@AArnott
AArnott / SimpleConcurrency.cs
Created May 11, 2017 15:07
Trivial example of unbounded flooding of the threadpool queue
void WorkOnCollectionConcurrently(IEnumerable<T> data, Action<T> worker)
{
foreach (T item in data)
{
Task.Run(() => worker(item));
}
}
@AArnott
AArnott / ThrottleDemo.cs
Last active March 1, 2021 21:28
Demonstrates scheduling unbounded work and applying a throttle to keep the threadpool responsive.
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
class Program
{
static void Main(string[] args)
{
Console.WriteLine("*** WITHOUT throttling ***");