Skip to content

Instantly share code, notes, and snippets.

View efrecon's full-sized avatar

Emmanuel Frecon efrecon

View GitHub Profile
@efrecon
efrecon / ghprofile.sh
Last active November 1, 2018 00:16
Uses steganography to hide a snapshot of all public projects for a github user inside a JPEG or similar. Source JPEG file should be given as an argument
#! /usr/bin/env bash
VERBOSE=0
GHUSER=efrecon
SNAPSHOT=0
while [ $# -gt 0 ]
do
case "$1" in
-u | --user)
GHUSER=$2
@efrecon
efrecon / csvsed.sh
Created October 9, 2018 06:28
Execute a sed script on one or several CSV files, in place or concatenating the output into a single CSV result file
#!/bin/sh
usage() {
if [ -n "$1" ]; then echo $1 1>&2; fi
cat << USAGE >&2
Usage:
$0 options.. [--] files...
-v | --verbose Be more verbose when waiting
--no-header Do not consider CSV file with header
--dry-run Do not modify files in place, show result instead
@efrecon
efrecon / httpcheck.sh
Last active March 31, 2021 23:33
Check URL return code against set of possible answers, defaults to 2XX. Good for internal Docker healthcheck.
#!/bin/sh
# Check if the URL passed as a first argument maches some of the HTTP codes that
# are passed in the following arguments as regular expressions. The list of
# error codes can be omitted, in which case this will be the whole "OK" range,
# from 200 to 299. When the remote site answers one of the matching code an
# exit code of 0 is returned, otherwise an error is returned.
#
# Additional options can be passed:
# -v to increase verbosity.
@efrecon
efrecon / gist:30ba2c33d700287a23959a75bef78442
Created October 3, 2018 14:18
List databases available to a given user in postgres
psql -U postgres -l -t
@efrecon
efrecon / gist:21ebe0214a4d34cbc176d39727da790c
Created October 3, 2018 14:17
List all tables in a given postgres db
echo "SELECT table_schema || '.' || table_name FROM information_schema.tables WHERE table_type = 'BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'information_schema');" | psql -U postgres -d dbname -q -t
@efrecon
efrecon / gitrdiff.sh
Created August 30, 2018 09:07
Diff between local and remote git
git fetch
git branch -a
git diff remotes/origin/HEAD
@efrecon
efrecon / dlt.sh
Created August 29, 2018 14:05
Execut docker log on all containers at once
#!/bin/bash
names=$(docker ps --format "{{.Names}}")
echo "tailing $names"
while read -r name
do
# eval to show container name in jobs list
eval "docker logs -f --tail=5 \"$name\" | sed -e \"s/^/[-- $name --] /\" &"
# For Ubuntu 16.04
@efrecon
efrecon / genepwd.sh
Created June 12, 2018 21:34
Generate and/or update mosquitto password files so content does not gets encrypted twice (and thus rendered unusable) when run. When updating files in place (when no -d option is given) this will simply detect passwords that are already encrypted and **not** touch them.
!/bin/sh
warn() {
printf "%s\n" "$*" 1>&2
}
verbose() {
if [ "$VERBOSE" = "1" ]; then printf "%s\n" "$*" 1>&2; fi
}
@efrecon
efrecon / druct.tcl
Last active May 25, 2018 22:01
druct, C-like structs using dictionaries in Tcl
namespace eval ::druct {
namespace eval types {}
namespace export {[a-z]*}
namespace ensemble create
}
proc ::druct::new { type varname } {
set typedef [Definition $type]
if { ![info exists $typedef] } {
return -code error "$type does not exist!"
@efrecon
efrecon / hub-tags.sh
Last active April 16, 2018 08:15
List all the tags for a given image at the Docker hub
#!/bin/sh
# Inspired by: https://stackoverflow.com/a/43262086, tested on Ubuntu and Alpine
if [ -z "$1" ]; then
echo "You have to provide an image name!"
exit
fi
if [ -z "$(echo "$1" | grep -o '/')" ]; then