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
/** | |
* Find into all collections. | |
* | |
* @param {{}} query | |
* @param {[]} fields | |
* @param {{}} sort | |
* | |
* @return {Array} | |
*/ | |
function findAll(query, fields, sort) { |
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
const createSelector = (...selectors) => { | |
let last = selectors.pop(); | |
return state => { | |
let args = selectors.map(selector => selector(state)); | |
return last.apply(null, args); | |
} | |
}; |
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
// tslint:disable:no-any directive-selector | |
import { Directive, Input, TemplateRef, ViewContainerRef } from '@angular/core'; | |
/** | |
* Declare a variable in the template. | |
* Eg. <i *ngVar="false as variable">{{ variable | json }}</i> | |
*/ | |
@Directive({selector: '[ngVar]'}) | |
export class NgVarDirective { |
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
alert('I am stealing your local storage... ha-ha'); | |
console.log(localStorage); |
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
<canvas id=canvas width=360 height=360> |
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
// The core function is ported from clipboard.js | |
// https://github.com/zenorocha/clipboard.js/ | |
const isCopySupported = (doc: Document): boolean => { | |
return Boolean(doc.queryCommandSupported && doc.queryCommandSupported('copy')); | |
}; | |
/** | |
* Creates a fake textarea element, sets its value from `text` property, | |
* and makes a selection on it. |
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 { FormControl } from '@angular/forms'; | |
import { concat, of, Observable } from 'rxjs'; | |
import { map } from 'rxjs/operators'; | |
type Nullable<T> = T | null; | |
/** | |
* @see AbstractControl.status | |
*/ | |
export enum RxFormControlStatus { |
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
/** | |
* Convert zoom level to range. | |
* | |
* @param {number} zoomLevel The zoom level in meters | |
* @param {number} latitude The latitude in radians | |
* @param {number} canvasWidth The canvas width in px | |
* @param {number} scaleFactor The scale factor (e.g. window.devicePixelRatio) | |
* @param {number} fov The FOV in degrees (e.g. 60) | |
* @param {number} globeRadius The globe radius in meters (e.g. 6378137) | |
* |
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
const zeroPad = (n: number) => n < 10 ? '0' + n : String(n); | |
const getTimezoneStr = (date: Date): string => { | |
const tz_offset_min = date.getTimezoneOffset(); | |
const offset_hrs = Math.abs(tz_offset_min / 60); | |
const offset_min = Math.abs(tz_offset_min % 60); | |
return tz_offset_min === 0 | |
? 'Z' | |
: `${tz_offset_min > 0 ? '-' : '+'}${zeroPad(offset_hrs)}:${zeroPad(offset_min)}`; |
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 { BehaviorSubject, Observable, Subscription } from 'rxjs'; | |
export class RxRpc<P, R> { | |
constructor(private readonly cmd: (params: P) => Observable<R>) {} | |
private subscription: Subscription | null = null; | |
private readonly _pending$ = new BehaviorSubject(false); | |
public readonly pending$ = this._pending$.asObservable(); |
OlderNewer