Latest posts for tag cazzeggio
Monitoring a heart rate monitor
I bought myself a cheap wearable Bluetooth LE heart rate monitor in order to play with it, and this is a simple Python script to monitor it and plot data.
Bluetooth LE
I was surprised that these things seem decently interoperable.
You can use hcitool
to scan for devices:
hcitool lescan
You can then use gatttool
to connect to device and poke at them interactively
from a command line.
Bluetooth LE from Python
There is a nice library called Bleak which is also packaged in Debian. It's modern Python with asyncio and works beautifully!
Heart rate monitors
Things I learnt:
- The UUID for the heart rate interface starts with
00002a37
. - The UUID for checking battery status starts with
00002a19
. - A longer list of UUIDs is here.
- The layout of heart rate data packets and some Python code to parse them
- What are RR values
How about a proper fitness tracker?
I found OpenTracks, also on F-Droid, which seems nice
Why script it from a desktop computer?
The question is: why not?
A fitness tracker on a phone is useful, but there are lots of silly things one can do from one's computer that one can't do from a phone. A heart rate monitor is, after all, one more input device, and there are never enough input devices!
There are so many extremely important use cases that seem entirely unexplored:
- Log your heart rate with your git commits!
- Add your heart rate as a header in your emails!
- Correlate heart rate information with your work activity tracker to find out what tasks stress you the most!
- Sync ping intervals with your own heartbeat, so you get faster replies when you're more anxious!
- Configure workrave to block your keyboard if you get too excited, to improve the quality of your mailing list contributions!
- You can monitor the monitor script of the heart rate monitor that monitors you! Forget buffalo, be your monitor monitor monitor monitor monitor monitor monitor monitor...
Boring restaurants
While traveling around Germany, one notices that most towns have a Greek or Italian restaurant, and they all kind of have the same names. How bad is that lack of fantasy?
Let's play with https://overpass-turbo.eu/. Select a bounding box and run this query:
node
[cuisine=greek]
({{bbox}});
out;
Export the results as gpx and have some fun on the command line:
sed -nre 's/^name=([^<]+).*/\1/p' /tmp/greek.gpx \
| sed -re 's/ *(Grill|Restaurant|Tavern[ae]) *//g' \
| sort | uniq -c | sort -nr > /tmp/greek.txt
Likewise, with Italian restaurants, you can use cuisine=italian
and something like:
sed -nre 's/^name=([^<]+).*/\1/p' /tmp/italian.gpx \
| sed -re 's/ *(Restaurant|Ristorante|Pizzeria) *//g' \
| sort | uniq -c | sort -nr > /tmp/italian.txt
Here are the top 20 that came out for Greek:
162 Akropolis
91 Delphi
86 Poseidon
78 Olympia
78 Mykonos
78 Athen
76 Hellas
74 El Greco
71 Rhodos
57 Dionysos
53 Kreta
50 Syrtaki
49 Korfu
43 Santorini
43 Athos
40 Mythos
39 Zorbas
35 Artemis
33 Meteora
29 Der Grieche
Here are the top 20 that came out for Italian, with a sadly ubiquitous franchise as an outlier:
66 Vapiano
64 Bella Italia
59 L'Osteria
54 Roma
43 La Piazza
38 La Dolce Vita
38 Dolce Vita
35 Italia
32 Pinocchio
31 Toscana
30 Venezia
28 Milano
28 Mamma Mia
27 Bella Napoli
25 San Marco
24 Portofino
22 La Piazzetta
22 La Gondola
21 Da Vinci
21 Da Pino
One can play a game while traveling: being the first to spot a Greek or Italian restaurant earns more points the more unusual its name is. But beware of being too quick! If you try to claim points for one of the restaurant with the top-5 most common names, you will actually will actually lose points!
Have fun playing with other combinations of areas and cuisine: the Overpass API is pretty cool!
Update:
Rather than running xml through sed, one can export geojson, then parse it with the excellent jq:
jq -r '.features[].properties.name' italian.json \
| sed -re 's/ *(Restaurant|Ristorante|Pizzeria) *//g' \
| sort | uniq -c | sort -nr > /tmp/italian.txt
Opinion Sort
«Bullshit is unavoidable whenever circumstances require someone to talk without knowing what he is talking about. Thus the production of bullshit is stimulated whenever a person’s obligations or opportunities to speak about some topic are more excessive than his knowledge of the facts that are relevant to that topic.
This discrepancy is common in public life, where people are frequently impelled— whether by their own propensities or by the demands of others—to speak extensively about matters of which they are to some degree ignorant.
Closely related instances arise from the widespread conviction that it is the responsibility of a citizen in a democracy to have opinions about everything, or at least everything that pertains to the conduct of his country’s affairs.
The lack of any significant connection between a person’s opinions and his apprehension of reality will be even more severe, needless to say, for someone who believes it his responsibility, as a conscientious moral agent, to evaluate events and conditions in all parts of the world.»
Opinion Sort
In a world where it is more important to have a quick opinion than a thorough understanding, I propose this novel sorting algoritihm.
def opinion_sort(list: List[Any], post: Callable[List]):
"""
list: a list of elements to sort in place
post: a callable that requires a sorted list as input and does
proper error checking, as they should do
"""
if list[0] > list[1]:
swap(list[0], list[1])
while True:
try:
# Assert opinion: "It is a sorted list!"
post(list)
except NotSortedException as e:
# Someone disagrees, and they have a good point
swap(list[e.unsorted_idx_1], list[e.unsorted_idx_2])
else:
break
# The list is now sorted, and the callable has to agree
This algorithm is the most efficient sorting algorithm, because it can sort a list by only looking at the first two elements.
Fiori in primavera
Poesia: "Fiori in primavera"
Se vuoi portarmi dei fiori in primavera
Portami dei carciofi
Che ce li facciamo a fettine sottili
Saltati nell'aglio
E con gli scarti
Facciamo il risotto
Non importa che mi dai del voi
Dai, non importa che mi dai del voi
In che senso?
Eh, mi dici sempre "voi informatici", "voi tecnici", "voi..."
Spelling a chilometri zero
Lo spelling internazionale è troppo globalizzato, e volete recuperare un attimo la dimensione del posto dove siete nati e cresciuti?
Da oggi c'è questo script che fa per voi: gli dite dove abitate, e lui vi crea lo spelling a chilometri zero.
$ git clone git@gitorious.org:trespolo/osmspell.git
$ cd osmspell
$ ./osmspell "San Giorgio di Piano"
1: San Giorgio di Piano, BO, EMR, Italia
2: San Giorgio di Piano, Via Codronchi, San Giorgio di Piano, BO, EMR, Italia
3: San Giorgio Di Piano, Via Libertà, San Giorgio di Piano, BO, EMR, Italia
Choose one: 1
Center: 44.6465332, 11.3790398
A Argelato, Altedo
B Bentivoglio, Bologna, Boschi
C Cinquanta, Castagnolo Minore, Castel Maggiore, Cento
D Dosso
E Eremo di Tizzano
F Funo di Argelato, Finale Emilia, Ferrara, Fiesso
G Gherghenzano, Galliera, Gesso
I Il Cucco, Irnerio, Idice
L Località Fortuna, Lovoleto, Lippo
M Malacappa, Massumatico, Minerbio, Marano
N Navile
O Osteriola, Ozzano dell'Emilia, Oca
P Piombino, Padulle, Poggio Renatico, Piave
Q Quarto Inferiore, Quattrina
R Rubizzano, Renazzo, Riale
S San Giorgio di Piano, Saletto
T Torre Verde, Tintoria, Tombe
U Uccellino
V Venezzano Mascarino, Vigarano Mainarda, Veduro
X XII Morelli
Z Zenerigolo, Zola Predosa
I dati vengono da OSM, e lo script è un ottimo esempio di come usarne la API di geolocazione (veloci) e la API di query geografica (lenta).
Update: source code is now here.
Poesia: "Lavatrice"
Pensavo fosse pail,
invece ora è feltro.
Shops
Christmas songs should only ever be played on Christmas day.
In church.
At midnight.
Unless I happen to be there.
Airports
In the airport, we are not travellers. We are a captive audience with dwell time.
In other words, suckers stuck in a room where the only pastime provided is spending money and staring at advertisements selling advertisement space in rooms full of suckers like them.
Explanation of umarell
Umarell /uma'rɛl/ (oo-mah-rell), n; pl. Umarells. People in a community who offer all sorts of comments to those who are trying to get some work done, but who are not doing any work themselves.
Etymology and further details
Umarell is a word that entered Italian slang in Bologna and is spreading to nearby towns, occasionally even across Italy. It comes from the Bolognese for "cute/odd little man".
"Umarells" are those people, usually retired men, who spend time watching construction works, often holding their hands behind their back, occasionally commenting on what is going on, sometimes trying to tell the workers what to do.
It's easy to find examples on the internet; the word was popularised by a blog collecting photos, which has even been published into a book.
With some Italian Debian friends, we realised that umarell is the perfect word to describe those people in a community, who offer all sorts of comments to those who are trying to get some work done, but who are not doing any work themselves.
I think that it is a word that fits perfectly, and since I'm likely going to use it blissfully anywhere, here is a page that temporarily explains what it means until the Oxford English Dictionary picks it up.