This file contains hidden or 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
internal static class ColorHelpers | |
{ | |
/// <summary> | |
/// Converts HSL color value to RGB fractional color value | |
/// </summary> | |
/// <param name="hue">Hue angle value between [0,360]</param> | |
/// <param name="saturation">Saturation value between [0,1]</param> | |
/// <param name="lightness">Lightness value between [0,1]</param> | |
/// <returns>RGB color values, with each value between [0,1]</returns> | |
/// <see href="https://en.wikipedia.org/wiki/HSL_and_HSV#HSL_to_RGB_alternative"/> |
This file contains hidden or 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 System.Collections.Generic; | |
using System.Runtime.CompilerServices; | |
using System.Threading; | |
using System.Threading.Channels; | |
public static class ChannelReaderExtensions | |
{ | |
/// <summary> | |
/// Creates an <see cref="IAsyncEnumerable{T}"/> that enables reading all of the data from the channel |
This file contains hidden or 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
public class AsyncLock | |
{ | |
private readonly SemaphoreSlim semaphore = new SemaphoreSlim(1, 1); | |
private readonly Task<IDisposable> releaser; | |
public AsyncLock() | |
{ | |
releaser = Task.FromResult((IDisposable)new AsyncLockReleaser(this)); | |
} |
This file contains hidden or 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.Numerics; | |
/// <summary> | |
/// Round the given integral value down to a power of 2. | |
/// This is the equivalent to returning a number with a single bit set at the most significant location a bit is set in the input value. | |
/// </summary> | |
/// <param name="value">The value.</param> | |
/// <returns> | |
/// The smallest power of 2 which is less than or equal to <paramref name="value"/>. | |
/// If <paramref name="value"/> is 0 or the result overflows, returns 0. |
This file contains hidden or 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
# Script to switch between wired LAN and WiFi on Surface Book and MS Dock. | |
# Initially, one should be disabled and the other enabled. The script will then flip their states. | |
[string]$wifi_ifdesc = 'Marvell AVASTAR Wireless-AC Network Controller' | |
[string]$eth_ifdesc = 'Surface Ethernet Adapter #2' | |
if((Get-NetAdapter -InterfaceDescription $wifi_ifdesc).Status -eq 'Disabled') { | |
# Switch to Wifi | |
Write-Output 'Switching to WiFi' | |
This file contains hidden or 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
# Powershell script to automatically open a putty window for each serial port on the computer | |
param ( | |
[string]$baud = "115200" | |
) | |
$serialreg = Get-Item -Path Registry::HKEY_LOCAL_MACHINE\HARDWARE\DEVICEMAP\SERIALCOMM | |
foreach ($thisname in $serialreg.GetValueNames()) | |
{ |
This file contains hidden or 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
#!/bin/bash | |
# Dynamic DNS auto-update script for CloudFlare API | |
# Version 3 - Ryan Crosby 2023 | |
# | |
# Supports IPv4 and IPv6 (A and AAAA records) | |
# | |
# Requires curl and jq | |
echo "Dynamic DNS auto-update script for CloudFlare API" |
This file contains hidden or 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
// Copyright 2021 Ryan Crosby | |
// This code is licensed under the MIT license | |
using System; | |
using System.Text; | |
using System.Text.RegularExpressions; | |
// ... | |
public static class PathGlobbingHelpers |
This file contains hidden or 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
public static class IntExtensions | |
{ | |
public static uint GetNextPowerOfTwo(this uint input) | |
{ | |
--input; | |
input |= input >> 1; | |
input |= input >> 2; | |
input |= input >> 4; | |
input |= input >> 8; | |
input |= input >> 16; |
This file contains hidden or 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.Threading; | |
using System.Threading.Tasks; | |
public static class CancellationTokenExtensions | |
{ | |
public static async Task WhenCancelled(this CancellationToken cancellationToken) | |
{ | |
TaskCompletionSource<bool> taskCompletionSource = new TaskCompletionSource<bool>(); |
NewerOlder