Skip to content

Instantly share code, notes, and snippets.

View rendfall's full-sized avatar
💭
Coffee is a drink, not a language! ☕️

rendfall rendfall

💭
Coffee is a drink, not a language! ☕️
View GitHub Profile
@rendfall
rendfall / get-only-modified-values.js
Created May 31, 2017 23:44
Get only modified values by comparing objects (naive version)
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];
@rendfall
rendfall / angular-tabs.component.ts
Created September 28, 2017 15:30
Angular 2+ tabsComponent
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>`,
@rendfall
rendfall / cached-service.ts
Created September 28, 2017 22:23
Angular 2+ cache observable http result data
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);
@rendfall
rendfall / i18n.service.js
Last active October 12, 2017 15:58
Angular 2+ - internationalization with Polyglot.js
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')
};
@rendfall
rendfall / random-with-weight.js
Created November 14, 2017 23:44
Generate a weighted random number
// 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);
@rendfall
rendfall / blob-to-json.js
Created March 18, 2018 22:10
BLOB saving as JSON
// https://jsfiddle.net/koldev/cW7W5/
var saveData = (function () {
var a = document.createElement("a");
document.body.appendChild(a);
a.style = "display: none";
return function (data, fileName) {
var json = JSON.stringify(data),
blob = new Blob([json], {type: "octet/stream"}),
url = window.URL.createObjectURL(blob);
a.href = url;
@rendfall
rendfall / random-word.sh
Created June 17, 2018 13:13
Random 4-letter word from the dictionary
# Random 4-letter word from the dictionary
$ shuf -n4 /usr/share/dict/words | tr -d '\n'
@rendfall
rendfall / addDelayedEventListener.js
Created September 7, 2018 17:15
Delayed event listener
function addDelayedEventListener($el, eventName, action) {
const listener = async function (event) {
$el.removeEventListener(eventName, listener);
$el.disabled = true;
await action.call(action, event);
$el.disabled = false;
addDelayedEventListener($el, eventName, action);
};
@rendfall
rendfall / multiple_ssh_setting.md
Created December 13, 2018 11:55
Multiple SSH keys for different github accounts

Multiple SSH Keys settings for different github account

create different public key

create different ssh key according the article Mac Set-Up Git

$ ssh-keygen -t rsa -C "your_email@youremail.com"
@rendfall
rendfall / animation-loop.js
Created January 23, 2019 22:10
Animation Loop
class AnimationLoop {
constructor(fps = 24) {
this.updateFn = null;
this.id = 0;
this.setFps(fps);
}
onUpdate(fn) {
this.updateFn = fn;
}