Tumble Confused Device

.oOo.

What about Fortran for speed

As I was playing with fibonacci sequences to try different languages I decided to return to one of my first/oldest/smelliest languages: fortran.

I coded a recursive function like this:

program fibonacci
  implicit none
  integer :: fibo
  print *, "Fibonacci 44:", fibo(44)
end program

recursive integer function fibo(n) result(a)
  if (n<2) then
    a = n
  else 
    a = fibo(n-2)+fibo(n-1)
  end if
end function fibo

You can compare this to the C Version and think that these two will be similar.

Until when they are compiled. With no optimization their runnig times arem comparable, but when using -O2 the fortran version smokes the C version. 1.0s vs 1.9s in my MBAir. What? I expected them to be on parity but we are always surprised.

Other versions of fibo are on github.

Fibonnaci curiosity

while playing with code that generates Fibonacci sequences, I came about a curiosity. In the following code:

#include <stdio.h>

int fibonacci(int n)
{
  if (n < 2)
  {
    return n;
  }
  return fibonacci(n - 1) + fibonacci(n - 2);
}

int main()
{
  printf("Fibonacci 44 %d\n", fibonacci(44));
  return 0;
}

the recursion return adds the -1 and -2 Fibonacci elements. But you can swap the order of the summation and the result doesn’t change. What is interesting is that if you compile this and run both versions, this one is slightly faster (in my MB Air M2). So… there’s some magical caching behind the scenes.

Bash better echo

Using echo in bash scripts is normal, but I like to have timestamps in my outputs. Also, I usually like to print stuff starting with a # so everything is a comment if I accidentally copy and paste into another terminal. Don’t ask how I get to this preference.

my_log() {
    echo [$(date +%H:%M:%S)] "$@"
}

Usually this goes into a one-liner, and I drop the my at the head of the function name and maybe use printf instead of echo, but, you get the point.

This allows me to run something like:

my_log This stuff will break if andrew touchs this code

And have a nice timestamped log… :-)

Arduino Water and Light Sensors

Two circuit diagrams showing a water sensing device and a light sensor

Do not update to macOS 26

I’ve done it and it sucks. I’m not even going to talk about the “features”. Just the design of the liquid glass.

This design with round (to 150%) corners on everything, and transparency that looks a pastiche of bad taste, childish clay toys and a failure to be a grown up design.

Apple is at a lost. Even the download of the 16GB(what?) update was a nightmare for the poor engineering apple has these days. I’m on an ethernet connection with 1Gbps and it kept saying that i wasn’t connected to the internet and I should try again. Yes, apple keeps blaming its failures on the users side. And then… this awful design.

This is clearly the most hideous design system on an apple I’ve ever seen.

But I can only kick myself: Why did I upgrade? Why? It’s my fault. Maybe my 9 year old will like this computer. I’m going shopping.

Show bash script documentation trick

Bash scripts are the bread and butter when organizing computer stuff. After writing so many script I don’t remember everything I did. It is nice to have comments or some other way of knowing what it is that certain script does.

There are many solutions, but I tend to use comments (lines starting with #) and usually my bash scripts start something like this:

#!/usr/bin/env bash
#
# Converts markdown files to HTML presentations using pandoc
# 
# Example usage:
# 
#   md2html.sh name-of-file.md
#

head -8 "$0"

The above snippet ensures that the head of the file is always shown when the script is ran. The head -N "$0" line is where the magic happens. I just replace N with the number of lines that I want to show.

Whenever the script runs, the first thing it does is to display the header documenting the script. If you scripts require the passing of arguments then running the script without parameters will show the proper way to use the script.

Neat.

Finding Fibonacci in the Golden Ratio Recursion Calculation

#lang racket
;; Finding Fibonacci in the Golden Ratio Recursion Calculation
;;
;; Check the numbers in the fractions of the Values
(define (golden-ratio previous-value current-value tolerance)
  (let ([error (abs (- current-value previous-value))])
    (if (> error tolerance)
        (begin
         (printf "Error: ~v, \t Value:~v~n" error current-value)
         (golden-ratio current-value (+ 1 (/ 1 current-value)) tolerance))
        (printf "Error: ~v, \t Value:~v~n" error current-value))))

(golden-ratio 0 3/2 1e-5)

Run it at https://onecompiler.com/racket/43v2qa42g

microbit one liner temperature display

from microbit import *

while True:
    display.scroll(str(temperature())+".C", delay=200)

An alternative, using a Japonese Soroban inspired representation:

from microbit import *

def da(i,v):
    if i<0 or i > 4:
        return
    if v<0 or v>9:
        return
    if v>4:
        display.set_pixel(i, 0, 9)
        v = v % 5
    else:
        display.set_pixel(i, 0, 0)
    for p in range (5-v, 5):
        display.set_pixel(i, 5-p, 9)

def db(v):
    display.clear()
    if v < 0 or v > 99999 or type(v) != int:
        return
    for i in range(4,-1,-1):
        u = v % 10
        v = v // 10
        da(i,u)

while True:
    sleep(1000)
    db(temperature())

Better Serial Plotter in Arduino IDE 2

Arduino IDE 2 came with a very unusable Serial Plotter. The number of data points displayed in the horizontal axis is only 50 by default and this makes displaying fast datapoints disappointing.

A better solution is to increase the number of points.

in file Arduino\ IDE.app/Contents/Resources/app/lib/backend/resources/arduino-serial-plotter-webapp/static/js/main.35ae02cb.chunk.js

search for

U=Object(o.useState)(50)

and replace the value with a bigger buffer (500, 1000, INFINITE :-( ).

Dictionaries

Just to set a list of dictionaries to be used regularly.

English

Português

Tailwind or CSS?

Tailwind is the worst of all worlds. It is a regrettable step backwards that takes everything bad about CSS and modern web development and brings it all together in one library. – Colton Voege

After 2 years immersed in Tailwind my feelings toward it are mixed. As a Design System it is better than a Component System, but even so… I feel that some of these “systems” try to much. Maybe it is time to reflect about the use of these “libraries” when the HTML + CSS specs are getting so powerful.

I’m trying AI Warp agentic development enviroment

Every body is doing AI in many different ways, some use the chat form in a browser, some use VSCode Copilot, some the CLIs. I’ve been a fan of separation between my local machine and the AI stuff running in the cloud, but I decided to mix thing up.

Came across Warp and decided to give it a try. It has been just a couple of days in and I’m adapting. I see where this has agentic idea has potential applications and probably will end up using them in my workflows. I’ll be experimenting with Gemini-cli and others. The speed to achieve a viable product is tremendous and although I find myself tweaking and correcting minor things, my role becomes more of a code reviewer than of the full time programmer (that I’m not).

AI might give me more time to do other things and that is precious.

And if you’re not tired of reading about AI, here’s a list of stuff about it in this blog:

.oOo.