Skip to content

Instantly share code, notes, and snippets.

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);
@NickStrupat
NickStrupat / raspi-install-dotnet-core-3.0.sh
Last active July 24, 2019 05:25
install .NET Core 3.0 Preview 7 on Raspbian Buster
sudo apt install -y libicu63, libssl1.1
curl -o dotnet3pre7 https://download.visualstudio.microsoft.com/download/pr/11d6ec80-4d7f-4100-8a54-809ed30b203e/1c0267225b22437aca9fdfe04160d1d5/dotnet-sdk-3.0.100-preview7-012821-linux-arm.tar.gz
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;
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));
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();
@NickStrupat
NickStrupat / subscriptions.ts
Created June 28, 2019 16:04
class for pushing in observable subscriptions in order and then unsubscribing from then in reverse order
import { Subscription } from "rxjs";
export class Subscriptions {
private readonly subscriptions = new Array<Subscription>();
push(subscription: Subscription): void {
this.subscriptions.push(subscription);
}
unsubscribeAll(): void {
import { HostBinding, OnDestroy, OnInit } from '@angular/core';
import { MediaObserver } from '@angular/flex-layout';
import { Subscription } from 'rxjs';
/**
* If you inherit (extend) your component from this class, the host element of your component will have a class added to it with the media query alias.
* For example...
*
* <app-search-bar class="some-class" _nghost-c5 ...>
*
import { strict as assert } from 'assert';
/**
* This class supports retrieving a class type name at run-time. It requires TypeScript decorators.
* Usage: Register the typename with `@TypeName.decorate(...)`
*
* @TypeName.decorate("Foo")
* class Foo {
* readonly text: string = "text";
* }
export class QueryablePromise<T> implements Promise<T> {
private readonly promise: Promise<T>;
private _isPending: boolean = true;
private _isRejected: boolean = false;
private _isFulfilled: boolean = false;
public get isPending(): boolean { return this._isPending; };
public get isRejected(): boolean { return this._isRejected; };
public get isFulfilled(): boolean { return this._isFulfilled; };
@NickStrupat
NickStrupat / ng-media-query-body-class.ts
Last active April 12, 2019 19:11
Add the media query alias to the body tag with angular flex-layout
import { Component, OnInit, OnDestroy, Inject, Renderer2 } from '@angular/core';
import { Subscription } from 'rxjs';
import { MediaObserver } from '@angular/flex-layout';
import { DOCUMENT } from '@angular/common';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})