Skip to content

Instantly share code, notes, and snippets.

View Avi-E-Koenig's full-sized avatar
🎯
Focusing

Avi E. Koenig Avi-E-Koenig

🎯
Focusing
View GitHub Profile
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);
@Avi-E-Koenig
Avi-E-Koenig / validateJsonSchema.js
Last active May 26, 2022 11:50
draft concept to validate json structure
const validateSchema = (json, schema) => {
try {
JSON.parse(json)
const parsed = JSON.parse(json)
for (const key in parsed) {
if (!schema.hasOwnProperty(key)) {
return false;
}
@Avi-E-Koenig
Avi-E-Koenig / recursiveBillPrint.js
Created May 26, 2022 12:17
Recursive Bill display
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);
@Avi-E-Koenig
Avi-E-Koenig / basicEmailTester.js
Created May 31, 2022 17:16
Simple Regex Email Tester
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
}
@Avi-E-Koenig
Avi-E-Koenig / AD.js
Created June 2, 2022 07:51
Active Directory Playground
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) {
@Avi-E-Koenig
Avi-E-Koenig / lsutils.js
Created June 12, 2022 15:16
basic ls stuff
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)
}
}
@Avi-E-Koenig
Avi-E-Koenig / snippets.js
Created June 16, 2022 07:29
my snippets vscode
/**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": [
@Avi-E-Koenig
Avi-E-Koenig / logger.php
Last active September 9, 2022 15:00
Basic output to console of object
<?php
function echoPrettyJson($variable,$key)
{
//pseudo
if($production) return;
try {
$key_name = $key ? $key : 'output';
$content = new stdClass();
@Avi-E-Koenig
Avi-E-Koenig / ballsort.js
Created December 15, 2022 13:46
Sort Balls by color and num
// 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
@Avi-E-Koenig
Avi-E-Koenig / t.js
Last active February 18, 2023 23:04
Triangle one loop
var triangleSize;
// Keep prompting for a valid positive number
while (
isNaN(triangleSize) ||
typeof triangleSize !== 'number' ||
triangleSize < 3 ||
triangleSize % 1 != 0
) {
triangleSize = parseInt(