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
@Avi-E-Koenig
Avi-E-Koenig / CloudinaryCrud.ts
Created March 14, 2023 14:00
basic cloudinary crud
import cloudinary from 'cloudinary';
import fs from 'fs';
import { CLOUDINARY_API_KEY, CLOUDINARY_API_SECRET, CLOUDINARY_CLOUD_NAME } from '@/config';
cloudinary.v2.config({
cloud_name: CLOUDINARY_CLOUD_NAME,
api_key: CLOUDINARY_API_KEY,
api_secret: CLOUDINARY_API_SECRET,
});
@Avi-E-Koenig
Avi-E-Koenig / image.api.js
Last active March 7, 2023 19:06
Next.js Image Handler
import {COLLECTIONS} from '@/const'
import {NextApiRequest, NextApiResponse} from 'next'
import fs from 'fs/promises'
import formidable, {Fields, File, Files} from 'formidable'
import path from 'path'
import checkAuthMiddleware from '../../../backend/middleware/checkIsAdmin'
import {v4 as uuid} from 'uuid'
const IMAGE_DIRECTORY = './public/assets/images/'
const ACCEPTED_FILE_TYPES = ['jpg', 'png']
@Avi-E-Koenig
Avi-E-Koenig / auth-is-admin.middleware.js
Created March 7, 2023 19:00
Next js generic authMiddleware
import {NextApiRequest, NextApiResponse} from 'next'
import jwt from 'jsonwebtoken'
type Handler = (req: NextApiRequest, res: NextApiResponse) => Promise<any>
const checkAuthMiddleware = (handler: Handler) =>
async function (req: NextApiRequest, res: NextApiResponse): Promise<any> {
try {
// Check if the Authorization header exists and extract the token value
const authHeader = req.headers['authorization']
@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(
@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 / 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 / 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 / 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 / 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 / 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
}