Skip to content

Instantly share code, notes, and snippets.

View alexsanqp's full-sized avatar
💭
plus-minus

Oleksandr K. alexsanqp

💭
plus-minus
View GitHub Profile
@alexsanqp
alexsanqp / get-polygon-centroid.ts
Last active April 24, 2019 17:33
Polygon centroid - typescript or javascript
/**
* https://en.wikipedia.org/wiki/Centroid#Of_a_polygon
*/
public getPolygonCentroid(vertices: number[][]): { lat: number, lon: number } {
const centroid: { lat: number, lon: number } = { lat: 0, lon: 0 };
const vertexCount: number = vertices.length;
let area: number = 0;
let x0: number = 0; // Current vertex X
let y0: number = 0; // Current vertex Y
@alexsanqp
alexsanqp / dimension.class.ts
Last active April 24, 2019 17:28
The Dimension class encapsulates the width and height of a component (in integer precision) in a single object.
/**
* The Dimension class encapsulates the width and height
* of a component (in integer precision) in a single object.
*/
export class Dimension {
/**
* The width dimension; negative values can be used.
* @default 0
*/
protected width: number;
@alexsanqp
alexsanqp / point.class.ts
Last active April 24, 2019 17:28
A point representing a location in (x,y) coordinate space, specified in integer precision.
/**
* A point representing a location in (x,y) coordinate space, specified in integer precision.
*/
export class Point {
/**
* The X coordinate of this Point.
* @default 0
*/
protected x: number;
@alexsanqp
alexsanqp / run-outside-event-manager.service.ts
Last active April 25, 2019 12:52
Triggers an event listener outside the angular zone.
import { Inject, Injectable, NgZone } from '@angular/core';
import { EVENT_MANAGER_PLUGINS, EventManager } from '@angular/platform-browser';
export const RUN_OUTSIDE: string = '.run-outside';
/**
* @example
*
* @NgModule({
* // ...
export const memorizeFn = <T extends () => void>(fn: T, size = 5, duration = 0): any => {
const cache: Map<string, any> = new Map<string, any>();
if (duration) {
setInterval(() => cache.clear(), duration);
}
return (...args: any[]): any => {
const key: string = JSON.stringify(args);
if (!cache.has(key)) {
cache.set(key, (fn as any)(...args));
This file has been truncated, but you can view the full file.
[{"args":{"name":"swapper"},"cat":"__metadata","name":"thread_name","ph":"M","pid":0,"tid":0,"ts":0},
{"args":{"name":"Compositor"},"cat":"__metadata","name":"thread_name","ph":"M","pid":15676,"tid":13992,"ts":0},
{"args":{"name":"CrRendererMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":15676,"tid":364,"ts":0},
{"args":{"name":"CrBrowserMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":22488,"tid":15936,"ts":0},
{"args":{"name":"Chrome_IOThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":22488,"tid":10384,"ts":0},
{"args":{"name":"VizCompositorThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":33572,"tid":5576,"ts":0},
{"args":{"name":"GpuVSyncThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":33572,"tid":12292,"ts":0},
{"args":{"name":"CrGpuMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":33572,"tid":14628,"ts":0},
{"args":{"name":"Chrome_ChildIOThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":15676,"tid":32852,"ts"
This file has been truncated, but you can view the full file.
[{"args":{"name":"swapper"},"cat":"__metadata","name":"thread_name","ph":"M","pid":0,"tid":0,"ts":0},
{"args":{"name":"Compositor"},"cat":"__metadata","name":"thread_name","ph":"M","pid":22096,"tid":22068,"ts":0},
{"args":{"name":"ThreadPoolServiceThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":33572,"tid":6276,"ts":0},
{"args":{"name":"CrRendererMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":22096,"tid":10276,"ts":0},
{"args":{"name":"CrBrowserMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":22488,"tid":15936,"ts":0},
{"args":{"name":"Chrome_IOThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":22488,"tid":10384,"ts":0},
{"args":{"name":"VizCompositorThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":33572,"tid":5576,"ts":0},
{"args":{"name":"GpuVSyncThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":33572,"tid":12292,"ts":0},
{"args":{"name":"CrGpuMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":33572,"tid":14628,
This file has been truncated, but you can view the full file.
[{"args":{"name":"swapper"},"cat":"__metadata","name":"thread_name","ph":"M","pid":0,"tid":0,"ts":0},
{"args":{"name":"Compositor"},"cat":"__metadata","name":"thread_name","ph":"M","pid":15676,"tid":13992,"ts":0},
{"args":{"name":"CrRendererMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":15676,"tid":364,"ts":0},
{"args":{"name":"CrBrowserMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":22488,"tid":15936,"ts":0},
{"args":{"name":"Chrome_IOThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":22488,"tid":10384,"ts":0},
{"args":{"name":"VizCompositorThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":33572,"tid":5576,"ts":0},
{"args":{"name":"GpuVSyncThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":33572,"tid":12292,"ts":0},
{"args":{"name":"CrGpuMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":33572,"tid":14628,"ts":0},
{"args":{"name":"Chrome_ChildIOThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":15676,"tid":32852,"ts"
This file has been truncated, but you can view the full file.
[{"args":{"name":"swapper"},"cat":"__metadata","name":"thread_name","ph":"M","pid":0,"tid":0,"ts":0},
{"args":{"name":"Compositor"},"cat":"__metadata","name":"thread_name","ph":"M","pid":22096,"tid":22068,"ts":0},
{"args":{"name":"ThreadPoolServiceThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":33572,"tid":6276,"ts":0},
{"args":{"name":"CrRendererMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":22096,"tid":10276,"ts":0},
{"args":{"name":"CrBrowserMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":22488,"tid":15936,"ts":0},
{"args":{"name":"Chrome_IOThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":22488,"tid":10384,"ts":0},
{"args":{"name":"VizCompositorThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":33572,"tid":5576,"ts":0},
{"args":{"name":"GpuVSyncThread"},"cat":"__metadata","name":"thread_name","ph":"M","pid":33572,"tid":12292,"ts":0},
{"args":{"name":"CrGpuMain"},"cat":"__metadata","name":"thread_name","ph":"M","pid":33572,"tid":14628,