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
const db = require('../models');
const Logger = require('../helpers/logger.helper');
const callLifeCycle = db.call_life_cycle;
const newcall_handler = async (dataObj, insert_params, where_params) => {
const t1 = await sequelize.transaction();
try {
let query_newcall_result = await callLifeCycle.findOne({
where: where_params,
transaction: t1,
const fetchAllKeys = async (fields) => {
try {
let promiseArray = await Promise.all(
Object.keys(fields).map(async (entry) => {
const uri = `${baseUrl}${entry}Fields?${params}&${api_token}`;
const person_result = await axios.get(uri);
let data = await person_result.data.data.map((field) => {
const { id, key, name } = field;
return { id, key, name };
});
@Avi-E-Koenig
Avi-E-Koenig / DateArrMaker.js
Created June 18, 2020 10:04
get arr of dates in isoString for the period between months in a year.
class DateArrMaker {
constructor(minMonth, maxMonth, year) {
if (isNaN(minMonth) || isNaN(maxMonth) || isNaN(year)) {
throw new Error(`all values must be numeric`);
}
// if (maxMonth < minMonth) {
// let temp = maxMonth;
// minMonth = maxMonth;
// maxMonth = temp;
// }
// see: https://davidwalsh.name/javascript-proxy-with-storage
function getStorage() {
return new Proxy(window.localStorage, {
// just a helper to see if value is valid json ie stringified obj or array
set: (obj, prop, value) => {
value !== null && typeof value === 'object'
? obj.setItem(prop, JSON.stringify(value))
: obj.setItem(prop, value);
console.log(`${prop} added to localstorage!😀`);
},
//// -- https://dbdiagram.io/d/5e8f12c739d18f5553fd5b60
//// -- LEVEL 1
//// -- Tables and References
// Creating tables
Table users as U {
id int [pk, increment] // auto-increment
fName varchar
lName varchar
const Logger = require('./logger.service');
const { parse } = require('json2csv');
// opt contain fieldsc
const jsonTocsv = (data, opt) => {
console.log('jsonTocsv -> opt', opt);
console.log('jsonTocsv -> data', data[0]);
try {
if (!data || !data.length) return null;
const csv = parse(data, opt);
@Avi-E-Koenig
Avi-E-Koenig / Crypto_module.js
Last active January 27, 2021 08:31
Encrypt/decrypt with aes
const CryptoJS = require('crypto-js');
const SECRET_KEYB = process.env.SECRET_KEYB;
class CryptoHandler {
constructor() {
if (!SECRET_KEYB || !SECRET_KEYB.length) {
throw new ErrorHandler(500, 'please see env');
}
}
export default {
name: 'color-picker',
template: /*html*/ `
<div class="row" style="margin-bottom:0;">
<div
class="input-field col s12"
@click="openColorPicker">
<i class="material-icons prefix">color</i>
<input
@Avi-E-Koenig
Avi-E-Koenig / dcConn.js
Last active May 17, 2021 22:20
async await Sqlite connection with db file write (if not exists)
const sqlite3 = require('sqlite3').verbose();
const { open } = require('sqlite');
const path = require('path');
const fs = require('fs').promises;
async function checkFileExists(file) {
try {
return await fs.stat(file);
} catch (error) {
@Avi-E-Koenig
Avi-E-Koenig / printPHPObject.php
Created September 27, 2021 11:35
print an object in php to screen
function printAll($spaces = 0, $payload)
{
$currentIndentation = str_repeat("&nbsp;", $spaces);
if (is_string($payload)) {
echo "&nbsp;$payload<br/>";
}
if (is_array($payload)) {
foreach ($payload as $key => $value) {
echo "<br/> $currentIndentation $key: ";