Skip to content

Instantly share code, notes, and snippets.

View jpmikkers's full-sized avatar
😁

Jean-Paul Mikkers jpmikkers

😁
View GitHub Profile
@jpmikkers
jpmikkers / nostr.txt
Created July 7, 2023 11:55
nostr.txt
Verifying that I control the following Nostr public key: npub1t7uc9qtrtj8ll8ys67lhsnkn35xn6q8f9phs5rv058asamacsnnqwztra0
@jpmikkers
jpmikkers / notnullext.cs
Last active December 26, 2021 16:29
NotNull IEnumerable extension, converts from IEnumerable<T?> to IEnumerable<T>
public static class IEnumerableExtensions
{
[Pure]
public static IEnumerable<T> NotNull<T>(this IEnumerable<T?> enumerable) where T : class
=> enumerable.Where(e => e is not null).Select(e => e!);
[Pure]
public static IEnumerable<T> NotNull<T>(this IEnumerable<T?> enumerable) where T : struct
=> enumerable.Where(e => e.HasValue).Select(e => e!.Value);
}
@jpmikkers
jpmikkers / FindMainAddresses.ps1
Created September 25, 2020 12:17
Find the local ipv4 addresses of the network adapter handling your internet connection
$gateway = '192.168.1.1' # this should be the ip address of your router, presumably that is reasonably constant for most systems.
$baseadapter = Get-NetIPConfiguration |
where { $_.IPv4DefaultGateway.NextHop -eq $gateway} |
select -First 1 | Get-NetAdapter
if($baseadapter -eq $null)
{
throw "Could not find base adapter"
}
@jpmikkers
jpmikkers / totp.ps1
Last active October 24, 2019 23:00 — forked from jonfriesen/totp.ps1
TOTP Client for PowerShell
<#
.SYNOPSIS
Time-base One-Time Password Algorithm (RFC 6238)
.DESCRIPTION
This is an implementation of the RFC 6238 Time-Based One-Time Password Algorithm draft
based upon the HMAC-based One-Time Password (HOTP) algorithm (RFC 4226). This is a time
based variant of the HOTP algorithm providing short-lived OTP values.
#>
@jpmikkers
jpmikkers / packcircles.cs
Created September 26, 2019 20:48
Packed circles solver for three circles with three known radii and two known positions.
/// <summary>
/// Given two circles with known positions and radii, and one circle of known radius and unknown position,
/// calculate the position of the third circle so it exactly touches the other circles.
/// </summary>
/// <param name="x1">x coordinate of circle 1</param>
/// <param name="y1">y coordinate of circle 1</param>
/// <param name="r1">radius of circle 1</param>
/// <param name="x2">x coordinate of circle 2</param>
/// <param name="y2">y coordinate of circle 2</param>
/// <param name="r2">radius of circle 2</param>
@jpmikkers
jpmikkers / keybase.md
Created September 12, 2019 22:40
Keybase.md

Keybase proof

I hereby claim:

  • I am jpmikkers on github.
  • I am jpmikkers (https://keybase.io/jpmikkers) on keybase.
  • I have a public key ASA2O9WXA2m3Bij_0CvXwmgnuVY4cCbiqRKbGa3Py177RQo

To claim this, I am signing this object:

http://stackoverflow.com/questions/2094694/how-can-i-run-powershell-with-the-net-4-runtime
https://gist.github.com/jstangroome/882528
@jpmikkers
jpmikkers / slidingwindowminimum.cs
Created January 13, 2016 23:16
Streaming sliding window minimum
// see http://people.cs.uct.ac.za/~ksmith/articles/sliding_window_minimum.html
public class SlidingWindowMinimum<T> where T : IComparable
{
private struct Item
{
public long TimeStamp;
public T Value;
}
private long m_Counter;
@jpmikkers
jpmikkers / ProducerToConsumerStream.cs
Created November 29, 2015 23:43
A writeonly stream (aka 'producer') that siphons data to a readonly stream (aka 'consumer'), which it creates and passes to a delegate Action. This is handy if you want to serialize huge objects to WCF interfaces that use streamed transfer modes, without having to buffer all the data in memory.
/*
Copyright (c) 2015 Jean-Paul Mikkers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@jpmikkers
jpmikkers / siphonstream.cs
Created November 25, 2015 23:49
Siphonstream is a readonly stream that siphons data from a writeonly stream, which it creates and passes to a delegate Action. This is handy if you want to serialize huge objects to WCF interfaces that use streamed transfer modes, without having to buffer all the data in memory.
/*
Copyright (c) 2015 Jean-Paul Mikkers
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions: