Skip to content

Instantly share code, notes, and snippets.

Nick Strupat NickStrupat

Block or report user

Report or block NickStrupat

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
NickStrupat / StrupHash.cs
Created Oct 15, 2019
pinning byte[] before page alignment calculation
View StrupHash.cs
using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace StrupHash
class Program
static unsafe void Main(string[] args)
View map-wrappers.ts
class MapWrapper implements Map<string, any> {
constructor(readonly object: any) {}
clear(): void {
for (let key of this.keys())
delete this.object[key];
delete(key: string): boolean {
if (!this.has(key))
return false;
NickStrupat / crypto.ts
Created Sep 17, 2019
Small class for generating public-private key pairs, signing, and verifying signatures
View crypto.ts
import { sign } from "tweetnacl"
import { decodeUTF8 } from "tweetnacl-util";
export class Crypto {
private constructor() {}
static generateKeys(): CryptoKeyPair {
const naclKeyPair = sign.keyPair();
return new CryptoKeyPair(naclKeyPair.publicKey, naclKeyPair.secretKey);
NickStrupat / get-all-key-value-pairs.ts
Created Sep 17, 2019
Get an object as iterable pairs of eval-able keys and values
View get-all-key-value-pairs.ts
function * getAllKeyValuePairs(o: any, key: string): IterableIterator<[string, string]> {
if (o instanceof Map) {
for (let element of o.entries())
yield * getAllKeyValuePairs(element[1], `${key}.get("${element[0]}")`);
else if (o instanceof Date) {
for (let languageCode of ['en', 'fr'])
yield * getAllKeyValuePairs(o.toLocaleString(languageCode), `${key}.toLocaleString("${languageCode}")`);
else if (o instanceof Array) {
View gist:f05d8993853718a2dbc23de5c7a1c575
public static class Extensions
public static Rune[] ToArray(this SpanUtf8BytesRuneEnumerator enumerator)
Span<Rune> runes = stackalloc Rune[enumerator.remaining.Length];
var i = 0;
foreach (var utf8BytesRune in enumerator)
runes[i++] = utf8BytesRune;
var result = new Rune[i];
runes.Slice(0, i).CopyTo(result);
View AsyncProgram.cs
using System.Threading;
using System.Threading.Tasks;
public static class AsyncProgram
private static readonly CancellationTokenSource cts = new CancellationTokenSource();
static AsyncProgram() => Console.CancelKeyPress += (s, e) => cts.Cancel();
public static CancellationToken CancellationToken => cts.Token;
NickStrupat /
Last active Jul 24, 2019
install .NET Core 3.0 Preview 7 on Raspbian Buster
sudo apt install -y libicu63, libssl1.1
curl -o dotnet3pre7
mkdir -p /opt/dotnet && tar zxf dotnet3pre7 -C /opt/dotnet
if ! grep -q 'export DOTNET_ROOT=/opt/dotnet' ~/.bash_profile; then echo "export DOTNET_ROOT=/opt/dotnet" >> ~/.bash_profile; fi
sudo ln -s /opt/dotnet/dotnet /usr/bin/dotnet
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
<# var maxDimensions = 32; #>
using System;
using System.Collections.Generic;
View ArrayEnumerableExtensions.cs
using System;
using System.Collections.Generic;
public static class ArrayEnumerableExtensions
public static IEnumerable<T> AsEnumerable<T>(this Array array)
if (array is null)
throw new ArgumentNullException(nameof(array));
View property-names.ts
type NonFunctionPropertyNames<T> = { [K in keyof T]: T[K] extends Function ? never : K }[keyof T];
export function getPropertyNames<T>(defaultInstance: T): NonFunctionPropertyNames<T>[] {
const memberNames = Object.getOwnPropertyNames(defaultInstance); // get all members of the instance
const propertyNames = memberNames.filter(x => typeof (defaultInstance as any)[x] != "function"); // filter out functions
return propertyNames as NonFunctionPropertyNames<T>[]; // cast as array of string union of non-function properties (ideally would be a string typed tuple but can't be done yet)
export function createFromObject<T>(constructor: { new(): T }, parameters: Partial<T>): T {
const newInstance = new constructor();
You can’t perform that action at this time.