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 initTimer() { | |
let timer = 0; | |
let interval = setInterval(() => { | |
timer++; | |
console.log("🚀 ~ file: main.js ~ line 5 ~ interval ~ timer", timer) | |
if (timer === 10) { | |
clearInterval(interval); | |
console.log('Time is up!'); | |
} | |
}, 1000); |
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
const validateSchema = (json, schema) => { | |
try { | |
JSON.parse(json) | |
const parsed = JSON.parse(json) | |
for (const key in parsed) { | |
if (!schema.hasOwnProperty(key)) { | |
return false; | |
} |
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
const itemFactory = () => { | |
return { | |
name: makeid(), | |
price: getRandomInt(1, 100), | |
items: Math.random() < 0.5 ? Array.from({ length: getRandomInt(1, 4) }, itemFactory) : [], | |
} | |
} | |
function getRandomInt(min, max) { | |
min = Math.ceil(min); |
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
export const isValidEmail = (emailStr) => { | |
const regex = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/ | |
const res = regex.test(emailStr.toLowerCase()); | |
console.log("🚀 ~ file: validateEmail.js ~ line 5 ~ isValidEmail ~ res", res) | |
return res | |
} |
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
var ActiveDirectory = require('activedirectory'); | |
var config = { | |
url: process.env.AD_URL, | |
baseDN: process.env.AD_BASE_DN, | |
username: process.env.AD_USERNAME, | |
password: process.env.AD_PASSWORD | |
} | |
var ad = new ActiveDirectory(config); | |
ad.authenticate(user.name, user.password, function (err, auth) { |
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
const ls = window?.localStorage; | |
export const save = (key, value) => { | |
try { | |
const payload = JSON.stringify({ [key]: value }) | |
ls.setItem(key, payload); | |
} catch (error) { | |
console.log("🚀 ~ file: localstorage.js ~ line 5 ~ store ~ error", error) | |
} | |
} |
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
/**react js storybook snippet*/ | |
{ | |
// Place your snippets for javascriptreact here. Each snippet is defined under a snippet name and has a prefix, body and | |
// description. The prefix is what is used to trigger the snippet and the body will be expanded and inserted. Possible variables are: | |
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders. Placeholders with the | |
// same ids are connected. | |
// Example: | |
// "Print to console": { | |
// "prefix": "log", | |
// "body": [ |
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
<?php | |
function echoPrettyJson($variable,$key) | |
{ | |
//pseudo | |
if($production) return; | |
try { | |
$key_name = $key ? $key : 'output'; | |
$content = new stdClass(); |
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
// take bag of balls in colors red,yellow,blue green with digit 1-9 | |
// args array of balls | |
const ball = { color: 'red', num: 1 }; | |
/** | |
* | |
* @param {number} min | |
* @param {number} max |
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
var triangleSize; | |
// Keep prompting for a valid positive number | |
while ( | |
isNaN(triangleSize) || | |
typeof triangleSize !== 'number' || | |
triangleSize < 3 || | |
triangleSize % 1 != 0 | |
) { | |
triangleSize = parseInt( |