Skip to content

Instantly share code, notes, and snippets.

View warriorg's full-sized avatar
🏠
Working from home

warriorg warriorg

🏠
Working from home
View GitHub Profile
@warriorg
warriorg / Amount2RMB.java
Created November 25, 2023 11:03 — forked from binjoo/Amount2RMB.java
JAVA:字符串金额转成中文大写
/*
* Amount2RMB.java 2008-6-15
*/
package test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Amount2RMB {
private static final Pattern AMOUNT_PATTERN =
@warriorg
warriorg / bash_strict_mode.md
Created June 30, 2022 01:33 — forked from vncsna/bash_strict_mode.md
set -e, -u, -o, -x pipefail explanation

set -e, -u, -o, -x pipefail

The set lines

  • These lines deliberately cause your script to fail. Wait, what? Believe me, this is a good thing.
  • With these settings, certain common errors will cause the script to immediately fail, explicitly and loudly. Otherwise, you can get hidden bugs that are discovered only when they blow up in production.
  • set -euxo pipefail is short for:
set -e
set -u
@warriorg
warriorg / keys.go
Created August 19, 2021 02:25 — forked from sdorra/keys.go
Golang RSA Key Generation
/*
* Genarate rsa keys.
*/
package main
import (
"crypto/rand"
"crypto/rsa"
"crypto/x509"
@warriorg
warriorg / front
Created March 25, 2021 03:02
anki cloze template
<div class="card">
{{#Example}}
<div id="context">{{Example}}</div>
<div id="word">{{Word}}</div>
{{/Example}}
{{^Example}}
<div style="text-align: center">
<div>{{Word}}</div>
<div>{{IPA}}</div>
@warriorg
warriorg / Docker Compose + NATS example
Created March 30, 2020 03:55 — forked from wallyqs/Docker Compose + NATS example
NATS Docker blog post/HTTP Server
FROM golang:1.6.2
COPY . /go
RUN go get github.com/nats-io/nats
RUN go build api-server.go
EXPOSE 8080
ENTRYPOINT ["/go/api-server"]
@warriorg
warriorg / get_request
Created December 23, 2019 02:36
通过spring,在项目的任意位置获取当前Request
public static HttpServletRequest getRequest(){
ServletRequestAttributes ra= (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = ra.getRequest();
return request;
}
@warriorg
warriorg / gist:8779d29edb27a1375ff2decebe915249
Created June 2, 2019 02:38 — forked from jedp/gist:3166317
Logging module, file, and line number of caller
var util = require('util');
const STACK_FRAME_RE = new RegExp(/at ((\S+)\s)?\(?([^:]+):(\d+):(\d+)/);
const THIS_FILE = __filename.split('/')[__filename.split('/').length - 1];
var Logger = module.exports = function Logger() {
// I like pie
};
Logger.prototype = {
@warriorg
warriorg / PasswordCheck.go
Created October 29, 2018 08:04 — forked from xigang/PasswordCheck.go
校验密码。密码强度要求:必须包含大写字母、小写字母、数字、特殊字符(!@#$%^&*_-)中的至少三种
func PasswordCheck(passwd string) error {
indNum := [4]int{0, 0, 0, 0}
spCode := []byte{'!', '@', '#', '$', '%', '^', '&', '*', '_', '-'}
if len(passwd) < 6 {
return errors.New("password too short")
}
passwdByte := []byte(passwd)
@warriorg
warriorg / sendMail.go
Created July 22, 2017 08:04 — forked from andelf/sendMail.go
golang send mail net/smtp SMTP
package main
import (
"log"
"net/mail"
"encoding/base64"
"net/smtp"
"fmt"
"strings"
var (
codes = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/~!@#$%^&*()_="
codeLen = len(codes)
)
func RandNewStr(len int) string {
data := make([]byte, len)
rand.Seed(time.Now().UnixNano())
for i := 0; i < len; i++ {