Skip to content

Instantly share code, notes, and snippets.

@allex
allex / self-signed-certificate-with-custom-ca.md
Created June 8, 2021 14:06 — forked from fntlnz/self-signed-certificate-with-custom-ca.md
Self Signed Certificate with Custom Root CA

Create Root CA (Done once)

Create Root Key

Attention: this is the key used to sign the certificate requests, anyone holding this can sign certificates on your behalf. So keep it in a safe place!

openssl genrsa -des3 -out rootCA.key 4096
@allex
allex / bash_strict_mode.md
Created June 2, 2021 02:16 — forked from mohanpedala/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
@allex
allex / foo.js
Created May 25, 2021 14:56 — forked from OliverJAsh/foo.js
function reverseFormatNumber(val,locale){
var parts = new Intl.NumberFormat(locale).formatToParts(1111.1);
var group = parts.find(part => part.type === 'group').value;
var decimal = parts.find(part => part.type === 'decimal').value;
var reversedVal = val.replace(new RegExp('\\' + group, 'g'), '');
reversedVal = reversedVal.replace(new RegExp('\\' + decimal, 'g'), '.');
return Number.isNaN(reversedVal)?0:+reversedVal;
}
console.log(reverseFormatNumber('1,234.56','en'));
#!/bin/sh
# by @allex_wang
# GistURL: https://gist.github.com/allex/33de61e650be11f472f49df4efb89b9b
# GistID: 33de61e650be11f472f49df4efb89b9b
set -e
cur=$(pwd)
tmp=$(mktemp -d)
scriptName=$(basename "$0")
@allex
allex / simple_args_parsing.sh
Created April 29, 2021 04:11 — forked from jehiah/simple_args_parsing.sh
a simple way to parse shell script arguments
#!/bin/sh
#
# a simple way to parse shell script arguments
#
# please edit and use to your hearts content
#
ENVIRONMENT="dev"
#!/bin/sh
set -x
# do some route cleanup after vpn connected.
# by @allex_wang
# GistID: 5b264ff483e7a67318f7ad2504e94d3c
exec >/tmp/tidu-vpn.log 2>&1
if [ ! "$EUID" = "0" ]; then
#!/bin/sh
# helper for cleanup docker registry (based on api v2)
# by @allex_wang
# GistID: 3aab7875e033815227dd313a79465e18
# requires: [jq]
set -eu
scriptName=$(basename "$0")
REGISTRY=127.0.0.1:5000
REG_USER=
#!/bin/bash
# vim: set ft=sh fdm=manual ts=2 sw=2 sts=2 tw=85 et:
# ================================================
# Description: git-release-npm for release npm package
# Last Modified: Thu Dec 16, 2021 00:06
# Author: Allex Wang ([email protected])
# GistID: d76edec6238937813a9bc4d4e2f19d9c
# GistURL: https://gist.github.com/allex/d76edec6238937813a9bc4d4e2f19d9c
# ================================================
@allex
allex / ReadSTDIN.go
Created January 19, 2021 03:54 — forked from AlexMocioi/ReadSTDIN.go
Read big text data from SDIN in Go
package main
import "fmt"
import "bufio"
import "os"
func main() {
f, _ := os.Create("outputgo.txt")
reader := bufio.NewReader(os.Stdin)
for {
line, err := reader.ReadString('\n')
#!/bin/sh
# vim: set ft=sh fdm=manual ts=2 sw=2 sts=2 tw=85 et:
# ================================================
# Description: A docker build alternative impl, support squash and interactive build
# Usage:
# $ docker-build -t foo:1.0.0 -f ./Dockerfile --no-cache (all of native build args)
# -i interactive mode to maintain intermediate container
# Last Modified: Tue Dec 08, 2020 17:57
# Author: Allex Wang ([email protected])