Skip to content

Instantly share code, notes, and snippets.

View fsjorgeluis's full-sized avatar
🏠
Working from home

Jorge Fernández fsjorgeluis

🏠
Working from home
View GitHub Profile
@fsjorgeluis
fsjorgeluis / reduceExamples.js
Created December 14, 2022 14:21 — forked from quangnd/reduceExamples.js
Some examples about reduce() in Javascript
//Example 1 - Calculate average value of an array (transform array into a single number)
var scores = [89, 76, 47, 95]
var initialValue = 0
var reducer = function (accumulator, item) {
return accumulator + item
}
var total = scores.reduce(reducer, initialValue)
var average = total / scores.length
/*Explain about function
@fsjorgeluis
fsjorgeluis / index.js
Last active June 20, 2022 21:14
aws cdk layer: s3-manager helper
module.exports.putObjectToS3 = async ({ S3 }, bucketName, key, data) => {
const s3 = new S3({ apiVersion: '2006-03-01' });
const params = {
Bucket: bucketName,
Key: key,
Body: JSON.stringify(data),
};
s3.putObject(params, function (err, data) {
if (err) {
console.log(err, err.stack);
@fsjorgeluis
fsjorgeluis / index.js
Created June 16, 2022 07:12
aws cdk layer: key-formatter helper
module.exports.keyFormatter = (key, value) => {
const formattedKey = `${key}#${value.replace(/\s/g, '').toUpperCase()}`;
return formattedKey.toUpperCase();
};
module.exports.wordNormalizer = (word) => {
return word.toLowerCase().replace(/\b\w/g, (firstChar) => firstChar.toUpperCase())
};
module.exports.capitalize = (phrase) => {
@fsjorgeluis
fsjorgeluis / renameObjectKey.helper.ts
Created December 16, 2021 18:25
Rename object key
export const renameKey = (object: any, key: string, newKey: string) => {
const clonedObj: Record<string, unknown> = clone(object);
const targetKey = clonedObj[key];
delete clonedObj[key];
clonedObj[newKey] = targetKey;
return clonedObj;
@fsjorgeluis
fsjorgeluis / ping_sweep.py
Created September 9, 2021 13:48
ping to array of ip, starting on 2 and finishing on 255, (customizable range)
#!/usr/bin/python3
import sys, subprocess
if len(sys.argv) != 2:
print ("ping_sweep.py 192.168.254.")
else :
cmdping = "ping -c 2 "+sys.argv[1]
for x in range(2,32): # 1, 255
p = subprocess.Popen(cmdping+str(x), shell = True, stderr = subprocess.PIPE)
while True:
@fsjorgeluis
fsjorgeluis / .prettierrc.js
Created August 25, 2021 16:02
Just a little prettier config I like
module.exports = {
trailingComma: 'es5',
tabWidth: 2,
semi: true,
singleQuote: true,
useTabs: true,
bracketSpacing: true,
jsxBracketSameLine: false,
arrowParens: 'always',
};
@fsjorgeluis
fsjorgeluis / hashAndCompare.ts
Last active January 25, 2025 09:46
Functions to hash and compare password using bcrypt library and typescript
import * as bcrypt from 'bcrypt';
/**
* Hash password using bcrypt library
* @param password String
* @returns string type
*/
export const HashPassword = async (password: string): Promise<string> => {
const salt = await bcrypt.genSalt();
const hash = await bcrypt.hash(password, salt);