Skip to content

Instantly share code, notes, and snippets.

@allex
allex / git-rev
Last active May 14, 2020
git-rev
View git-rev
#!/bin/sh
set -euE
# Similar as `git describe`, but add some normalize specs:
#
# - add suffix of commit sha if not a stable tag, e.g.
# v1.0.3 => v1.0.3
# v1.0.2-dev => v1.0.2-7105ba5
# - ensure tag is starts with v, e.g. v1.0.2
#
View docker-machine-rename
#!/usr/bin/env bash
#copy this in a folder from path ex: /usr/local/bin
#usage: docker-machine-rename default my-default
# Authors
#
# alexproca initial script
# eurythmia sed magic
View pushimage.sh
#!/bin/sh
# vim: set ft=sh fdm=manual ts=2 sw=2 sts=2 tw=85 et:
# ================================================
# Description: spush docker images to remote
# Last Modified: Tue Jun 09, 2020 17:52
# Author: Allex Wang (allex.wxn@gmail.com)
# GistID: 42f93720be61ec33c0542855f5a0f543
# GistURL: https://gist.github.com/42f93720be61ec33c0542855f5a0f543
# ================================================
@allex
allex / git-quote-string-multiline
Created Mar 6, 2020 — forked from HaleTom/git-quote-string-multiline
Quote a single- or multi-line string for use in git's aliases
View git-quote-string-multiline
#!/bin/bash -eu
# Quote a single- or multi-line string for use in git's aliases
# Copyright (c) 2016 Tom Hale under https://en.wikipedia.org/wiki/MIT_License
quote() {
printf %s "$1" | sed -r 's/(["\\])/\\\1/g';
}
IFS=$(printf '\n')
View bit-flag-test.js
// Uses bit operation to reduce your codes (by allex)
// GistID: 459aaa91c9b584e127f3f45890026303
const ADD = 4
const UPDATE = 2
const DELETE = 1
const checkFlag = (v, mask) => (v & mask) === mask
const print = (v, desc) => {
View nginx-vars.lua
-- print all nginx variables
-- author: allex_wang
-- GistID: b9f5206b58570d7686c6f22b8fed3144
local inspect = require('inspect')
local keys = {
"args",
"binary_remote_addr",
"body_bytes_sent",
@allex
allex / json.lua
Created Feb 11, 2020 — forked from tylerneylon/json.lua
Pure Lua json library.
View json.lua
--[[ json.lua
A compact pure-Lua JSON library.
The main functions are: json.stringify, json.parse.
## json.stringify:
This expects the following to be true of any tables being encoded:
* They only have string or number keys. Number keys must be represented as
strings in json; this is part of the json spec.
@allex
allex / post-checkout
Created Jan 7, 2020 — forked from betorobson/post-checkout
git hook to run a command after `git pull` and `git checkout` if a specified file was change for example, package.json or bower.json
View post-checkout
#!/usr/bin/env bash
# fork from https://gist.github.com/jakemhiller/d342ad51505addf78ec628a16fd3280f
changed_files="$(git diff-tree -r --name-only --no-commit-id $1 $2)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
check_run package.json "npm prune && npm install"
View gist.sh
#!/bin/sh
# GistID: 8f9a8a45e86f0edef6caea81f0795031
set -eE
echoerr() {
echo "$@" 1>&2;
}
error() {
if [ -t 1 ]; then
echoerr "\033[1;31m$@\033[0m"
@allex
allex / README.md
Created Mar 11, 2019 — forked from marz619/README.md
Go build LDFlags
View README.md

Using the -ldflags parameter can help set variable values at compile time.

Using the example provided here:

  1. Running make build will create a build executable. Running it will result in:
$> ./build
no version (Mon YYYY)
$>
You can’t perform that action at this time.