Skip to content

Instantly share code, notes, and snippets.

@rquackenbush
rquackenbush / Columnizer.cs
Last active January 5, 2023 18:15
Text columnizer
using System.Text;
namespace ConsoleApp1
{
public static class Columnizer
{
public static IEnumerable<string> Columnize(IList<string> headers, IList<string[]> rows, string separator = " ")
{
// Start with the lengths of the column headers
int[] columnWidths = headers
@rquackenbush
rquackenbush / RemoveLastTriplet.cs
Created August 11, 2022 18:52
One (non-optimized) solution for a Stack Overflow question.
using System;
using System.Collections.Generic;
/*
Example 1
input : nums = [2,4,2,2,7,5,6,7,8,6,6,2,6,7,6]
output : nums = [2,4,5,6,8,6]
Example 2 input : nums = [2,2,3,2,3,2]
output : nums = [2,3,3]
@rquackenbush
rquackenbush / DictionaryExtensions.cs
Created August 4, 2022 15:07
Simple extension method to pull a subtyped value from a dictionary.
using System.Collections.Generic;
public static class IDictionaryExtensions
{
public static bool TryGetValue<TKey, TOutValue, TInValue>(this IDictionary<TKey, TInValue> source, TKey key, out TOutValue value)
where TInValue : TOutValue
{
if (source.TryGetValue(key, out var temp))
{
value= temp;
@rquackenbush
rquackenbush / AsyncEnumerableExtensions.cs
Last active July 27, 2022 16:41
A simple batching bit of code for IAsyncEnumerable.
using System.Runtime.CompilerServices;
namespace Extensions.Core;
public static class AsyncEnumerableExtensions
{
public static async IAsyncEnumerable<T[]> BatchAsync<T>(
this IAsyncEnumerable<T> source,
int batchSize,
[EnumeratorCancellation] CancellationToken cancellationToken = default)
@rquackenbush
rquackenbush / ping-google.sh
Created February 24, 2021 04:14
Ping with timestamp and tee to a file.
#!/bin/bash
mkdir -p ping-logs
filename=ping-logs/$(date +"%m-%d-%Y %T")_internet.log
echo $filename
ping www.google.com | while read endlooop; do echo "$(date): $endlooop"; done | tee "$filename"
@rquackenbush
rquackenbush / Timestamped.cs
Created December 7, 2020 19:03
Simple wrapper call that wraps another thing with a timestamp.
using System;
namespace Foo
{
/// <summary>
/// Simple wrapper to add a timestamp to another item.
/// </summary>
/// <typeparam name="T"></typeparam>
public class Timestamped<T>
{
using ClickHouse.Ado;
using System;
using System.Data;
namespace ClickHouseTest
{
class Program
{
static ClickHouseConnectionSettings connectionSettings = new ClickHouseConnectionSettings("xxxxx");
@rquackenbush
rquackenbush / cert-manager.sh
Created April 2, 2020 19:41
Debugging cert-manager issues
kubectl get certificaterequest
kubectl describe certificaterequest X
kubectl get order
kubectl describe order X
kubectl get challenge
kubectl describe challenge X
@rquackenbush
rquackenbush / SymmetricKey.cs
Created March 25, 2020 17:39
Symmetric key validation
using System;
using System.Diagnostics;
using System.Linq;
using System.Security.Cryptography;
namespace SymmetricKeyTest
{
class Program
{
static void Main(string[] args)
@rquackenbush
rquackenbush / RSASignAndVerify.cs
Created March 25, 2020 17:37
Example of RSA Sign and Verify
using System.Security.Cryptography;
using Xunit;
namespace TpmTest.Tests
{
public class StandaloneRsaTests
{
[Fact]
public void Test()
{