Skip to content

Instantly share code, notes, and snippets.

Avatar
🖖
Live long and prosper

Jess Delgado Perez jesatrix

🖖
Live long and prosper
View GitHub Profile
View export-utils
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({
@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 / timestamp.sh
Last active August 5, 2021 14:27
Bash Utils
View timestamp.sh
get_duration () {
: ${1?"You must provide a number value"}
num=$1
min=0
hour=0
day=0
if((num>59));then
((sec=num%60))
((num=num/60))
if((num>59));then
@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
});