This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env zsh | |
## Save initial state | |
exec {saved_stdin}<&0 # save initial stdin | |
exec {saved_stdout}>&1 # save initial stdout | |
## Redirect initial stdin and stdout to terminal |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: compare-locales LC_TIME POSIX de_DE.UTF-8 'date' | |
function compare-locales() { | |
local -r category="$1" | |
local -r locale1="$2" | |
local -r locale2="$3" | |
local -r command="$4" | |
#echo "=== Comparing '$command' in $locale1 and $locale2 ===" | |
printf "Output in %-15s %s\n" "$locale1:" "$( | |
export "$category=$locale1" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Calculate the size of a git commit in bytes. | |
function git-commit-size() { | |
# This script calculates the size of a git commit in bytes. | |
# Usage: git-commit-size.sh <commit hash> | |
# | |
# Example: | |
# git-commit-size.sh 1234567 | |
# | |
# Output: | |
# The total size of the commit in bytes, formatted with thousands separators. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# List running EC2 instances filtered by `Name` tag | |
# | |
# params: | |
# $1 - optional string. Filters output by instances with `Name` tag containing the string | |
function aws-ec2() { | |
aws ec2 describe-instances \ | |
--filter "Name=instance-state-name,Values=running" \ | |
--filter "Name=tag:Name,Values=*$1*" \ | |
--query "Reservations[].Instances[].{ | |
id: InstanceId, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
item=$1 | |
field=$2 | |
bw get item "$1" \ | |
| jq --raw-output '.fields[] | select(.name == "'"$field"'") | .value' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Global vars | |
export LESS='--buffers=128 --HILITE-UNREAD --ignore-case --LONG-PROMPT --max-back-scroll=15 --no-init --quiet --quit-at-eof --quit-if-one-screen --RAW-CONTROL-CHARS --status-column --tabs=4 --window=-4' | |
export FZF_DEFAULT_COMMAND='rg --files --no-ignore --hidden --follow --glob "!.git/*"' | |
export FZF_DEFAULT_OPTS='--height 50% --ansi --info=inline' | |
export EDITOR='/usr/local/bin/nvim' | |
## zinit | |
source ~/.zinit/bin/zinit.zsh |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def foo(Object... args) { | |
def normalizedArgs = [] | |
if (args != null) { | |
if (args.size() == 1) { | |
normalizedArgs << args[0] | |
} else { | |
normalizedArgs += args.toList() | |
} | |
} | |
print('foo(varargs): ' + normalizedArgs.size() + ': ') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Class Wrapper allows to wrap and execute variable number of nested Closures. | |
* Immediately-wrapped closure is accessible inside the wrapper as variable `_`. | |
*/ | |
final class Wrapper { | |
private final List stack = [] | |
Wrapper leftShift(Closure c) { | |
c.resolveStrategy = Closure.DELEGATE_FIRST | |
stack << c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String getHostFromUrl(String url) { | |
url | |
.replaceAll('^[a-z]+://', '') | |
.replaceAll('(/.*)?$', '') | |
.replaceAll('(:[0-9]+)?$', '') | |
} | |
def getHostFromUrlSpec() { | |
expect: | |
getHostFromUrl('https://example.com:9999/path.ext') == 'example.com' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String f(Object... varArgs) { | |
List args = varArgs == null ? [null] : varArgs | |
Map named = args | |
? (args[0] instanceof Map ? args[0] : [:]) | |
: [:] | |
List positional = named ? args.drop(1) : args | |
"named: $named; positional: $positional; all: $args" | |
} |
NewerOlder