Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Paul Knulst paulknulst

🎯
Focusing
View GitHub Profile
@paulknulst
paulknulst / 12-important-js-functions-to-improve-code-as-a-web-developer.js
Created January 10, 2023 12:16
12 Important JavaScript Functions To Improve Code as a Web Developer on Medium: https://medium.com/@paulknulst
View 12-important-js-functions-to-improve-code-as-a-web-developer.js
// 1. Valid Json
const isValidJSON = (str) => {
try {
JSON.parse(str);
return true;
} catch (e) {
return false;
}
};
View 14-important-js-functions-every-web-developer-should-know.js
// 1. Max Number
const maxN = (arr, n = 1) => [...arr].sort((a, b) => b - a).slice(0, n);
maxN([1, 2, 3, 4]); // [4]
maxN([2, 4, 6, 4, 3], 2); // [6, 4]
// 2. Ternary Operator
function temparature(temp) {
return temp > 39 || temp < 35.5
@paulknulst
paulknulst / 12-useful-js-code-snippets.js
Created December 24, 2021 00:18
12 useful JavaScript snippets to solve everyday problems, save time and optimize code as a web developer.
View 12-useful-js-code-snippets.js
// 1. Destructive Assignment
const data = ["Paul", "too old", "Software Engineer"]
const [name, age, job_title] = data
console.log(name, age, job_title) // Paul too old Software Engineer
// 2. Find an object in Array
const employess = [
{name: "Paul", job_title: "Software Engineer"},
View useful-tips.js
// 1. Shorten the console log
const log = console.log.bind(document)
log("does it work?")
log("yes")
log(5)
// 2. Merge two arrays into one
const array1 = ["One", "Two", "Three"]
const array2 = ["Four", "Five", "Six"]
@paulknulst
paulknulst / full-db-zipping-and-uploading-to-gcp.sh
Created November 3, 2021 09:33
zip/encrypt (with pass from env) db backups within folder and upload resulting file to gcp using stored credentials on system
View full-db-zipping-and-uploading-to-gcp.sh
#!/bin/bash
TIME=$(date +%Y-%m-%d)
HOST=$(hostname)
BACKUPSAVEPATH=/root/backups_encrypted/
BACKEDUPFILE=$BACKUPSAVEPATH/db-backups-$HOST-$TIME.enc
TARGET=gs://f1nalboss-db-backups/
cd /root/backups/db || exit 1
if [ -z "$(ls -A .)" ]; then
exit 1
@paulknulst
paulknulst / update.sh
Last active October 27, 2021 05:46
this update script is used to deploy several docker files.
View update.sh
#!/bin/bash
filepath=`pwd`
if [[ $filepath == *"test-suite/live-deploy" ]]; then
read -p "choose environment 'prod' or 'demo': " updateEnv
else
echo "it seems that you are in the wrong folder, pls got to test-suite/live-deploy"
exit 1
fi
@paulknulst
paulknulst / full-db-backup.sh
Last active November 3, 2021 09:29
this simple script searches all docker container and do a full db backup of all databases
View full-db-backup.sh
#!/bin/bash
mysqlContainer=$(docker ps | grep 'mysql\|maria' | awk {'print $NF'}) #gets every container with a name containing mysql/mariadb
postgreContainer=$(docker ps | grep -Ei 'postgre'| grep -Eiv 'gitlab' | awk {'print $NF'}) #gets every container with a name containing postgre
gitlabPotsgreContainer=$(docker ps | grep -Ei 'postgre'| grep -Ei 'gitlab' | awk {'print $NF'}) #special gitlab because it use other env variables
timestamp=$(date +%Y-%m-%d_%H-%M-%S)
for container in $mysqlContainer; do
containerStringParts=$(echo $container | tr "." "\n")
for single in $containerStringParts; do
simpleName=$single