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 / check_ssl.py
Created April 30, 2021 03:30
Check ssl expire time
# Maintainer: k8scat@gmail.com
import sys
import time
from datetime import datetime
import ssl
import socket
def get_ssl_info(domain, port=443):
@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 / install_git.sh
Last active June 13, 2021 17:35
Install git from source code on CentOS 7.
#!/bin/bash
#
# Install git from source code on CentOS 7, refer to https://github.com/git/git/blob/master/INSTALL
set -e
# Get version from https://github.com/git/git/releases, for example: 2.29.2
version=$1
if [[ -z "${version}" ]]; then
echo "usage: $0 <version, 2.29.2> [profile]"
exit 1
@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 / 📊 Weekly development breakdown
Last active July 16, 2021 00:48
📊 Weekly development breakdown
Other 67 hrs 4 mins █████████████████▍░░░ 83.2%
Go 6 hrs 4 mins █▌░░░░░░░░░░░░░░░░░░░ 7.5%
Markdown 2 hrs 14 mins ▌░░░░░░░░░░░░░░░░░░░░ 2.8%
sh 1 hr 37 mins ▍░░░░░░░░░░░░░░░░░░░░ 2.0%
JavaScript 43 mins ▏░░░░░░░░░░░░░░░░░░░░ 0.9%