Skip to content

Instantly share code, notes, and snippets.

@k8scat
k8scat / format-time.js
Created April 29, 2021 04:31
Format time from timestamp
export const formatTime = (timestamp) => {
const date = new Date(timestamp);
const YY = date.getFullYear();
const MM = date.getMonth() + 1 < 10 ? `0${date.getMonth() + 1}` : date.getMonth() + 1;
const DD = date.getDate() < 10 ? `0${date.getDate()}` : date.getDate();
const hh = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours();
const mm = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes();
const ss = date.getSeconds() < 10 ? `0${date.getSeconds()}` : date.getSeconds();
return `${YY}-${MM}-${DD} ${hh}:${mm}:${ss}`;
};
@k8scat
k8scat / watch.sh
Last active May 4, 2021 19:11
Play `watch` in a shell script
#!/bin/sh
# while :; do clear; your_command; sleep 2; done
# usage: watch.sh "<your_command>" "<sleep_duration>"
d=${2:-2}
while :; do
clear
date
$1
sleep ${d}
@k8scat
k8scat / logfilter.go
Last active May 6, 2021 10:44
Filter content by date range or read only last N lines of a file.
package main
import (
"bufio"
"bytes"
"flag"
"fmt"
"io"
"os"
"regexp"
@k8scat
k8scat / install_python.sh
Last active May 7, 2021 04:00
Install python3 from source code on CentOS 7.
#!/bin/bash
#
# Install python3 from source code on CentOS 7
# Maintainer: K8sCat <k8scat@gmail.com>
set -e
if [[ $(id -u) -ne 0 ]]; then
echo "require root"
exit 1
fi
@k8scat
k8scat / backup_volume.sh
Last active May 8, 2021 02:36
Backup data from a volume.
#!/bin/sh
#
# Backup data from a volume.
# Maintainer: k8scat@gmail.com
data_volume=$1
data_dir=$2
if [[ "${data_volume}" = "" || "${data_dir}" = "" ]]; then
echo "usage: $0 <data_volume> <data_dir>"
exit 1
@k8scat
k8scat / delete_git_submodule.md
Created May 11, 2021 03:45 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
@k8scat
k8scat / postman_pre_request.js
Created May 12, 2021 10:52
Pre-request Script in Postman help me get and refresh the access_token.
// https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/#sending-requests-from-scripts
const url = pm.environment.replaceIn("{{base_url}}/some/api")
const req = {
url: url,
method: 'POST',
header: {
'Content-Type': 'application/json',
'X-Foo': 'bar'
},
body: {
@k8scat
k8scat / rm_mysql.md
Created May 17, 2021 14:31 — forked from vitorbritto/rm_mysql.md
Remove MySQL completely from Mac OSX

Remove MySQL completely

  1. Open the Terminal

  2. Use mysqldump to backup your databases

  3. Check for MySQL processes with: ps -ax | grep mysql

  4. Stop and kill any MySQL processes

  5. Analyze MySQL on HomeBrew:

    brew remove mysql
    
@k8scat
k8scat / ssl_smtp_example.go
Created May 19, 2021 07:54 — forked from chrisgillis/ssl_smtp_example.go
Golang SSL SMTP Example
package main
import (
"fmt"
"log"
"net"
"net/mail"
"net/smtp"
"crypto/tls"
)
#!/bin/bash
# bash generate random alphanumeric string
#
# bash generate random 32 character alphanumeric string (upper and lowercase) and
NEW_UUID=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1)
# bash generate random 32 character alphanumeric string (lowercase only)
cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1