This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<#@ 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Subscription } from "rxjs"; | |
export class Subscriptions { | |
private readonly subscriptions = new Array<Subscription>(); | |
push(subscription: Subscription): void { | |
this.subscriptions.push(subscription); | |
} | |
unsubscribeAll(): void { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
* } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ...> | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'] | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Person { | |
name!: string; | |
age!: number; | |
sex!: string; | |
public toString = () : string => JSON.stringify(this); | |
} | |
const people: Person[] = [ | |
{ age: 25, sex: 'f', name: 'Sue' }, | |
{ age: 30, sex: 'f', name: 'Angela' }, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Public Sub tojson() | |
Dim fso As Object | |
Set fso = CreateObject("Scripting.FileSystemObject") | |
jsonFilename = fso.GetBaseName(ActiveWorkbook.Name) & ".json" | |
fullFilePath = Application.ActiveWorkbook.Path & "\" & jsonFilename | |
Dim fileStream As Object | |
Set fileStream = CreateObject("ADODB.Stream") | |
fileStream.Type = 2 'Specify stream type - we want To save text/string data. | |
fileStream.Charset = "utf-8" 'Specify charset For the source text data. |