Skip to content

Instantly share code, notes, and snippets.

View leagris's full-sized avatar
:octocat:

Léa Gris leagris

:octocat:
  • France - Marvejols
View GitHub Profile
#!/usr/bin/env bash
print_basket() {
# Print remaining keys (content of basket)
for fruit in "${!basket[@]}"; do
printf '%d %s\n' "${basket[$fruit]}" "${fruit,,}"
done
}
declare -a all_fruits=(
@leagris
leagris / mandelbrot.sh
Last active January 6, 2023 17:27
Mandelbrot for POSIX shell
#!/usr/bin/env sh
#
# Modified version of bash mandelbrot from Mecki stackoverflow.com/users/15809
# found at https://stackoverflow.com/a/63749612/1765658
# Avoiding forks and running bc as background task, reducing
# execution time, from many hours to less than 10' (on my desktop)
#
# Modified version for POSIX shell by Léa Gris:
# https://gist.github.com/leagris/59e1b7e72462024b278652696f375e71
# Improved to addressing fifos by FDs.
@leagris
leagris / OVHGhostNSCheck.sh
Created March 16, 2021 18:16
OVH Ghost mutualised DNS checker
#!/usr/bin/env sh
# Domain name to retrieve ghost host RR from
__ARG_DOMAIN=${1:-example.com}
# Setup the name or IP of the ghost OVH mutu hosting DNS
__ARG_GHOST_NS=${2:-dns200.anycast.me.}
old_ip=$(
dig +short +norecurs "$__ARG_DOMAIN" "@$__ARG_GHOST_NS" -t A 2>/dev/null
@leagris
leagris / RendererSettings.md
Last active January 3, 2021 14:22
Renderer settings per side for correct UV regardless of block bounds

Renderer settings per side for correct UV regardless of block bounds:

Side field_152631_f flipTexture
XPos
XNeg
YPos
YNeg
Zpos
ZNeg
@leagris
leagris / mapfile_assoc_shim.sh
Last active December 18, 2020 02:40
A shim for Bash's mapfile to support mapping key value pairs into an associative array
#!/usr/bin/env bash
# mapfile_assoc_shim.sh
# If mapfile does not have a -A associative array mode
# then implement it
# Usage:
# include mapfile_assoc_shim.sh
# or
# . mapfile_assoc_shim.bash
#
# Example:
@leagris
leagris / github.sieve
Last active February 12, 2022 02:41
Sieve filter for GitHub notifications
# rule:[notifications@github.com]
#require ["fileinto", "mailbox", "variables", "imap4flags", "regex"];
if address :is "from" "notifications@github.com" {
set "gitfolder" "Lists.GitHub";
if header :matches "List-ID" "*<*.*.github.com>" {
set "gituser" "${3}";
set "gitrepository" "${2}";
# Replace . or + by dashes for proper IMAP folder name
# Sieve has no regex global replace, so do it at max 3 occurences
if string :regex "${gitrepository}" "(.*)[.+]+(.*)" {
@leagris
leagris / which-min.sh
Last active March 27, 2022 22:25
Bash implementation of debianutils:which
#!/usr/bin/env bash
IFS=:;if (($#>0))&&[ "${1:0:1}" == - ];then if [ "$1" != -a ];then printf >&2 'Illegal option %s\nUsage: which [-a] args\n' "$1";exit 2;else b=1;fi;shift;fi;read -rd '' -a g < <(printf %s:\\0 "$PATH");while (($# > 0));do f=0;for d in "${g[@]}";do e="$d/$1";while [[ -L $e && "$(ls -l "$e")" =~ -\>\ (.*) ]];do e="${BASH_REMATCH[1]}";done;if [[ -f $e && -x $e ]];then f=1;echo "$d/$1";((b))||break;fi;done;((f))||c=1;shift;done;exit $c