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
//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 |
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
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); |
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
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) => { |
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 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; |
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
#!/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: |
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
module.exports = { | |
trailingComma: 'es5', | |
tabWidth: 2, | |
semi: true, | |
singleQuote: true, | |
useTabs: true, | |
bracketSpacing: true, | |
jsxBracketSameLine: false, | |
arrowParens: 'always', | |
}; |
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 * 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); |