Batch resising for web
Smaller environment (Photo credit: wikipedia)
I recently tried to measure the environmental impact of this website. I used
an online tool. The result shows the easiest way
to improve my score was to reduce image sizes. This could easily be done with
ImageMagick.
I wrote a small bach script to resize my files:
#!/bin/bash
# resize images for web use
target_size=200 # in kb
output_dir="web"
mkdir -p $output_dir
resize_image() {
echo "image $1..."
output_file=$output_dir/$1
cp "$1" "$output_file"
current_size=$(( $(stat -c%s "$output_file") / 1024 ))
factor=95
while (( current_size > target_size ))
do
echo "current size: $current_size"
current_size=$(( $(stat -c%s "$output_file") / 1024 ))
magick "$1" -resize $factor% "$output_file"
factor=$(( factor - 5 ))
done
}
for image in *jpg
do
resize_image "$image"
done
It tries several resize factor (while loop, factor being redefined line 20)
until the output size is lower than a predefined threshold.
Then, I needed to replace path in all my articles.
Kmeans with Polars
rusty python logo
The goal of this article is to use the rust
polars directly to
perform a common machine learning task I usually do using python.
The task
Let's choose a simple task: use of K-means.
To do so, we should:
- retrieve a dataset
- make some preprocessing
- perform kmeans …
Read More
Cache implementation using weakref
Bird's cache (Photo credit: Wikipedia)
This article presents a quick example of how to use
weakref to implement a
home-made cache mechanism.
Let's use the following use case:
- Let's consider items:
- items can be stored on a storage
- items can be retrieved from storage
- items are identify by an ID …
Read More
Tkinter and Asyncio
Asynchronous process results waiting (Photo credit: Wikipedia)
Graphical interfaces are typically the kind of object that can take advantage
of asynchrounous programming as a GUI spend lot of time waiting for user input.
Tkinter <https://docs.python.org/3/library/tkinter.html#module-tkinter>_
is a kind of standard for …
Read More
Wikipedia crawling (part II)
Crawling (Photo credit: Wikipedia)
This article is the follow up of the one about
wikidata crawling.
Wikipedia has specific
infobox templates.
This is the normalized way to enter specification inside wikipedia articles.
It provides templates with already defined fields.
For example the
planet template
has fields such as periapsis or …
Read More
Travis setup
One job in continuous integration pipeline (Photo credit: Wikipedia)
The goal is to setup a CI pipeline based on Travis
with external dependencies integrated to a Github repository
Travis basics
To enable Travis integration in Github, one must edit ./.travis.yml file.
I won't go into detail. The setup is …
Read More
Wikidata crawling
Graph database representation (Photo credit: Wikipedia)
I wish to have reliable data about vehicles. I decided to rely
on one large source, namely Wikipedia. I chose it because it is reviewable and
most of the time reviewed, and regularly updated and completed.
Wikipedia - Wikidata relationship
Wikidata items are made to …
Read More
Virtual Jupyter
Jupyter and a Python (almost) (Photo credit: Wikipedia)
Following the isolation of python environements
and given I use jupyter notebooks,
isolating jupyter kernels inside virtualenv is a logical step.
To do so, you must install a new kernel using the ipython you installed inside
your virtualenv:
- Create your virtualenv
- Install …
Read More
Sail ship maneuvers

Sail ship not tacking (Proto credit: Wikipedia)
Maneuvering a sailship is not straight forward, especially when against the wind.
This article is focused on sail position when turning for
full-rigged sailships.
The main sources are naval action videos.
Preambule
The sailship has 2 or 3 masts.
The fore-mast (the one …
Read More
loop devices
Loop devices are used to acces any file as if it were a block
device such as a disk. On
GNU/linux, the canonical command to interact with loop devices is
losetup . To list the next
usable loop device :
losetup -f
disk image loop mount …
Read More