Daily Shaarli
October 18, 2017
Via : https://hugogiraudel.com/2013/07/29/optimizing-with-bash/
adaptation sale, mais fait le boulot.
Pngoptimizer est disponible ici http://psydk.org/pngoptimizer
#!/bin/bash
PROGNAME=${0##*/}
INPUT=''
QUIET='0'
NOSTATS='0'
MOVE='0'
max_input_size=0
max_output_size=0
usage()
{
cat <<EO
Usage: $PROGNAME [options]
Script to optimize JPG and PNG images in a directory.
Options:
EO
cat <<EO | column -s\& -t
-h, --help & shows this help
-m, --move & move files (deleting source)
-q, --quiet & disables output
-i, --input [dir] & specify input directory (current directory by default)
-o, --output [dir] & specify output directory ("output" by default)
-ns, --no-stats & no stats at the end
EO
}
# $1: input image
# $2: output image
optimize_image()
{
input_file_size=$(stat -c%s "$1")
max_input_size=$(expr $max_input_size + $input_file_size)
if [ "${1##*.}" = "png" ]; then
optipng -o1 -clobber -quiet $1 -out $2
pngcrush -q -rem alla -reduce $1 $2 >/dev/null
fi
if [ "${1##*.}" = "jpg" -o "${1##*.}" = "jpeg" ]; then
jpegtran -copy none -progressive $1 > $2
fi
if [ "$MOVE" == "1" ]; then
rm -f $1
fi
output_file_size=$(stat -c%s "$2")
max_output_size=$(expr $max_output_size + $output_file_size)
}
get_max_file_length()
{
local maxlength=0
IMAGES=$(find $INPUT -regextype posix-extended -regex '.*\.(jpg|jpeg|png)' | grep -v $OUTPUT)
for CURRENT_IMAGE in $IMAGES; do
filename=$(basename "$CURRENT_IMAGE")
if [[ ${#filename} -gt $maxlength ]]; then
maxlength=${#filename}
fi
done
echo "$maxlength"
}
main()
{
# If $INPUT is empty, then we use current directory
if [[ "$INPUT" == "" ]]; then
INPUT=$(pwd)
fi
# If $OUTPUT is empty, then we use the directory "output" in the current directory
if [[ "$OUTPUT" == "" ]]; then
OUTPUT=$(pwd)/output
fi
# We create the output directory
mkdir -p $OUTPUT
# To avoid some troubles with filename with spaces, we store the current IFS (Internal File Separator)...
SAVEIFS=$IFS
# ...and we set a new one
IFS=$(echo -en "\n\b")
max_filelength=`get_max_file_length`
pad=$(printf '%0.1s' "."{1..600})
sDone=' [ DONE ]'
linelength=$(expr $max_filelength + ${#sDone} + 5)
# Search of all jpg/jpeg/png in $INPUT
# We remove images from $OUTPUT if $OUTPUT is a subdirectory of $INPUT
IMAGES=$(find $INPUT -regextype posix-extended -regex '.*\.(jpg|jpeg|png)' | grep -v $OUTPUT)
if [ "$QUIET" == "0" ]; then
echo --- Optimizing $INPUT ---
echo
fi
for CURRENT_IMAGE in $IMAGES; do
filename=$(basename $CURRENT_IMAGE)
filepath=$(dirname "$CURRENT_IMAGE")
if [ "$QUIET" == "0" ]; then
printf '%s ' "$filename"
printf '%*.*s' 0 $((linelength - ${#filename} - ${#sDone} )) "$pad"
fi
#optimize_image $CURRENT_IMAGE $OUTPUT/$filename
mkdir -p ${filepath/$INPUT/"$OUTPUT/"}
optimize_image $CURRENT_IMAGE ${CURRENT_IMAGE/$INPUT/"$OUTPUT/"}
if [ "$QUIET" == "0" ]; then
printf '%s\n' "$sDone"
fi
done
# we restore the saved IFS
IFS=$SAVEIFS
if [ "$MOVE" == "1" ]; then
find $INPUT -type d -empty -delete
fi
if [ "$NOSTATS" == "0" -a "$QUIET" == "0" ]; then
echo
echo "Input: " $(human_readable_filesize $max_input_size)
echo "Output: " $(human_readable_filesize $max_output_size)
space_saved=$(expr $max_input_size - $max_output_size)
echo "Space save: " $(human_readable_filesize $space_saved)
fi
}
human_readable_filesize()
{
echo -n $1 | awk 'function human(x) {
s=" b Kb Mb Gb Tb"
while (x>=1024 && length(s)>1)
{x/=1024; s=substr(s,4)}
s=substr(s,1,4)
xf=(s==" b ")?"%5d ":"%.2f"
return sprintf( xf"%s", x, s)
}
{gsub(/^[0-9]+/, human($1)); print}'
}
SHORTOPTS="h,i:,o:,q,s,m"
LONGOPTS="help,input:,output:,quiet,no-stats,move"
ARGS=$(getopt -s bash --options $SHORTOPTS --longoptions $LONGOPTS --name $PROGNAME -- "$@")
eval set -- "$ARGS"
while true; do
case $1 in
-h|--help)
usage
exit 0
;;
-i|--input)
shift
INPUT=$1
;;
-o|--output)
shift
OUTPUT=$1
;;
-q|--quiet)
QUIET='1'
;;
-s|--no-stats)
NOSTATS='1'
;;
-m|--move)
MOVE='1'
;;
--)
shift
break
;;
*)
shift
break
;;
esac
shift
done
mainDepuis quelques, la chasse est ouverte. La feignasse, ça se pêche, ça s’appâte, ça se chasse. Guillaume lui aussi a voulu en débusquer dans les rues de Paris.
This tutorial shows how you can back up Linux and Windows systems with BackupPC. BackupPC acts as a server and is installed on a Linux system, and from there it can connect to all Linux and Windows systems in your local network to back them up and restore them without interfering with the user's work on that system. On the clients minimal to no configuration is needed. BackupPC supports full and incremental backups, and it comes with a neat web frontend for the administrator and normal user so that backups and recoveries can be managed through a web browser. It should be noted, however, that BackupPC does file-based backups, not bit-wise backups like Ghost4Linux, for example, so it is not made for disk/partition imaging.
Avec :
Suivi des versions Windows 10 tellement c'est bordélique.
A simple management tool for dnscrypt-proxy
Les 28 volumes de l’Encyclopédie de Diderot et d’Alembert sont désormais en ligne sur le site de l’Académie des sciences. Une interface numérique aboutie permet de découvrir dans toute sa richesse la plus incroyable entreprise éditoriale du XVIIIe siècle. Alexandre Guilbaud, qui a piloté le projet, nous en dévoile les grandes lignes.
Microsoft a mis en ligne la version finale du kit de déploiement et d’évaluation (ADK) pour Windows 10 1709 (Fall Creators Update).
Central Authentication System de Apereo (anciennement Jasig) est un service Web permettant de fournir un serveur d’authentification unique (SSO).
Le but du jeu est de ne pas redemander l’authentification des utilisateurs pour les différents services Web internes de l’entreprise.
Du ministère de l'intérieur à la victoire de l’Élysée, il n'aura fallu que deux années à Sarkozy pour faire une campagne pied au plancher.
This is Part 1 of the Comprehensive Guide to Terraform series. In the intro to the series, we discussed why every company should be using infrastructure-as-code (IAC). In this post, we’re going to discuss why we picked Terraform as our IAC tool of choice.
So let’s try a not-so-easy exercise: write a script to optimize a directory of images. Yup, I know there are a lot of web services offering this kind of feature
Script auto pour optimiser jpeg+png,
script ici : https://gist.github.com/lgiraudel/6065155
Comme l’IPv6 est prioritaire par rapport à l’IPv4, j’ai décidé de basculer mes DNS en IPv6 ! Sur Windows, j’utilise depuis plusieurs années DNScrypt couplé à Unbound. Pour rappel, DNScrypt permet de chiffrer vos requêtes vers un DNS public de votre choix. Unbound, quant à lui, est un cache DNS qui évite de solliciter en permanence les serveurs publics accessibles par DNScrypt. Sans Unbound, votre résolution DNS risque d’être extrêmement lente !
Le long épisode de questionnement lancé par la loi de finance 2016 n’en a fini d’évoluer de précisions en amendement tant le point de départ était flou… Après la FAQ de cet été, voici les amendements issus de la loi de finances 2018.
strace is a powerful command line tool for debugging and trouble shooting programs in Unix-like operating systems such as Linux. It captures and records all system calls made by a process and the signals received by the process.
Présentation du projet d’API REST avec un backend écrit en Golang, une base NoSQL Mongo DB avec un proxy Nginx dans du Docker Swarm