This file contains 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
// 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; | |
} |
This file contains 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
const G = (1 + Math.sqrt(5)) / 2; // Golden Ratio | |
Math.round(G ** n / Math.sqrt(5)); |
This file contains 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
* `--trace_gc`: Logs garbage collection operations. | |
* `--inspect`: Runs node in debugging mode. open Chrome with `chrome://inspect` to see the debug session. |
This file contains 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 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; | |
} |
This file contains 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
/* 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 } | |
* } | |
* } |
This file contains 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 React, { Component } from 'react' | |
export default class ComponentName extends Component { | |
constructor(props) { | |
console.log ("constructor"); | |
super(props); | |
this.state = { | |
}; | |
} |
This file contains 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 quick Javascript class for creating a countdown timer | |
// leadingZero is a boolean, onTimeCallback will be called on each second update with the timer string | |
function Countdown(hours,minutes,seconds, leadingZero, onTimeCallback) { | |
this.hours = hours; | |
this.minutes = minutes; | |
this.seconds = seconds; | |
this.countdownStr = hours+":"+minutes+":"+seconds; | |
this.onTime = onTimeCallback; | |
this.leadingZero = leadingZero; |
This file contains 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
var url = '/.../'; | |
var req = new XMLHttpRequest(); | |
req.open('GET', url, true); | |
req.onreadystatechange = function () { | |
if (req.readyState == 4 && req.status == 200) | |
console.log(req.responseText); | |
else | |
console.log("Error loading page"); | |
}; | |
req.send(); |
This file contains 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
// put 'req' on the elements of any required input fields. Don't use the 'required' attribute, otherwise the default action | |
// will trigger. | |
function onFormSubmit(form) { | |
var isValid = true; | |
Array.prototype.forEach.call(form.elements, function (e) { | |
if ((e.value.length == 0 || ! /\S/g.test(e.value)) && e.getAttribute('req') !== null && e.getAttribute('req') !== undefined) { | |
isValid = false; | |
e.value = ""; | |
if (e.getAttribute('req') == "") { |
This file contains 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
-webkit-transition: prop 0.2s ease; | |
-moz-transition: prop 0.2s ease; | |
-o-transition: prop 0.2s ease; | |
transition: prop 0.2s ease; |
NewerOlder