This file contains hidden or 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
// Source: https://stackoverflow.com/a/8435261 | |
function weightedRand(spec) { | |
let i, j, table = []; | |
for (i in spec) { | |
// The constant 10 below should be computed based on the | |
// weights in the spec for a correct and optimal table size. | |
// E.g. the spec {0:0.999, 1:0.001} will break this impl. | |
for (j = 0; j < spec[i] * 10; j++) { | |
table.push(i); |
This file contains hidden or 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 { Injectable } from '@angular/core'; | |
const Polyglot = require('node-polyglot'); // https://www.npmjs.com/package/node-polyglot | |
// Example of pl_pl.json file: { "Hello world":"Witaj świecie" } | |
let dictionaries = { | |
pl_pl: require('./pl_pl/pl_pl.json'), | |
en_gb: require('./en_gb/en_gb.json') | |
}; |
This file contains hidden or 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 { Injectable } from '@angular/core'; | |
import { HttpClient } from '@angular/common/http'; | |
import { Observable, ReplaySubject } from 'rxjs'; | |
@Injectable() | |
export class CachedService { | |
data$: Observable<any> = this.dataSubject.asObservable(); | |
private dataSubject = new ReplaySubject<any>(1); |
This file contains hidden or 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 { AfterContentInit, Component, Input, OnChanges, SimpleChanges } from '@angular/core'; | |
interface TabInterface{ | |
active: boolean; | |
name: string | |
} | |
@Component({ | |
selector: 'app-tab', | |
template: `<div class="tab" [hidden]="!active"><ng-content></ng-content></div>`, |
This file contains hidden or 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
function getOnlyModifiedValues(originalValues, newValues) { | |
let isObject = (o) => (typeof o === 'object' && o !== null); | |
let isEquals = (a, b) => (String(a).trim() === String(b).trim()); | |
let isEmpty = (o) => (Object.keys(o).length === 0); | |
function diff(a, b) { | |
return Object.keys(b).reduce((value, key) => { | |
let v1 = a[key]; | |
let v2 = b[key]; |
This file contains hidden or 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
@mixin element($e) { | |
&__#{$e} { @content; } | |
} | |
@mixin modifier($e) { | |
&--#{$e} { @content; } | |
} | |
.grid { | |
$gutter: 30px; |
This file contains hidden or 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
/** | |
* A collection of helper prototype for everyday DOM traversal, manipulation, | |
* and event binding. Sort of a minimalist jQuery, mainly for demonstration | |
* purposes. MIT @ m3g4p0p | |
*/ | |
window.$ = (function (undefined) { | |
/** | |
* Duration constants | |
* @type {Object} |
This file contains hidden or 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
runas /profile /user:Administrator /savecred "notepad C:\Windows\System32\drivers\etc\hosts" |
This file contains hidden or 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
function invokeOnce($element, eventType, handler, useCapture = false) { | |
var args = arguments; | |
$element.addEventListener(eventType, function selfRemoving(event) { | |
event.target.removeEventListener(event.type, selfRemoving, useCapture); | |
return handler.apply(handler, args); | |
}); | |
} |
This file contains hidden or 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
(function (root) { | |
var canvas = document.createElement('canvas'); | |
var context = canvas.getContext && canvas.getContext('2d'); | |
var DEFAULT_RGB = { r: 0, g: 0, b: 0 }; | |
function extractRGB(imageData) { | |
var len = imageData.data.length; | |
var rgb = { r: 0, g: 0, b: 0 }; | |
var blockSize = 5; // Check every 5 pixels | |
var i = -4; |