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
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, | |
}); |
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
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'] |
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
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'] |
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( |
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
<?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
/**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
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
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
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 | |
} |