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 / aws.zsh
Last active August 19, 2023 13:39
Helpers for AWS CLI #aws #zsh #bash
# List running EC2 instances filtered by `Name` tag
#
# params:
# $1 - optional string. Filters output by instances with `Name` tag containing the string
function 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 / .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"
}
@turboBasic
turboBasic / test-firefox-places-queries.md
Last active November 9, 2021 10:24
List of test queries and bookmark items for Firefox places db #firefox

List of test queries and bookmarks for Firefox Places database

Bookmark items for testing queries

@turboBasic
turboBasic / generate.sh
Last active October 24, 2021 18:46
LS_COLORS file for file type coloring in ls, grep etc.
function __generate() {
typeset -A themes=(
[molokai]="no=0:di=0;38;2;102;217;239:ln=0;38;2;249;38;114:ow=0:so=0;38;2;0;0;0;48;2;249;38;114:fi=0:tw=0:ex=1;38;2;249;38;114:mi=0;38;2;0;0;0;48;2;255;74;68:*~=0;38;2;122;112;112:pi=0;38;2;0;0;0;48;2;102;217;239:or=0;38;2;0;0;0;48;2;255;74;68:cd=0;38;2;249;38;114;48;2;51;51;51:bd=0;38;2;102;217;239;48;2;51;51;51:st=0:*.r=0;38;2;0;255;135:*.t=0;38;2;0;255;135:*.o=0;38;2;122;112;112:*.a=1;38;2;249;38;114:*.d=0;38;2;0;255;135:*.h=0;38;2;0;255;135:*.m=0;38;2;0;255;135:*.p=0;38;2;0;255;135:*.z=4;38;2;249;38;114:*.c=0;38;2;0;255;135:*.td=0;38;2;0;255;135:*.hs=0;38;2;0;255;135:*.mn=0;38;2;0;255;135:*.jl=0;38;2;0;255;135:*.ui=0;38;2;166;226;46:*.pl=0;38;2;0;255;135:*.ml=0;38;2;0;255;135:*.py=0;38;2;0;255;135:*.kt=0;38;2;0;255;135:*.el=0;38;2;0;255;135:*.ps=0;38;2;230;219;116:*.cc=0;38;2;0;255;135:*.gv=0;38;2;0;255;135:*.ts=0;38;2;0;255;135:*.vb=0;38;2;0;255;135:*.rb=0;38;2;0;255;135:*.di=0;38;2;0;255;135:*.rs=0;38;2;0;255;135:*.pp=0;38;2;0;255;135:*.xz=4;38;2;2
@turboBasic
turboBasic / changeCallerOfClosure.groovy
Last active May 25, 2022 12:00
Dynamically change caller of Groovy closure #groovy
void withOptionalDocker(String dockerImageName, Closure body) {
(dockerImageName
? { c -> withDockerContainer(image: dockerImageName) {c()} }
: { c -> c() }
)(body)
}
withOptionalDocker(shouldUseDocke() ? 'my-image' : null) {
sh 'doSomething'
}
@turboBasic
turboBasic / rename-program-in-ubuntu.md
Last active September 15, 2021 18:37
Rename program provided by Ubuntu/Debian package manager #ubuntu

Rename program in Ubuntu

Example 1. Rename ack-grep utility to ack

sudo dpkg-divert --local --divert /usr/bin/ack --rename --add /usr/bin/ack-grep