Skip to content

Instantly share code, notes, and snippets.

@fenying
fenying / docker-mongo.sh
Created Jan 20, 2020
Deploy MongoDB inside docker.
View docker-mongo.sh
#!/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 / calcWeaponScroll.ts
Created Nov 24, 2019
[MapleStory] Calculate the average ATTACK added in a weapon by scrolls
View calcWeaponScroll.ts
/**
* Calcuate the used scrolls of a weapon.
*
* @param baseAttack The base attack
* @param totalAttack The total attack
* @param sparkAttack The ATTACK added by spark
* @param appliedScrolls The quantity of scrolls applied.
* @param appliedStars The quantity of stars applied.
*/
@fenying
fenying / docker-rabbitmq.sh
Last active Nov 12, 2019
Deploy RabbitMQ server with docker.
View docker-rabbitmq.sh
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-php-fpm.sh
Created Sep 24, 2019
Install PHP-FPM by docker with extensions for MySQL and Redis
View docker-php-fpm.sh
FROM php:fpm
RUN pecl install -o -f redis \
&& rm -rf /tmp/pear \
&& docker-php-ext-enable redis \
&& docker-php-ext-install mysqli pdo pdo_mysql
CMD ["php-fpm"]
@fenying
fenying / calcIgnoreMobDefnese.js
Last active Aug 12, 2019
[MapleStory] Calculate ignore ratio of monster defense.
View calcIgnoreMobDefnese.js
/**
* Calculate the ignore ratio of monster defense.
*
* @param base The base ignore ratio, (Value: 0 ~ 1)
* @param ignoreItems The items of ignore addition to be added, (Value: 0 ~ 1)
*/
function calcIgnoreMobDefnese(base, ignoreItems) {
return Math.floor(ignoreItems.reduce((p, v) => p + (1 - p) * v, base) * 100) / 100;
}
@fenying
fenying / git-switch-remote-repo.sh
Last active Apr 24, 2019
A tool for switching git remote repository URL.
View git-switch-remote-repo.sh
#!/bin/bash
# Usage
#
# We assume the link of remote repository is of SSH style like:
#
# <git-user>@<domain>:<scope>/<project-name>.git
#
# git-switch-remote-repo <remote-name> full <full-repo-link>
# git-switch-remote-repo <remote-name> domain <new-domain>
@fenying
fenying / auto-init-ssh-agent.sh
Last active Nov 12, 2019
Auto-start ssh-agent when BASH starts, and reuse for all bash instance.
View auto-init-ssh-agent.sh
# 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 / docker-mysql.sh
Last active Jan 19, 2020
Run MySQL server by docker with configurations
View docker-mysql.sh
#!/bin/bash
# This script will pull down the latest mysql 5.7 and run a container.
LOCAL_MYSQL_ROOT=/docker/mysql/data # The local mysql data directory.
LOCAL_MYSQL_CNF_DIR=/docker/mysql/conf.d # The local mysql configuration directory.
LOCAL_MYSQL_PORT=3306 # The exported port of mysql.
LOCAL_MYSQL_ADDR=0.0.0.0
DOCKER_MAX_MEMORY=512m
@fenying
fenying / get-latest-tag.sh
Last active Dec 26, 2018
Get the latest tag of git respository
View get-latest-tag.sh
#!/bin/bash
# Method 1, reference: https://stackoverflow.com/a/29497919
git log --tags --simplify-by-decoration --pretty="format:%ci %d" | head -n 1 | grep -Po '(?<=tag: ).+?(?=,)'
# Method 2, reference: https://stackoverflow.com/questions/6269927/how-can-i-list-all-tags-in-my-git-repository-by-the-date-they-were-created#comment81585017_24830212
git tag --sort=-creatordate | head -n 1
@fenying
fenying / acme-nginx-alidns.sh
Last active Dec 12, 2018
Issue SSL cert with AliDNS by ACME.sh
View acme-nginx-alidns.sh
export Ali_Key="<ACCESS_KEY>"
export Ali_Secret="<SECRET_KEY>"
THE_DOMAIN=litert.org
THE_CERT_OUTPUT_DIR=/etc/nginx/ssl.d
mkdir -p $THE_CERT_OUTPUT_DIR
acme.sh --issue \
--dns dns_ali \
-d "$THE_DOMAIN" \