Skip to content

Instantly share code, notes, and snippets.

@yuval-a
yuval-a / gist:01dfc6b38c39a80ef66cbbc613e041bc
Last active March 15, 2021 08:49
useEvents High Order Hook/Function for separation of template and logic in React
/* events should be an object containing DOM event names as keys (click, keyup, hover...), with the values as objects having
* element "names" as keys, and event handler functions as values. E.g.:
* {
* click: {
* button1() { // handle button1 click },
* button2() { // handle button2 click },
* keyup {
* input1() { // handle input1 keyup }
* }
* }
@yuval-a
yuval-a / gist:ad8dd131506c56da2a634693db72e2c9
Last active April 19, 2021 08:15
str_length that ignores Hebrew "nikud" characters
function str_length(str) {
let length = 0, nikud_chars = /[ְֱֲֳִֵֶַָֹֻּׁׂ]/;
for (let i=0,len=str.length;i<len;i++)
length += nikud_chars.test(str[i]) ? 0 : 1;
return length;
}
@yuval-a
yuval-a / gist:73fe8ac54a313bacea5c3d8a41c5ca72
Last active October 18, 2021 12:46
Usefull Node command line options
* `--trace_gc`: Logs garbage collection operations.
* `--inspect`: Runs node in debugging mode. open Chrome with `chrome://inspect` to see the debug session.
@yuval-a
yuval-a / gist:43bac660b3b46063ff58263d7ee2cb24
Created October 9, 2022 12:06
Fibonacci positive Nth item formula
const G = (1 + Math.sqrt(5)) / 2; // Golden Ratio
Math.round(G ** n / Math.sqrt(5));
@yuval-a
yuval-a / areObjectsEqual
Last active February 13, 2023 16:56
Simple objects equality checker function
// Check if objects are equal (have the same keys with the same values), all values must be primitives (no functions, objects or arrays)
function areObjectsEqual(obj1, obj2) {
let obj1KeysCount = 0;
for (const key in obj1) {
if (obj1[key] !== obj2[key]) return false;
obj1KeysCount++;
}
return Object.keys(obj2).length === obj1KeysCount;
}