Skip to content

Instantly share code, notes, and snippets.

@allex
allex / README.md
Created March 11, 2019 05:20 — forked from marz619/README.md
Go build LDFlags

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)
$>
@allex
allex / post-checkout
Created January 7, 2020 11:23 — 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
#!/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"
@allex
allex / json.lua
Created February 11, 2020 09:18 — forked from tylerneylon/json.lua
Pure Lua json library.
--[[ 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 / git-quote-string-multiline
Created March 6, 2020 10:26 — forked from HaleTom/git-quote-string-multiline
Quote a single- or multi-line string for use in git's aliases
#!/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')
@allex
allex / docker-machine-rename
Created April 26, 2020 07:45 — forked from alexproca/docker-machine-rename
Rename docker-machine
#!/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
@allex
allex / gcpl.sh
Created August 14, 2020 04:34 — forked from nickboldt/gcpl.sh
git cherry pick latest (or multiple latest) commits
#!/bin/bash
#
#script to make it easier to git cherry-pick the latest commit to another branch
numCommits=1 # but we can cherry-pick more than one if needs be
red="\033[1;31m"
norm="\033[0;39m"
grey="\033[0;37m"
green="\033[0;32m"
@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')
@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"
@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'));
@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