Skip to content

Instantly share code, notes, and snippets.

Get ssh thumbprint or ssh fingerprint of every entry in known_hosts as json:

ssh-keygen -l -f known_hosts  | awk '{ print "{" "\042host\042:\042" $3 "\042" ",\042thumbprint\042:\042" $2 "\042" ",\042alg\042:\042" $4 "\042" ",\042size\042:\042" $1 "\042" "}"}' | sort | jtbl

formatted:

ssh-keygen -l -f known_hosts \
@djeikyb
djeikyb / InteropCancellationToken.cs
Last active March 1, 2024 18:54
How to cancel a long running native function — from c# — with a CancellationToken!
using System.Runtime.InteropServices;
using System.Threading;
[StructLayout(LayoutKind.Sequential)]
internal struct InteropCancellationToken
{
public InteropCancellationToken(CancellationToken ct)
{
IsCancellationRequested = () => ct.IsCancellationRequested;
}
@djeikyb
djeikyb / MelExtensions.cs
Last active December 22, 2023 01:41
Fluent methods to add scope state key-value pairs to your logs!
using Microsoft.Extensions.Logging;
public static class LogEx
{
public static ScopeStateBuilder<T> With<T>(this ILogger<T> logger, string k, object? v) => new(logger, k, v);
public sealed class ScopeStateBuilder<T> : ILogger<T>
{
private readonly ILogger<T> _logger;
private readonly IDictionary<string, object?> _state = new Dictionary<string, object?>();
@djeikyb
djeikyb / Program.cs
Created October 16, 2023 23:26
Rabbitmq, MassTransit, & the dotnet generic host in a cli program.
using System.ComponentModel.DataAnnotations;
using System.Net.Mime;
using System.Text;
using MassTransit;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
@djeikyb
djeikyb / flatten
Last active October 10, 2023 21:04
Turns an appsettings.json into flat json of key-value pairs, or, shell friendly list of plain key-value pairs
#!/bin/sh
toEnvVars() {
toFlatJson "$1" | jq --raw-output '. | to_entries[] | "\(.key)=\(.value)"'
}
toFlatJson() {
# thank you jeff mercado https://stackoverflow.com/a/42303836/659715
jq --arg delim '__' 'reduce (tostream|select(length==2)) as $i ({};
.[[$i[0][]|tostring]|join($delim)] = $i[1]
public static (X509Certificate2, RSA) Read(string publicCert, string privateKeyPemTaggedOrNot)
{
var rsa = RSA.Create();
if (privateKeyPemTaggedOrNot.StartsWith("-----BEGIN RSA PRIVATE KEY-----"))
{
rsa.ImportFromPem(privateKeyPemTaggedOrNot);
}
else
{
var key = Convert.FromBase64String(privateKeyPemTaggedOrNot);
@djeikyb
djeikyb / 20220504.gitconfig
Created May 4, 2023 19:43
current gitconfig
[user]
name = Jacob
email = jace42@thegoogles.mail
[alias]
unstage = restore --staged
changelog = log --format='* %s%n%w(,4,4)%+b'
pick = cherry-pick
ll = log --graph --pretty=format:'%C(auto)%h %ad %d %s %C(white)[%aN]' --date='format:%y·%b·%d' --use-mailmap
l = ll --remotes='origin/head' origin/head~5..HEAD
@djeikyb
djeikyb / GitlabClient.cs
Last active December 9, 2022 19:13
Gitlab client with only a couple label endpoints implemented
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
class GitlabClient
{
private readonly HttpClient _client;
public GitlabClient(HttpClient client, string token)
@djeikyb
djeikyb / git-wc
Last active October 6, 2022 18:37
A word counter for git messages
#!/bin/sh
countWords() {
commit="$1"
word_count=$(git show --format='%B' --no-patch "$commit" | wc -w)
auth="$(git show --format='%h %aN / %cN' --no-patch $commit)"
echo "$word_count $auth"
exit 0
}
@djeikyb
djeikyb / pg.sh
Last active July 26, 2022 18:00
another script to assist back and restore between local postgres and remote
#!/bin/sh
SELF=${0##*/}
setPgEnvVars() {
# consult `man test` for conditionals
if [ -z "$1" ]; then
usage
die "Missing aws env argument, like dev or live"
fi