Skip to content

Instantly share code, notes, and snippets.

View leewaiho's full-sized avatar
😗
be stronger

weihao leewaiho

😗
be stronger
View GitHub Profile
@leewaiho
leewaiho / redis-lock.go
Created May 28, 2019 07:36
Go 语言实现 Redis分布式锁
package util
import (
"gopkg.in/redis.v5"
"github.com/pborman/uuid"
"time"
)
const (
UNLOCK_SCRIPT = "if (redis.call('get', KEYS[1]) == ARGV[1]) then \n redis.call('del', KEYS[1]) \n return 1 \n else \n return 0 \n end"
@leewaiho
leewaiho / set_timeformat.sh
Created May 28, 2019 08:38
Bash Histroy命令查看时间戳
export HISTTIMEFOR="%F %T `whoami` :: "
@leewaiho
leewaiho / lottery.go
Last active May 31, 2019 07:33
Go实现抽奖机
package util
import (
"encoding/json"
"errors"
"fmt"
"math/rand"
"time"
)
@leewaiho
leewaiho / SSHKeyGen.java
Created May 31, 2019 07:46
生成用于SSH的密钥对
package com.leewaiho.business.common.util;
import org.apache.commons.codec.binary.Base64;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.math.BigInteger;
import java.security.*;
import java.security.interfaces.RSAPublicKey;
@leewaiho
leewaiho / httpclient-without-redirect.go
Created June 6, 2019 07:42
希望使用不自动重定向请求的httpClient客户端时
client: &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
},
}
@leewaiho
leewaiho / common-CurrentFuncInformation.go
Last active June 26, 2019 07:09
似乎是更好的选择
func GetCurrentFuncInfo() (funcName string, fileName string, line int) {
pc, file, line, ok := runtime.Caller(1)
f := runtime.FuncForPC(pc)
if ok {
return f.Name(), file, line
} else {
return "", "", -1
}
}
@leewaiho
leewaiho / rfc3339.js
Created August 1, 2019 08:08 — forked from pjdietz/rfc3339.js
Format a local date as an RFC 3339 date with timezone
function rfc3339(d) {
function pad(n) {
return n < 10 ? "0" + n : n;
}
function timezoneOffset(offset) {
var sign;
if (offset === 0) {
return "Z";
@leewaiho
leewaiho / rfc3339-es6.js
Last active August 1, 2019 08:11
rfc3339 es6 version by ailgip(https://github.com/liapig)
const rfc3339Date = d => {
const pad = n => {
return n < 10 ? "0" + n : n
}
const timezoneOffset = (offset) => {
let sign
if (offset === 0) {
return "Z"
}
@leewaiho
leewaiho / plantuml.sh
Created August 1, 2019 08:12
shortcut to use plantuml.jar
#!/bin/sh
# save as /sbin/plantuml
PLANTUML_JAR_FILE="/usr/lib/plantuml.jar"
generateUML() {
echo "\033[033mstart generating\033[0m" &&java -jar ${PLANTUML_JAR_FILE} $1 && echo "\033[032mgenerate success\033[0m"
}
generateUML $1
@leewaiho
leewaiho / email_embed_image.go
Created August 22, 2019 13:05
发送包含图片的HTML邮件
func ExampleMessage_Embed() {
m.Embed("/tmp/image.jpg")
m.SetBody("text/html", `<img src="cid:image.jpg" alt="My image" />`)
}