Skip to content

Instantly share code, notes, and snippets.

View jesatrix's full-sized avatar
🖖
Live long and prosper

Jess Delgado Perez jesatrix

🖖
Live long and prosper
View GitHub Profile
@jesatrix
jesatrix / array.util.ts
Last active September 21, 2023 20:52
Misc Utils
View array.util.ts
/* eslint-disable security/detect-object-injection */
import { flattenDeep, uniq } from 'lodash';
import { BooleanDictionary } from '../definitions';
/**
* Takes in a string and converts it to an array of strings
* @param values String with comma separated values
* @param removeSpaces Whether to remove spaces from the values
* @param toLower Whether to convert the values to lowercase
* @param separator The separator to use for splitting the string
View export-utils.ts
function exportToJson(data: unknown, fileName: string, directory: string) {
this.logger.debug({ msg: 'file name', fileName });
const jsonData = JSON.stringify(data);
const filePath = join(directory, `${new Date().toISOString()}_${fileName}.json`);
writeFile(filePath, jsonData, (err) => {
if (err) {
this.logger.error({
msg: `An error occurred while writing JSON to File.`,
filePath,
err,
@jesatrix
jesatrix / array.util.ts
Last active February 8, 2023 22:35
Array utilities
View array.util.ts
/**
* Takes in a string and converts it to an array of strings
* @param values String with comma separated values
* @returns array of strings or undefined
*/
export function splitStringAndCleanArray(values?: string, removeSpaces = false): string[] | undefined {
const cleaned =
values?.split(',')?.map((v) => {
const mod = v?.trim();
return removeSpaces ? mod.replace(' ', '') : mod;
@jesatrix
jesatrix / test.sh
Last active June 30, 2023 22:56
Bash Utils
View test.sh
#!/bin/bash
filePath=$1
testGroup=$2
clearCache=$3
if [[ $clearCache == true ]]; then
echo "Clearing cache"
node "/<path>/node_modules/jest/bin/jest.js" --clearCache --verbose
fi
@jesatrix
jesatrix / streams.get.ts
Last active August 3, 2021 19:44
Streams Sample
View streams.get.ts
import { pipeline, Transform, TransformCallback } from 'stream';
import { promisify } from 'util';
import { env } from 'process';
import axios, {
AxiosInstance,
AxiosRequestConfig,
AxiosResponse,
ResponseType,
} from 'axios';
import * as JSONStream from 'jsonstream-next';
@jesatrix
jesatrix / array.util.ts
Last active February 8, 2023 22:34
Random Utilities
View array.util.ts
/**
* Merge two distinct arrays into a single, unique record
* @param originalArray Starting version of the array
* @param newArray New values to append to the array
* @returns A unique array of values
*/
export function mergeArrays<T>(originalArray?: T[], newArray?: T[]) {
return (
(Array.isArray(originalArray)
? [...new Set([...originalArray, ...(newArray ?? [])])]?.filter((v) => typeof v !== 'undefined')
@jesatrix
jesatrix / console_angular_var_update.js
Created January 27, 2017 16:13
Access a variable within the console
View console_angular_var_update.js
var $scope = angular.element($0).scope();
$scope.$apply(function () {
// SET VARIABLE HERE
});