Wishful Coding

Didn't you ever wish your computer understood you?

Costa Rica

Day 0

My parents dropped me of at Dusseldorf two hours before departure. I had no checked baggage and checked in online. Security went really quick, so then I spent two hours waiting at the gate.

When it was my turn to board, they sent me to a different line. There I was told that my ESTA form was wrong. I had entered my ID number instead of document number where it asked for my passport number.

I had to fill in a new application, with the gate closing in 10 minutes. I ran to the nearest internet place, threw more than enough coins in it, and surfed tot he ESTA site. Everything seemed to take forever and I made a lot of mistakes, but I made it.

The flight was long and boring. I watched 1.8 movie, listened some music, and talked to my neighbor. Noah isn’t really going to kill his grandchildren, right?!!

Customs, security, more customs, more security. My documents where fine now. I must say I’m happy Atlanta was not my final destination, not my favourite dialect/culture.

Four hours later I was on my way to San Jose, in a smaller plane with less space and screens. I did sleep for a tiny bit, which was nice.

I had booked a dorm bed with Alajuela Packpackers for the night. After some waiting and talking to a guy in a beige shirt, a shuttle from the hotel picked me up.

At the hotel I learned two unfortunate things:

  • The large sum of Colon I got from the ATM was worth about $5
  • I lost my bag of fluids somewhere. No shampoo and toothpaste for me.

Day 1

I woke up 4 AM, and did not sleep after. At 8 AM I got a delicious breakfast on the roof of the hotel. That cheered me up a lot.

The barista also told me the location of the bus stop and a supermarket. Getting there was more challenging than expected though. I’m not used to risking my life to cross a street. Alajuela is like Manhattan without pedestrian crossings.

The supermarket was another challenge. I like to eat things like bread with cheese for lunch. The two things they did not sell where bread and cheese. I bought what looked most like it and ate it in a park.

I was really scared for the bus to Monteverde. From what I heard, I was expecting to stand for 5 hours without a toilet break while being robbed of all my stuff. In reality, the bus was half full of nice people and there was a break in between.

What I did not expect was that most of the way was over unpaved mountain roads. At one point we had to drive backwards because of an oncoming truck. It was very scenic. Bumpy roads, small settlements, green valleys, exotic plants.

When I arrived it was already dark. A taxi picked me up to bring me to the hostel. After two full days of traveling plus 8 hours time difference, I was at my destination.

Day 2

I still woke up 4 AM in the morning, but this time I slept a few more hours afterwards.

After eating a bread-free breakfast with my host family, we went to the nearest town for shopping. It was half an hour on foot. They do not own a car and do everything walking or with a taxi.

There was a farmers market, with fresh bananas and pineapples and vegetables I’ve never seen before. After visiting the supermarket (no bread), I started to worry how we would carry all this food home. I bought a local SIM card and shampoo from the tiny, tiny organic store. No toothpaste there.

We went home with a taxi.

Back at the hostel we ate some fruits, and later lunch with rice, potato, egg and some strange vegetable. Afterwards I got a pile of their broken devices to fix, because I know things about computers, right?

There was a phone more bricked than a brick, some netbooks with parts missing, burned, or misplaced, and some to old to run a recent Windows. I’m currently downloading Crunchbang at agonizing speed.

Day 3

There was a big moth in my room, buzzing against the window.

It’s Sunday, so I did not have to work, but I don’t know yet what I can do around here, and how to get around. So I decided to work, and have my free day some other time.

I installed Crunchbang in Spanish onto the working netbook and started looking into unlocking the SIM of a phone. Every time I had to download something, another 10 minutes passed by.

While downloading OpenOffice and Java, I helped out making a new room upstairs. The framework was already there, so it was just a matter of sawing planks to the right size and nailing them to the framework.

The house is almost entirely made of wood, and I learned that they built both the hostel and the house all by themselves. There where some construction workers in the beginning, but due to financial reasons they did the rest by themselves. I asked if it was hard to get a building permit, but it turns out you don’t need one. That explains the random chaos of building in the towns I guess.

Later, I saw Gudari with a broken RC tank modeled after the tank in Halo. I asked what he was doing. Nothing much, it was probably left by people living here before. (The hostel was their house and the house was rented out before) I offered to take it apart and try to fix it or use the parts for something else.

Fixing it seemed like the more boring option, and there where no batteries for the transmitter anyway. So we decided to try making robot using the Raspberry Pi I brought for him. This is slightly optimistic, as we lack a lot of parts and tools, but we started anyway.

We took it apart completely, yielding a PCB, some LEDs, some motors and a battery box. We just cut out pieces of plastic from the tank to keep the gearbox around the motors intact. We then attached cardboard wheels where the broken tracks had been, and glued everything to a piece of wood.

The end result of the day was that we could tape the wires of the motors to some batteries and have it drive around. If it will ever turn into a real robot depends if we can get tin, wires and transistors to hook it up to the Raspi.

Stores are not so great here when it comes to technology, electronics, organic food, or other things that are not food, clothing and souvenirs.

Day 4

The kids went to school, so it was a quiet and Spanish day. I removed the SIM lock from a phone, ate lunch and went to town.

I borrowed a bike because I thought it’d be easier, but the hills are so steep that I was out of breath after maybe one KM. The worst thing about being out of breath on the roadside is that half of the cars are trash with a trail of thick black smoke.

I had a small piece of paper with me with the names of the things I wanted to buy, and how to ask for them. This worked out okay, and I bought solder tin in Spanish. I could not find a lot of other things.

After recovering on the couch, the kids came back. We went to another store to buy a battery to test the transmitter. It did not transmit.

I studied the receiver for a while, and noticed that every motor was surrounded by a cluster of 6 transistors. I had a hunch that those transformed two binary signals from the chip to a bidirectional current. Some googling revealed that they are probably Tilden H-bridges.

I located the 2 wires from every motor that led to the chip, and fed them 3V from 2 of the 6 batteries. This started the motor! Next we cut the tracks to the chip, and hooked up wires to the Raspi GPIO pins.

This basically turns the receiver into a zombie motor controller for the Raspi. After some debugging we where able to control the motors using the Raspi!

The only problem is that it’s really fast. We wrote a program that drives 3 seconds, then turns 3 seconds in a loop. It went completely out of control.

Tomorrow we will look at using PWM to control the speed. I’ll also try to set up the Raspi with a WiFi dongle so we can command it remotely.

Day 5

I tried really hard not to finish the robot before Gudari came back from school, but I did repair the wheel and set up WiFi on the Raspi.

I spent the rest of the morning not doing ver much, helping with the new room upstairs, and checking out the suroundings.

When Gudari came back, we tried the PWM and creted some programs. Then we decided to make a bumper out of some paper and tinfoil. So now the robot can drive around and back away from obstacles.

Finally, I hacked together a Flask app to act as a remote control using a smartphone.

In the evening I practiced some Spanish.

Day 6

This morning Tarsicio told me I should take some more free time, I’m working too much. Problem is that I havn’t really figured out what to do with my time. I also like working here.

After brekfast I went to the nature reserve close by. It had really big trees, birds and butterflies. I also saw a squirl and some dog-sized animals that ran away before I could really see them.

After lunch I went to a waterfall and sat on a rock thinking and looking around. I returned home when it started to rain.

In the evening I played a game with Julia.

Day 7

In the morning I fixed the piano. The pedals where not working correctly. I printed Gymnopedie 1, which I practiced for a bit.

Afterwards worked on the new room until I started to lose focus and make mistakes. I’m really perfectionist, but the wood is not first class, neither are the tools. So it’s really hard to make everything fit exactly.

After lunch I made another trip to the village. I’m getting better at cycling in the mountains, but I was still exhausted when I got back. Without toothpaste.

Tarsicio previously told me he had an old Mac he wanted to fix. It’s an iMac G3, to which he forgot the password. I booted it in single user mode and added a new user. Then I looked for the pictures he said where on it, but did not find anything.

When I clicked “About this Mac”, I realized that this machine is slower than a Raspberry Pi. A 600Mhz G3 processor and 320MB RAM.

The internet does not work. Neither wired or wireless. I’m not sure if it’s a hardware or software problem. I tried installing various Linux distributions in various ways, but the G3 is so old and PPC so little used that it’s hard to find anything.

It was already dark, but not dinnertime yet. I played some more piano and did a moon mission in KSP. For dinner we had soup with popcorn.

Day 8

Today was the birthday of Gudari, so I decided to make a cake. I cycled to the supermarket to buy stuff.

The cream didn’t really work because it wasn’t cold. So I spent a bunch of time playing piano and KSP while I put the cream in the refridgerator.

After the cake was done I went to the Bat Jungle, run by a Flemish guy. He spent a bunch of time busting myths about bats, and raising awareness about their importance to the ecosystem.

Basically they are closer related to primates than birds or mice. They are intelligent and social. Half of them eat insects, the other half eat fruit. A few kinds live from blood, but… not from humans and they don’t carry diseases.

In Costa Rica there are more bats than birds, but you don’t see them during daytime. They are super important for polination of many tropical fruits. But they are endangered by deforestation and green energy(!).

I was surprised to learn that if you disturb a bat during daytime or winter(hibernation), it basically dies. As soon as it starts to fly it uses so much energy it needs to eat insects constantly. But without its usual prey, it just starves.

Then he fed them, and we could see them fly around and eat fruit. He showed the different kinds. There where hummingbats that could hover like a hummingbird.

Afterwards I cycled to town to buy a chicken for dinner. Some of Gudari’s friends came over, we ate cake and played Minecraft.

Future

To be continued…

Pepijn de Vos

My girlfriend in Rust

Some people don’t like to say “my girlfriend”. They think it implies ownership over the person. Lets explore that using Rust. Swap genders at will.

struct Human {
    name: str
    // ???
}

Even though Rust is not object oriented, I’m sorry for objectifying Alice here.

let bobs_girlfriend = Human { name: "Alice", /* ??? */ };

This is what some people think when they hear “my girlfriend”, Bob owns Alice in this cenario.

let charlies_friend = &bobs_girlfriend;

Charlie can only borrow Alice, Bob maintains ownership of Alice, the compiler enforces monogamy.

That is not how it works, lets try again.

use std::rc::Rc;
use std::option;

let alice = Rc::new(Human { name: "Alice", /* ??? */ });

The name “Alice” refers to Alice, who is now owned by the reference counter. In this digital world it’s like a god, it decides who lives and dies.

let mut bobs_girlfriend = Some(alice.clone());

“Bobs girlfriend” is a reference to Alice, no more or less than the name “Alice”. Bob owns the reference, but not Alice.

assert!(*alice == *(bobs_girlfriend.unwrap()));

“Alice” and “Bobs girlfriend” are the same thing, though the latter is mutable and optional.

assert!(*(bobs_girlfriend.unwrap()).beautiful == true);

This throws a compiler error; Beauty is in the eye of the beholder.

let mut charlies_girlfriend = Some(alice.clone()); // Polygamy

Charlie does not own Alice either.

charlies_girlfriend = None
bobs_girlfriend = None

If you are forgotten, do you cease to exist? Better not find out. Love the ones dear to you. You’ll never know when they will be garbage collected.

Pepijn de Vos

Raspberry Pi as my primary computer

my work

It occurred to me that most of the work I do on my shiny dual core i7 ultrabook is using VIM, Python, ssh, and other command-line tools. So why do I need a fast CPU and fancy graphics?

When the Raspberry Pi B+ was released, I knew I had to try this. I ordered one, installed Raspbian and all the stuff I needed, and took it to work.

my desk

I hooked up an external monitor, keyboard, and mouse. Then I sneaked a LAN cable into the WiFi hotspot and set to work.

I decided to forgo X entirely. As I mentioned, I use mostly terminal applications, and alternatives for the few GUI apps I use are readily available.

After a week, I can say it worked surprisingly well. I could pretty much do my job as usual. Most applications never used much CPU or memory. And even while compiling Python 3.4 from source, my terminal stayed snappy.

The only mayor problem is browsing the web. Elinks is pretty good, and most things that do not use JS are usable, but it’s not ideal. At times I had to startx and fire up Midori. It’s so much slower and resource hungry than elinks though.

On the upside, RFC’s look pretty much unchanged. Still dry and boring.

The one application that makes this work is tmux. Without tmux there is no way this would ever work. Tmux is my tiling window manager. Everything I do, I do it in tmux.

The best part is that you can startx, open a terminal, run tmux attach and continue working alongside the sluggish GUI apps. You could even walk over to a colleague, ssh to your machine and work there.

I use fbterm as my terminal emulator. This allows you to use your favourite monospaced font in a framebuffer. I use Zsh for my shell. I can highly recommend the .zshrc from grml.

I recommend that you enable overclocking and adjust the memory split to 16MB to give you all the resources you can get. However, this is mostly for web browsing, on the console you don’t notice the difference.

During the weekend before the experiment, I had a lot of fun setting up all the tools I need and more.

I set up alpine for email and weechat for IRC, but also youtube-dl and mplayer for playing videos in a framebuffer.

I did experiment with netsurf. A graphical browser in a framebuffer. The problem is that there is still no JS, and there is no way to quit it. So for times that elinks is not enough, you really want proper webkit.

In the case you want to try this, here are some essential keyboard shortcuts I learned in te past few days.

Tmux commands are all prefixed with ctrl+b. Put set -g mode-keys vi in ~/.tmux.conf for copying to work.

c   new pane
p   previous pane
n   next pane
0-9 go to pane
%   split vertically
o   other split pane
[   start selection/scroll mode
        space start selection
        enter copy selection
        v     toggle block selection
        q     exit mode
]   paste selection

VIM commands for working with tabs

:tabedit {file} open file in new tab
gt              go to next tab
gT              go to previous tab
{i}gt           go to tab in position i

Elinks also has tabs. I created a little alias to launch google results from the terminal directly.

t create tab
c close tab
> next tab
< previous tab
g go to url
G edit url

Weechat is mostly controlled by IRC commands I used anyway such as /join and /quit. To switch buffers you press alt+0-9. It really helps to install the buffers.pl script so you can see a numbered list of them.

If you startx use, ctrl+alt+F1-F7 to change TTY.

Pepijn de Vos