Skip to content

Instantly share code, notes, and snippets.

@fenying
fenying / auto-init-ssh-agent.sh
Last active April 23, 2024 08:13
Auto-start ssh-agent when BASH starts, and reuse for all bash instance.
# Add following code at the end of ~/.bashrc
# Check if ~/.pid_ssh_agent exists.
if [ -f ~/.pid_ssh_agent ]; then
source ~/.pid_ssh_agent
# Check process of ssh-agent still exists.
TEST=$(ssh-add -l)
@fenying
fenying / add-apache2-copyright.sh
Created November 3, 2023 10:53
Add Apache2 Copyright info to files
@fenying
fenying / docker-rabbitmq.sh
Last active October 23, 2023 02:20
Deploy RabbitMQ server with docker.
MQ_DOCKER_PORT=5672
MQ_DOCKER_ADMIN_USER="user"
MQ_DOCKER_ADMIN_PASS="password"
MQ_DOCKER_ADMINCP_PORT=15672
MQ_DOCKER_PATH=/var/lib/rabbitmq
MQ_DOCKER_NAME="RabbitMQ-Server"
MQ_DOCKER_MEMORY=256M
MQ_LOCAL_PATH=/docker/rabbitmq
MQ_LOCAL_HOST=0.0.0.0
@fenying
fenying / docker-compose.yml
Last active April 3, 2023 06:37
Run MySQL server by docker with configurations
version: "3"
services:
mysql.loc:
container_name: "mysql.loc"
image: "mysql:5.7"
deploy:
resources:
limits:
cpus: '0.50'
memory: 500M
@fenying
fenying / pbkdf2.js
Created March 5, 2023 10:33
PBKDF2 implementation in JS
// A JS implementation of PBKDF2.
// For study only, don't use this.
// Use NodeJS native implementation `crypto.pbkdf2` instead.
const Crypto = require('node:crypto');
function hmac(hmacAlgo, key, data) {
return Crypto.createHmac(hmacAlgo, key).update(data).digest();
}
const BUF_INT32_BE = Buffer.alloc(4);
@fenying
fenying / frps.sh
Last active August 2, 2022 03:46
The frp server service script /etc/init.d/frps
## File: /etc/init.d/frps
#!/bin/sh
#
# frps: FRP-Server Daemon
#
# description: FRP-Server Daemon
PID_FILE=/run/frps.pid
CONFIG_FILE=/etc/frps.ini
FRP_SERVER=/usr/local/frps/frps
start()
@fenying
fenying / clean-docker-logs.sh
Created May 8, 2021 02:47
Clean up all docker container logs
#!/bin/sh
## See https://stackoverflow.com/a/48029079/6559859
for k in $(docker ps --format='{{.ID}}')
do
echo "" > $(docker inspect --format='{{.LogPath}}' $k)
done
@fenying
fenying / request-wepay-sandbox-key.ts
Created May 26, 2021 11:31
Request wechat pay sandbox api sign key.
import * as $crypto from 'crypto';
const WEPAY_MCH_ID = 12345678;
const WEPAY_API_KEY = '';
const NONCE_STR = $crypto.randomBytes(16).toString('hex');
const REQ_SIGN = $crypto.createHash('md5')
.update(`mch_id=${WEPAY_MCH_ID}&nonce_str=${NONCE_STR}&sign_type=MD5&key=${WEPAY_API_KEY}`)
.digest('hex')
@fenying
fenying / docker-mongo.sh
Created January 20, 2020 10:32
Deploy MongoDB inside docker.
#!/bin/bash
MONGO_DOCKER_MAX_MEMORY=512M
MONGO_DOCKER_PORT=27017
MONGO_DOCKER_DATA_DIR=/data/db
MONGO_DOCKER_NAME=Mongo-Server
MONGO_LOCAL_PORT=27017
MONGO_LOCAL_DATA_DIR=/docker/mongo/db
@fenying
fenying / docker-redis.sh
Last active January 19, 2020 12:50
Run Redis server by docker with configurations
#!/bin/bash
# Redis configuration file is /docker/redis/redis_6379.conf:/data/redis_6379.conf
# Redis RDB file dir is /docker/redis/dump.rdb:/data/dump.rdb
REDIS_CONFIG_FILE=redis_6379.conf
DOCKER_REDIS_ROOT=/data
DOCKER_CONTAINER_NAME="Redis-Server"
DOCKER_MAX_MEMORY=256m
DOCKER_MAX_CPU=1