Skip to content

Instantly share code, notes, and snippets.

View zorgick's full-sized avatar
🐬
Plop!

zorgick

🐬
Plop!
  • Mundus
View GitHub Profile
/**
*
* @param {Object} obj source object to be traversed
* @param {RegExp} fieldName regular expression that represents a required property
*/
export const getFieldValues = (obj, fieldName) => {
if (Object.keys(obj).length === 0) {
return
}
/**
* MyNewType definition
* @typedef {MyNewType} MyNewType
* @param {number} first
* @param {number} second
* @property {function} logFirst
* @property {function} logSecond
* @returns MyNewType
*/
detectBrowserlanguage(defaultLang) {
const navLang = navigator.language || navigator.userLanguage || defaultLang;
return navLang.substring(0, 2);
}
componentDidMount() {
const defaultLang = this.detectBrowserlanguage("en");
const lang = localStorage.getItem("user-lang");
const usedLang = lang ? lang : defaultLang;
/**
* This function accepts array of strings or strings or both
* all empty or falsy values are omitted
* returns a string of classes
*@example
// 1) simple use case: single argument - array of strings
stringifyClasses([
styles.day,
isPassive && styles.dayPassive,
disabled && styles.dayDisabled,
@zorgick
zorgick / tikz-uml.md
Created July 14, 2020 15:42
How to install tikz-uml package on different platforms

How to install tikz-uml package on Mac

#!/bin/sh

mkdir -p ~/Library/texmf/tex/latex/tikz-uml/ # It doesn't really matter where to save this file 

cp ~/Downloads/tikzuml-v1.0b/tikz-uml.sty ~/Library/texmf/tex/latex/tikz-uml/
% Preamble
\usepackage{tikz-uml}
\usetikzlibrary{positioning}
% Preamble end
...
\begin{tikzpicture}[shorten >=1pt,node distance=3cm,auto]%,on grid
\tikzstyle{state}=[shape=circle,thick,draw,minimum size=1.5cm]
\node[state] (A1) {$A_1$};
\node[state,above of=A1] (B1) {$B_1$};
@zorgick
zorgick / dom_performance_reflow_repaint.md
Created May 13, 2021 14:42 — forked from faressoft/dom_performance_reflow_repaint.md
DOM Performance (Reflow & Repaint) (Summary)

DOM Performance

Rendering

  • How the browser renders the document
    • Receives the data (bytes) from the server.
    • Parses and converts into tokens (<, TagName, Attribute, AttributeValue, >).
    • Turns tokens into nodes.
    • Turns nodes into the DOM tree.
  • Builds CSSOM tree from the css rules.
@zorgick
zorgick / deepClone.js
Created January 3, 2022 20:34 — forked from wjx0820/deepClone.js
深拷贝 deepClone
// 通过 typeof 来查看每种数据类型的描述
// [undefined, null, true, '', 0, Symbol(), {}].map(it => typeof it)
// ["undefined", "object", "boolean", "string", "number", "symbol", "object"]
function clone(obj) {
// 添加一个 WeakMap 来记录已经拷贝过的对象,如果当前对象已经被拷贝过,那么直接从 WeakMap 中取出,否则重新创建一个对象并加入 WeakMap 中
// ES6 推出的 WeakMap 对象,该对象是一组键/值对的集合,其中的键是弱引用的。其键必须是对象,而值可以是任意的
let map = new WeakMap();
function deep(data) {
@zorgick
zorgick / draw-diagrams.es6
Created January 3, 2022 20:37 — forked from raganwald/draw-diagrams.es6
State Machines
// A state machine that works from a description including explicit transitions,
// and can generate a transition map and a digraph
const STATES = Symbol("states");
const STARTING_STATE = Symbol("starting-state");
const TRANSITIONS = Symbol("transitions");
const RESERVED = [STARTING_STATE, TRANSITIONS];
const MACHINES_TO_CURRENT_STATE_NAMES = new WeakMap();
const MACHINES_TO_STARTING_STATES = new WeakMap();
@zorgick
zorgick / ultimateDeepClone.js
Created January 3, 2022 20:41 — forked from ositowang/ultimateDeepClone.js
Ultimate version solving circular dependency with weakMap
/**
* Ultimate version solving circular dependency with weakMap
* Problems:
* 1. Symbols not covered
*
* @param {Object} sourceObj
* @param {WeakMap} [hash=new WeakMap()]
* @returns
*/
var deepCloneUltimate = (sourceObj, hash = new WeakMap()) => {