Skip to content

Instantly share code, notes, and snippets.

View erickvasilev's full-sized avatar

Erick Vasilev erickvasilev

View GitHub Profile
@erickvasilev
erickvasilev / time.js
Last active December 22, 2020 12:52
Date & Time Converter Native - Erick Vasilev
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);
@erickvasilev
erickvasilev / gist:e2c026f6c317ca115f3796d175f38eac
Created December 4, 2020 02:09
Cognito Login Authentication via Lambda
//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) => {
<?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,
@erickvasilev
erickvasilev / xtrabackup-s3.sh
Last active January 19, 2020 20:24
Percona Xtrabckup to S3 using S3cmd and AWS CLI version 2
#!/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
@erickvasilev
erickvasilev / backup.sh
Created January 8, 2018 01:03
Dump all MYSQL database
#!/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`
@erickvasilev
erickvasilev / restart_if_highload.sh
Last active March 13, 2018 10:55
Check if high load
#!/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
@erickvasilev
erickvasilev / restart_nodeJS_app.sh
Created May 4, 2017 03:16
Restart NodeJS App If Down/Crash
#!/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
@erickvasilev
erickvasilev / restart_mariadb.sh
Created May 4, 2017 03:14
Bash Script - Restart MariaDB if Down
#!/bin/bash
/usr/sbin/service mysql status | grep "stopped\|dead"
if [ $? -eq 0 ]; then
printf 'mysql is not running....'
sudo service mysql start
else
@erickvasilev
erickvasilev / restart_server.sh
Last active May 17, 2017 09:50
Bash Script - Check If Server is Down/Up
#!/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