Skip to content

Instantly share code, notes, and snippets.

@fenying
fenying / to32BitHex.js
Created January 10, 2018 06:06
Convert a signed integer into a unsigned 32-bit hex integer string.
function to32BitHex(v) {
if (typeof (v) !== 'number' || (Number.isInteger && !Number.isInteger(v))) {
throw new TypeError("Require a number as the argument.");
}
v = 0xFFFFFFFF & v;
if (v < 0) {
return (v >>> 0).toString(16);
}
else {
return v.toString(16);
@fenying
fenying / tasks.json
Created June 24, 2018 15:46
Node.js Remote Debugging Configuration for VSCode
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "[Remote-Debug-Sample] Auto-Attach",
"remoteRoot": "/home/admin/node-projects/remote-debug",
"protocol": "inspector",
"address": "localhost",
@fenying
fenying / getSameDayOfNeighboringMonth.ts
Last active November 25, 2018 08:39
Get the same day of neighboring month.
/**
* Get the same day in neighboring month, e.g.
*
* Input: ("2018-10-31", 1) Output: 2018-11-30
*
* Input: ("2018-10-30", 1) Output: 2018-11-30
*
* Input: ("2018-01-31", 1) Output: 2018-02-28
*
* Input: ("2020-01-31", 1) Output: 2020-02-29
@fenying
fenying / acme-nginx-alidns.sh
Last active December 12, 2018 09:46
Issue SSL cert with AliDNS by ACME.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" \
@fenying
fenying / get-latest-tag.sh
Last active December 26, 2018 09:43
Get the latest tag of git respository
#!/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 / git-switch-remote-repo.sh
Last active April 24, 2019 02:28
A tool for switching git remote repository URL.
#!/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 / calcIgnoreMobDefnese.js
Last active August 12, 2019 08:11
[MapleStory] Calculate ignore ratio of monster defense.
/**
* 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 / docker-php-fpm.sh
Created September 24, 2019 03:44
Install PHP-FPM by docker with extensions for MySQL and Redis
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 / calcWeaponScroll.ts
Created November 24, 2019 09:47
[MapleStory] Calculate the average ATTACK added in a weapon by scrolls
/**
* 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-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