Skip to content

Instantly share code, notes, and snippets.

View turboBasic's full-sized avatar
🔮
Focusing

andriy melnyk turboBasic

🔮
Focusing
View GitHub Profile
@turboBasic
turboBasic / redirect-stdin-and-stdout-to-terminal.zsh
Last active June 21, 2025 14:32
Forcefully read text from terminal even when in pipeline #zsh #shell
#!/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
@turboBasic
turboBasic / locale-demo.zsh
Last active June 12, 2025 12:18
Locale comparison functions #zsh #bash
# 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"
@turboBasic
turboBasic / git-commit-size
Last active June 10, 2025 08:55 — forked from kobake/git-commit-size.sh
Calculate size of a git commit object #git
# 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.
@turboBasic
turboBasic / aws.zsh
Last active May 20, 2025 10:39
Helpers for AWS CLI #aws #zsh
# 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,
@turboBasic
turboBasic / bw-get-field
Last active April 4, 2025 15:54
Get field from Bitwarden item #zsh
#!/bin/sh
item=$1
field=$2
bw get item "$1" \
| jq --raw-output '.fields[] | select(.name == "'"$field"'") | .value'
@turboBasic
turboBasic / .zshrc
Last active May 6, 2023 03:05
Zshrc file for zdharma-continuum/zinit framework #zsh #zinit #dotfiles
## 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
@turboBasic
turboBasic / useListAsVarargItem.groovy
Last active May 25, 2022 12:18
Use List as vararg item in Jenkins pipeline (spread operator is disabled) #groovy #jenkins
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() + ': ')
@turboBasic
turboBasic / wrapperDemo.groovy
Last active May 25, 2022 12:41
Groovy: wrap variable number of nested Closure calls #groovy
/**
* 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
@turboBasic
turboBasic / getHostFromUrl.groovy
Last active January 2, 2022 16:07
getHostFromUrl() #groovy
String getHostFromUrl(String url) {
url
.replaceAll('^[a-z]+://', '')
.replaceAll('(/.*)?$', '')
.replaceAll('(:[0-9]+)?$', '')
}
def getHostFromUrlSpec() {
expect:
getHostFromUrl('https://example.com:9999/path.ext') == 'example.com'
@turboBasic
turboBasic / argumentsProcessing.groovy
Last active May 25, 2022 11:24
Method arguments processing in Groovy #groovy
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"
}