Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env awk -f
# Parse option args with an OPTSTRING
#
# Author: Allex Wang (allex.wxn@gmail.com)
# Last Modified: Tue Aug 24, 2021 20:08
#
# Usage: echo "<OPTS>|<ARGS>" | parse_args
# eg> echo "-c 10 --welcome 'hi allex' -f |-c:,-v,--welcome:" | awk -f parse_args.awk
#
#!/bin/bash
# vim: set ft=sh fdm=marker ts=2 sw=2 sts=2 tw=85 et:
set -eu
# ================================================
# Description: Enhanced docker build with some helper parameters, such as --env, --build-arg-file
#
# Usage:
# docker-build [ -t tag_list ] [ -f Dockerfile ] [ ... ] [ --env <env_file> ] [ --build-arg-file <args_file> ]
#
#!/bin/bash
# By allex_wang
# GistID: 3bed8534d89fa58ff47b9d98752e3fef
# Last Modified: Fri Sep 24, 2021 10:51
set -e
PROG=$(basename "$0")
error() { echo >&2 "[$PROG]: ${*}"; }
[ "${CI-}" != true ] && { error "Runner context invalid"; exit 1; }
[ "${CI_DEBUG_TRACE-}" = "true" ] && set -x
@allex
allex / pack.js
Last active August 4, 2021 11:26
#!/usr/bin/env node
// GistID: 5ca7aa7bae0dc160c2e651611cc801ad
// GistURL: https://gist.github.com/allex/5ca7aa7bae0dc160c2e651611cc801ad
// by allex | MIT Licensed
// Usage: pack.js /foo/path -o - |tar tzf -
const sh = (cmd) => require('child_process').execSync(cmd).toString().trim()
const npmRoot = sh('npm root -g')
require('app-module-path').addPath(`${npmRoot}/npm/node_modules`)
@allex
allex / kubernetes-dashboard.md
Created August 2, 2021 15:08 — forked from tonysneed/kubernetes-dashboard.md
Kubernetes Dashboard
  1. Install the dashboard
    • Run: kubectl apply -f https://raw.githubusercontent.com/kubernetes/dashboard/v2.2.0/aio/deploy/recommended.yaml
  2. Create admin-user
    • Create a file named: dashboard-adminuser.yaml
    • Add this content:
apiVersion: v1
kind: ServiceAccount
metadata:
@allex
allex / input.scss
Created July 21, 2021 14:13
Generated by SassMeister.com.
// colors
$color-black: #595a5d !default;
$color-white: #fff !default;
$color-primary: #566779 !default;
$color-success: #40e193 !default;
$color-warning: #ffc688 !default;
$color-danger: #f44747 !default;
$color-info: #909399 !default;
$color-highlight: #edc547 !default;
@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")