Skip to content

Instantly share code, notes, and snippets.

@horothesun
horothesun / get_docker_hub_tags.sh
Last active June 29, 2023 13:00
Get Docker Hub repo tags
#!/bin/bash
# Call by running
# ./get_docker_hub_tags.sh "library" "alpine"
[[ -z "${DOCKER_HUB_TOKEN}" ]] && echo "Error: DOCKER_HUB_TOKEN must be defined" && exit 100
export DOCKER_NAMESPACE="$1"
export DOCKER_REPOSITORY="$2"
[[ -z "${DOCKER_NAMESPACE}" ]] && echo "Error: a Docker namespace must be passed as first argument" && exit 10
@horothesun
horothesun / get_all_gh_secrets.sh
Last active June 4, 2023 10:05
Get all GitHub secrets
#!/bin/bash
# Usage: ./get_all_gh_secrets.sh "<OWNER>" "100"
GITHUB_OWNER=$1
MAX_NUMBER_OF_REPOS=$2
[[ -z "${GITHUB_OWNER}" ]] && echo "Error: GITHUB_OWNER must be passed as first parameter" && exit 10
[[ -z "${MAX_NUMBER_OF_REPOS}" ]] && echo "Error: MAX_NUMBER_OF_REPOS must be passed as second parameter" && exit 20
@horothesun
horothesun / findNumber.pl
Created October 9, 2022 20:09
Find a number X such that "prepending" 4 to X equals to 4 times the number generated by "suffixing" X with 4
%% Find a number X such that "prepending" 4 to X equals to
%% 4 times the number generated by "suffixing" X with 4.
%%
%% X = X1,...,Xn . 4,X1,...,Xn = 4 * X1,...Xn,4
%%
%% :- find( 4, 9000, 11000, N ).
%%
natural( 0 ).
natural( s(X) ) :- natural( X ).
@horothesun
horothesun / input.csv
Created September 30, 2022 08:47
CSV filtering
user_id name phone
annoyingPrefix_001 Alice 07782123456
annoyingPrefix_002 Bob 07798765432
annoyingPrefix_003 Carl 07711928374
@horothesun
horothesun / CatsEffectOODecoratorCachedClient.scala
Last active June 16, 2022 21:04
Cats-effect - Cached client
import cats.effect.{IO, Resource}
case class Config()
case class InputA()
case class InputB()
case class InputC()
case class OutputA()
case class OutputB()
case class OutputC()
@horothesun
horothesun / toggle_sidecar.sh
Last active April 6, 2022 19:37
Toggle Apple Sidecar display
#!/bin/bash
# Setup
#
# ln -sf `pwd`/toggle_sidecar.sh ~/bin/toggle_sidecar.sh
# Usage
#
# toggle_sidecar.sh
@horothesun
horothesun / clone_all_team_repos.sh
Created January 11, 2022 16:26
Clone all team repos
#!/bin/bash
# Usage: GITHUB_OWNER=<owner> GITHUB_TEAM=<team> clone_all_team_repos.sh
#
# Dependencies: gh, jq
[ -z "$GITHUB_OWNER" ] && echo "Error: GITHUB_OWNER must be defined" && exit 10
[ -z "$GITHUB_TEAM" ] && echo "Error: GITHUB_TEAM must be defined" && exit 20
function cloneIfDoesNotExist() {
@horothesun
horothesun / poll.groovy
Last active August 29, 2021 11:59
Polling in Groovy (useful for Jenkins pipelines)
def <T> T poll( // can throw
long pollIntervalSeconds, // must be bigger than `functionToPoll()` execution time
long timeoutSeconds, // global timeout
Integer maxConsecutiveExceptionsAllowed, // maximum consecutive times `functionToPoll()` can throw before polling fails
Closure<T> functionToPoll, // returns T, can throw
Closure<Boolean> successConditionOnFnResult // returns Boolean, condition over `functionToPoll()` result to determine if polling is completed
) {
def Boolean isDone = false
def Boolean isTimeout = false
def Integer exceptionCounter = 0
brew install cpanminus kpcli
# https://sourceforge.net/p/kpcli/wiki/Installation%20instructions/
cpanm Crypt::Rijndael Term::ReadKey Sort::Naturally File::KeePass Term::ShellUI Term::ReadLine::Gnu Term::ReadLine::Perl Clipboard Sub::Install Data::Password::passwdqc Data::Password::passwdqc Math::Random::ISAAC Authen::OATH Convert::Base32
@horothesun
horothesun / github_billing.sh
Last active July 13, 2021 02:08
github_billing
# IMPORTANT: GITHUB_TOKEN with "Update ALL user data" permission
#
# Dependencies:
# - curl
# - jq
#
# Run:
# GITHUB_TOKEN=<token> GITHUB_USER=<username> ./github_billing.sh
#