This file contains 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
Date.prototype.addHours = function(h) { | |
this.setTime(this.getTime() + (h*60*60*1000)); | |
return this; | |
} | |
const singapore_time = new Date().addHours(8); // GMT +8 | |
const date_time = singapore_time.getTime(); | |
const current_timestamp = singapore_time.getTime().toString(); | |
const date_to_utc = ( new Date(date_time)).toUTCString(); | |
const utc_to_epoch = Date.parse(date_to_utc); |
This file contains 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
//When stackoverflow can't help you... | |
const AWS = require('aws-sdk'); | |
var AmazonCognitoIdentity = require('amazon-cognito-identity-js'); | |
var CognitoUserPool = AmazonCognitoIdentity.CognitoUserPool; | |
var AuthenticationDetails = AmazonCognitoIdentity.AuthenticationDetails; | |
var CognitoUser = AmazonCognitoIdentity.CognitoUser; | |
exports.handler = (event, context, callback) => { |
This file contains 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
<?php | |
error_log(E_ALL); | |
require_once "sodium/autoload.php"; | |
$password = "abc"; | |
$message = 'this is danger'; | |
$salt = random_bytes(SODIUM_CRYPTO_PWHASH_SALTBYTES); | |
$secret_key = sodium_crypto_pwhash(SODIUM_CRYPTO_SECRETSTREAM_XCHACHA20POLY1305_KEYBYTES, |
This file contains 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
#!/bin/bash | |
# This is my production backup script. | |
# https://sqlgossip.com | |
# taken from https://thedataguy.in/automation-script-for-percona-xtrabackup-full-incremental/ | |
# modified by erickvasilev | |
SHELL=/bin/bash | |
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin | |
set -e |
This file contains 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
#!/bin/bash | |
USER="root" | |
PASSWORD="eTsAWGkH" | |
#OUTPUT="/Users/rabino/DBs" | |
#rm "$OUTPUTDIR/*gz" > /dev/null 2>&1 | |
databases=`mysql -u $USER -p$PASSWORD -e "SHOW DATABASES;" | tr -d "| " | grep -v Database` |
This file contains 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
#!/bin/bash | |
trigger=2.30 | |
load=`cat /proc/loadavg | awk '{print $1}'` | |
response=`echo | awk -v T=$trigger -v L=$load 'BEGIN{if ( L > T){ print "greater"}}'` | |
if [[ $response = "greater" ]] | |
then | |
reboot | |
else | |
echo $load | |
fi |
This file contains 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
#!/bin/bash | |
pm2 show myapp | grep "stopped" | |
if [ $? -eq 0 ]; then | |
printf 'NodeJS App is not running....' | |
#i use PM2 to manage app | |
pm2 start myapp | |
else |
This file contains 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
#!/bin/bash | |
/usr/sbin/service mysql status | grep "stopped\|dead" | |
if [ $? -eq 0 ]; then | |
printf 'mysql is not running....' | |
sudo service mysql start | |
else |
This file contains 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
#!/bin/bash | |
# scanning website and save to status.txt | |
wget -q -O /var/www/test/status.txt bahrulilmi.com --timeout 10 -t 1 | |
cd /var/www/test/ | |
File=status.txt | |
# check if there is <title> metadata , if site is not accessible / timeout, file will be empty |