Skip to content

Instantly share code, notes, and snippets.

View CristianCantoro's full-sized avatar
🎯
Focusing

Cristian Consonni CristianCantoro

🎯
Focusing
View GitHub Profile
@CristianCantoro
CristianCantoro / example.py
Last active June 27, 2018 12:47
Using docopts for bash and docopt for python
#!/usr/bin/env python3
"""
Usage:
example.sh [options]
example.sh ( -h | --help )
example.sh ( --version )
Options:
-a, --all An optional flaag.
-b Another optional flag.
@CristianCantoro
CristianCantoro / scoping.sh
Last active May 31, 2018 13:08
Variable scoping in bash
#!/bin/bash
function hello() {
local fname="$1"
echo "Ciao, $fname"
}
echo "Ereditato dal terminale"
echo "\$USER: $USER"
@CristianCantoro
CristianCantoro / signal.sh
Last active May 25, 2018 18:22
Testing `nohup`, `&` and `disown`
#!/usr/bin/env bash
# shellcheck disable=SC2128
SOURCED=false && [ "$0" = "$BASH_SOURCE" ] || SOURCED=true
if ! $SOURCED; then
set -euo pipefail
IFS=$'\n\t'
fi
mypid="$$"
@CristianCantoro
CristianCantoro / esempio.sh
Last active May 25, 2018 09:57
Example script with docopts
#!/usr/bin/env bash
# shellcheck disable=SC2128
SOURCED=false && [ "$0" = "$BASH_SOURCE" ] || SOURCED=true
debug=false
parallel=false
query=''
topic=''
read -rd '' docstring <<EOF
@CristianCantoro
CristianCantoro / tsp.h
Created May 15, 2018 14:55
An header that works for C and C++
#ifndef TSP_H
#define TSP_H
#ifdef __cplusplus
// C++ code
using namespace std;
namespace helpers {
long long get_elapsed_time(void);
bool has_reached_timeout(void);
@CristianCantoro
CristianCantoro / histo_timestamps.py
Last active March 13, 2018 20:06
Create a histograms with time on the x-axis using arrow and matplotlib
#!/usr/bin/env python
import argparse
import arrow
from matplotlib import pyplot as plt
from matplotlib import dates as mdates
def get_args():
description=('Make an histogram from a list of timestamps')
@CristianCantoro
CristianCantoro / ..CMS_signal_setrlimit.md
Last active May 4, 2019 20:44
Handling RLIMIT_CPU signal SIGXCPU

README.md

@CristianCantoro
CristianCantoro / backup_restic.sh
Last active February 9, 2018 15:48
Backup script for restic
#!/usr/bin/env bash
# shellcheck disable=SC2128
SOURCED=false && [ "$0" = "$BASH_SOURCE" ] || SOURCED=true
if ! $SOURCED; then
set -euo pipefail
IFS=$'\n\t'
fi
awk_script=$(cat <<'AWKSCRIPT'
@CristianCantoro
CristianCantoro / keybase.md
Created February 16, 2017 23:01
keybase.md

Keybase proof

I hereby claim:

  • I am cristiancantoro on github.
  • I am cristiancantoro (https://keybase.io/cristiancantoro) on keybase.
  • I have a public key ASD3Kw17RB1F0WqiERb4VZ7d9ZwMpusDGQjppWw3H8CcfAo

To claim this, I am signing this object: