Skip to content

Instantly share code, notes, and snippets.

View AArnott's full-sized avatar

Andrew Arnott AArnott

View GitHub Profile
@AArnott
AArnott / EncyptionTools.ps1
Created June 24, 2024 17:04
Powershell functions for asymmetric encryption and decryption of data with an arbitrary length
Function Encrypt-DataAsymmetric {
[CmdletBinding()]
Param
(
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 0)]
[byte[]]$Data,
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true, Position = 1)]
[byte[]]$PublicKey
)
@AArnott
AArnott / azp-agent-linux.dockerfile
Created June 22, 2024 17:08
Scripts and dockerfile for running a private Azure Pipelines build agent on linux that supports jobs that create their own docker containers
# Inspired by https://github.com/MicrosoftDocs/azure-devops-docs/blob/main/docs/pipelines/agents/docker.md#linux
FROM ubuntu:22.04
ENV TARGETARCH="linux-x64"
# Also can be "linux-arm", "linux-arm64".
# Add a Capability that pipelines can filter to when they require a linux agent that supports creating docker containers.
ENV HasDockerAccess="true"
RUN apt-get update
RUN apt-get upgrade -y
@AArnott
AArnott / ConcurrentVsOrdinaryDictionary.cs
Last active May 11, 2022 08:33
The .NET Concurrent collections are often used as a thread-safe version of the ordinary collections. But they are *far* slower and heavier on GC pressure than simply adding a `lock` around use of the ordinary collections. Avoid the concurrent collections except in highly concurrent scenarios where you see high lock contention and therefore may b…
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
class Program
{
static void Main(string[] args)
{
var ordinary = RunTest(OrdinaryDictionaryRun);
@AArnott
AArnott / PatGenerator.cs
Created April 8, 2019 20:51
Securely generates new PATs. Useful for a service that wants to issue PATs to users.
using System;
using System.Security.Cryptography;
public static class SecurityUtilities
{
static void Main(string[] args)
{
Console.WriteLine(GeneratePat());
Console.WriteLine(GeneratePat());
Console.WriteLine(GeneratePat());
@AArnott
AArnott / Cancellation.cs
Last active December 12, 2023 16:33
Graceful console app cancellation on Ctrl+C
class Program
{
static async Task Main(string[] args)
{
// Add this to your C# console app's Main method to give yourself
// a CancellationToken that is canceled when the user hits Ctrl+C.
var cts = new CancellationTokenSource();
Console.CancelKeyPress += (s, e) =>
{
Console.WriteLine("Canceling...");
@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
ci = commit
st = status
p = push origin -u HEAD
goback = reset --hard HEAD~1
[core]
safecrlf = warn
preloadindex = true
fscache = true
@AArnott
AArnott / NativeMethods.txt
Last active June 4, 2022 19:49
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: