Skip to content

Instantly share code, notes, and snippets.

View john-yuan's full-sized avatar

JOHN YUAN john-yuan

View GitHub Profile
/**
* Render template string.
*
* @example
* renderTemplate(
* 'Hello {{name}}. The \\{{name}} will be replaced.',
* { name: 'Joe' }
* )
* // Output:
* // Hello Joe. The {{name}} will be replaced.
root = true
[*]
charset = utf-8
end_of_line = lf
indent_size = 2
indent_style = space
insert_final_newline = true
max_line_length = 0
trim_trailing_whitespace = true
@john-yuan
john-yuan / hs256.go
Created April 25, 2023 23:20
Golang HS256. An example to encode jwt with HS256 in golang.
package main
import (
"crypto/hmac"
"crypto/sha256"
"encoding/base64"
"encoding/hex"
"fmt"
)
@john-yuan
john-yuan / gitpid.sh
Created April 24, 2023 01:52
Linux shell script to get pid by process name.
#!/bin/bash
readonly CMD="${@:1}"
if [ "$CMD" == "" ]
then
echo "usage: $0 <command>"
exit 1
fi
package main
import (
"errors"
"fmt"
"time"
"github.com/golang-jwt/jwt/v5"
)
@john-yuan
john-yuan / aes.go
Last active January 23, 2024 20:59
Golang AES example. AES-128-CBC, AES-192-CBC, AES-256-CBC encryption and decryption functions written in golang. https://go.dev/play/p/Kj3oeHmz0zA
package main
import (
"bytes"
"crypto/aes"
"crypto/cipher"
"crypto/rand"
"encoding/hex"
"fmt"
"io"
#!/bin/sh
readonly SERVER_PORT="8388"
readonly SERVER_PASS="your_password"
sudo yum install git
sudo yum install python-setuptools && easy_install pip
sudo pip install git+https://github.com/shadowsocks/shadowsocks.git@master
firewall-cmd --permanent --zone=public --add-port=${SERVER_PORT}/tcp
@john-yuan
john-yuan / parseObjectPath.js
Created July 13, 2019 08:02
A function to parse object path in JSON.
/**
* Parse the property path string.
*
* @param {string} path The property path.
* @returns {string[]} Returns the array of path.
*/
function parseObjectPath(path) {
var i = 0;
var l = path.length;
var ch;
/**
* 格式化价格数字
*
* @example
* // 123,456.00
* formatPrice(123456);
*
* @param {number} price 价格数字
* @param {string} [separator] 可选的分隔符号,默认为英文逗号 `,`。
* @returns {string} 返回格式化后的价格字符串。
/**
* 获取指定月份日历视图中的 42 个日期对象。
*
* @param {number} year 完整的年份数字,如 `2019` 即代表 2019 年。
* @param {number} month 月份数字,如 `11` 即代表 11 月。
* @param {number} [startWeekDay=0] 可选的参数,默认为 `0`(星期日),表示日历中的第一列为星期几(一般为星期日或者星期一)。其中 `0` 表
* 示星期日,`1` 表示星期一,后面以此类推。
* @returns {Date[]} 返回一个数组,包含 42 个 `Date` 对象。
*/
function getCalendarDateList(year, month, startWeekDay) {