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.
Derive Proc macro step by step
Tokens stream in macro (photography) (Photo credit: wikipedia)
I recently try to write a proc_macro in rust but failed to find enough
example and I didn't have all the needed knowledge to fully understand
the examples I found.
The use case
Let's take a toy use case. Let's say we …
Read More
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
Mastermind solver in rust
(Not mastermind) code breaking machine (Photo credit: wikipedia)
I recently watch a video explaining how to solve mastermind.
I wanted to try it myself, so I coded it in rust.
Here are the code and the
playground.
Update: 2024 edition with more colors.
The game
I don't think this …
Read More
GNSS as an optimization problem
Satellite optimized (Photo credit: Wikipedia)
GNSS's basic functionality works as follow: Satellites sends their
position and their local time frequently.
The time is synchronized between satellites thanks to the most accurate
time keeping devices ever made (atomic clock).
Each GNSS constellation implements its own time (e.g. GPS time).
The …
Read More
Suicide burn
Rocket burn (Photo credit: Wikipedia)
Principle overview
The goal of the suicide burn (also called hoverslam)
is to land a rocket while minimal thrust is not low enough to hover .
Thus, the engine must be turned off at the point where the rocket land.
The challenge is then …
Read More
Differential thrust
Differential thrust (Photo credit: GE)
Principle overview
The basic principle is to create a torque offsetting the total thrust.
This offset is done by throttling thrust of multiple engines whose thrust
is not align with gravity center.
On the drawing, the thrust is aligned with CG for the left engine …
Read More
Approval voting
Children approving their teacher (Photo credit: Wikipedia)
This article is an update of the the previous one.
It adds the approval voting method and fix few errors.
Method explanation
Each voter can apprrove as many candidate as he wants.
It can be seen as a majority judgement with only two …
Read More
Alternative voting systems
(not Condorcet) duel (Photo credit: Wikipedia)
Many voting methods exists, and I want to explore results yields by some of
those.
For the argument stating one specific voting method is better than another
one, I let the reader see
this article from science étonnante (fr) ,
this video from la statitique …
Read More
Voting method reflections
Transparent voting box (Photo credit: Wikipedia)
This article presents personal thoughts on voting methods. More
specifically, it presents guarantees offer by the traditional
non-electronic voting method and won’t elaborate on electronic voting.
Specifications
First, let’s define few specifications I’d like to develop.
- any voter can understand how …
Read More