Skip to content

Instantly share code, notes, and snippets.

View jhsea3do's full-sized avatar
🤡
I may be slow to respond.

jhsea3do jhsea3do

🤡
I may be slow to respond.
View GitHub Profile
@jhsea3do
jhsea3do / guess.js
Last active February 18, 2019 10:00
guess number
const readline = require('readline');
const hint = (min, max) => (
'Please guess a number between %min and %max, hint(%h): '
.replace(/\%min/, min)
.replace(/\%max/, max)
.replace(/\%h/, Math.floor((min+max)/2))
);
const getnum = (msg, callback) => {
const rl = readline.createInterface({
input: process.stdin,
@jhsea3do
jhsea3do / grin-miner.sh
Created January 30, 2019 06:46
run grin-miner in background every 2 hours
#!/bin/sh
name=grin-miner
exec=/usr/bin/$name
screen -X -S $name quit
screen -dmS $name bash -c "cd $HOME/$name; $name"
cat > $HOME/bin/$name.crontab <<EOF
1 */2 * * * sh $HOME/bin/$name.sh >> /tmp/$name.log 2>&1
EOF
crontab -i $HOME/bin/$name.crontab
exit 0
@jhsea3do
jhsea3do / ocpasswd.sh
Last active October 18, 2018 11:45
create ocs (open connect server) password
#!/bin/sh
[ -z $1 ] && echo "!no user" && exit 1
[ -z $2 ] && echo "!no pass" && exit 1
cd $(realpath $(dirname $0))
rm -rf .tmp
mkdir -p .docker .tmp
[ ! -f .docker/Dockerfile ] && \
cat >.docker/Dockerfile<<EOF
FROM "wppurking/ocserv"
RUN apt-get update && \
@jhsea3do
jhsea3do / init_ssh_nopass.sh
Last active March 11, 2019 09:00
init ssh credentials without password
#!/bin/sh
# ------------------------------------------------------------------
# [Script] init_ssh_nopass.sh
# [Author] Hai Ji <jhsea3do@gmail.com>
# main script
# ------------------------------------------------------------------
# assumption: all nodes must have sshpass tool installed
# https://unix.stackexchange.com/questions/230084/send-the-password-through-stdin-in-ssh-copy-id
# [ ! -x "sshpass" ] && yum install -y sshpass;
@jhsea3do
jhsea3do / sed-replace-or-append-example
Created August 16, 2018 03:30
sed replace or append example
# https://superuser.com/questions/590630/sed-how-to-replace-line-if-found-or-append-to-end-of-file-if-not-found
sed '/^FOOBAR=/{h;s/=.*/=newvalue/};${x;/^$/{s//FOOBAR=newvalue/;H};x}' infile
# ssh -vvvv $host
# pledge: network
cat /etc/pam.d/postlogin
#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
session [success=1 default=ignore] pam_succeed_if.so service !~ gdm* service !~ su* quiet
session [default=1] pam_lastlog.so nowtmp showfailed
@jhsea3do
jhsea3do / (bin)init.sh
Created August 6, 2018 00:54
install tencent bkce cluster
#!/bin/sh
# ------------------------------------------------------------------
# [Script] bin/init.sh
# [Author] Hai Ji <shjihai@cn.ibm.com>
# main script
# ------------------------------------------------------------------
PRJ_NAME=bkce
PRJ_PATH=$(realpath "$(dirname $0)/..")
CWD=$(pwd)
@jhsea3do
jhsea3do / docker-helper-18.09.sh
Last active January 11, 2019 12:17
docker binary tar package setup script, support suse, centos
#!/bin/sh
FILE_DIR=${FILE_DIR:-"/tmp/docker"}
LOCL_DIR=${LOCL_DIR:-"/usr/local"}
INST_DIR=${INST_DIR:-"/home/docker"}
INST_GRP=${INST_GRP:-"docker"}
INST_GID=${INST_GID:-"2376"}
INST_VER=${INST_VER:-"18.09.1"}
INST_NET=${INST_NET:-"172.17.0.1/16"}
INST_SILENT=0
function load_cfg {
@jhsea3do
jhsea3do / pp
Created August 4, 2018 07:02 — forked from thiagophx/pp
JSON Pretty Print Stream
#!/usr/bin/python -u
import sys, json
from pygments import highlight
from pygments.lexers import JsonLexer
from pygments.formatters import Terminal256Formatter
while True:
line = sys.stdin.readline()
if line.strip():
/**
* docker pipeline sample
*/
node {
// create volume for root user
sh """
docker volume create ansible-root;
"""