May 13, 2018

Using foam to reduce 3d printer noise

I reduced the amount of noise the printer transfers to the table, as the table was acting as a loud speaker amplifying all noises. The result was very good with noticeable improvement and with the printer sounding smoother, as if I've had lubricated it.

One problem of using foam is that the printer bends to the heavier side requiring an extra conic piece of foam, as you can see on the right.

Feb 26, 2018

Composite material stress test: PET-G + Polyurethane foam

I found people doing lightweight and strong structures with very thin walls filled with expanding foam. See this post. I'm using a cylinder printed in black PETG with 0.4mm walls printed at 245C, 80mm of external diameter, 60mm internal diameter and 50mm height. The volume between the cylinders is approximately 93 ml, and each piece weights 14g~15g before adding foam.

0% infill with simple 0.4mm walls

Each piece weights between 14g and 15g before adding the foam.

The references I found online are for using professional polyurethane expanding foam made by combining two liquids. These are great for many reasons, one being that you can calculate the amount of foam to fill your pieces. I wanted to try polyurethane expanding foam found on the supermarket.

I highly recommend using protection glasses and gloves. These are cheap and can be of great help when handling the messiness of these foams. Latex gloves are not a good choice as the cleaner dissolves the latex. I also suggest you to get a product to clean the mess. I got a spray from Coltogum for cleaning the gun after use, and it is great to clean the mess and the plastic pipe.

Single component budget foam from Coop: 500ml makes 28L of foam, it expands 56 times

This single component foam require the parts to be wet before applying the foam or it won't expand properly. I tried it dry and it failed. The good is that you don't need to use all the foam at once, so you can store the can for a while and for a few uses. The bad is that the density is very low, making it light but not very strong. The two foams I got from the supermarket are on the extremes of expansion: I got the one with more expansion and the one with the least, and there were many in between.

Two components expensive foam from Coltogum: 400ml makes 10L of foam, it expands 25 times

The two component foam has a switch on the bottom that activates the foam and makes the can warm. It is clearly a great product, but after turning the switch you have only about 5 minutes to use it. 6 and a half minutes later and the can is hot and dead, no more foam will come out. So from the 10 L of foam I could have made I used less than 200ml in 2 of my pieces. Another reason the two liquid version is great: reduced waste.

I used the beer cans to make ~0.5kg of pressure on each piece. The holes I used for applying the foam are on the bottom. You can see foam leaking trough tiny little holes. White foam is low density, green is high density.

I used too much low density foam and high pressure deformed the interior of the cylinder.

Weight after applying the foam, and removing the excess:
  • Low density white foam: 19g with 4g~5g of foam. Foam density: ~52.68 kg/m3
  • High density green foam: 21g with 6g of foam. Foam density: ~225.80 kg/m3
These approximate and imprecise densities probably differ from the specs because the expansion was in a closed environment with some pressure applied to keep the foam from expanding freely. For comparison the densities of PETG and PLA are around 1250 kg/m3.

Without the foam, my finger wins(two layers of the wall separate) after ~2kg of pressure.

With the low density foam the wall still bend, but I can apply more than the double of pressure

And finally with the high density foam, the limit was my kitchen scale that goes only up to 5kg. Almost no bending.

Both the budget single component and the expensive two components foam did increase the strength of the pieces, with results probably mapping to the differences in density.

Another test was to compare with low fill densities:
  • 15% fill density using "3D Honneycomb" from Slic3r: 37g
  • 5% fill density using "3D Honneycomb" from Slic3r: 24g
With the 15% fill density the piece is unbreakable, even when I try with both hands. Problem is that the piece is very heavy, and not suitable for flying applications which is what I'm looking for. With the 5% infill the wight is not bad, however the skin becomes rigid and my finger won at ~ 3.1kg. One important difference is that when the 5% fill density piece failed, the affected area was small and the fracture on the skin had approximately 2.5cm instead of approximately 5cm on the piece with the 0% fill density and no foam.

3D Honneycomb with 5% filling density. Interesting result. Needs more testing.

I'll order some professional 2 components polyurethane foam to add to the comparison, and I'll try mixing very low fill densities with foam to see if I can get better results. Later I'll share my charts, and maybe I'll make a video with the stress tests.

If you have questions or comments, please leave them on the post.

Jul 8, 2017

Techsolo TN-100 Gigabit Express Card Performance on Linux

This devices are detected on Linux and work out of the box, but are slow and get very hot. Maximum performance is just a little bit more than 500 Mbps which is very poor. My guess is that the poor performance is caused by the PCI and not PCIe chipset: VIA Velocity VT6122

So if you have a choice, keep away from these devices.

Jan 24, 2017

My router runs Fedora - Part 1

My principle of 2017

For me 2017 is going to be the first year of the dog food. Eating your own dog food, or simply dogfooding, is reference to a scenario in which one uses its own creation to test and promote it. Until 2016 I was way too focused of being user of state-of-the-art, and I missed many interesting adventures. Let me go and catch up with how things really works.

Why start with my router?

I love OpenWRT, I really do. But you know what I miss there? systemd...

My job transformed my negative feelings about systemd into some love. I would do anything to be far away from systemd an year ago, but now I like it. systemd had the chance to start again, and leaving 40 years of bash hacks in the past is... awesome!

For a long time I was using a $ 20 router. This was the device in which I learned how to use and love OpenWRT. The only limitation of this cheap router is the 100 Mbps Ethernet ports which is a problem for the 200 Mbps I get from my ISP. The natural choice for an upgrade would be one of Linksys' WRT routers and I went for the top of the line, the Linksys WRT3200ACM.

Figure 1: Linksys WRT3200ACM with it's awesome two wifi radios

Wifi speed is pretty good, and I could finally use my ISP full speed, but... The stock interface is ok, but it doesn't support VPN for having isolated networks. It is easy to update to a new firmware, however at the time I had my router the wifi drivers and firmware were not available for OpenWRT(I didn't quite like dd-wrt). So I was stuck with an awesome WRT-friendly hardware that was not supported yet. Argh! Sent it back to the store and got my money back.

Well, what you do when you can't solve a problem with embedded? You go for x86, right? I went for a ZOTAC ZBOX CI323 NANO(+ 8GB of RAM and SSD) which is one of the cheapest barebones I could find.

Figure 2: ZOTAC ZBOX CI323 NANO with 2 Ethernet and wifi

The case isn't as attractive as the previous one, but guess what? It has all I needed, even more. It has good built quality, and four x86 cores. I added 8GB of RAM, and more SSD space I could probably use. From the networking perspective it has two gigabit ports and wifi. What is the natural choice when you are moving from OpenWRT? Fedora of course! So I installed latest Fedora 25 Server.

The network

I can't say my home network is simple, but it is definitively not big. All home specific stuff like phones, tv, printer, and wife's computer are on wifi, while the stuff related to my work is on the wired network. The wired network doesn't have loads of devices, as I only have only two 5-port Netgear Prosafe GS105E-200PES switches. Besides that my router has one port directly connected to the cable modem, and I have two cross-over connections between two test servers(10Gbps for pretty cool stuff, but this is another story). Total of 11 Ethernet cables. Here's how it looks like:

Figure 3: Peter's home network

I use the rectangles on the right to represent the internal logic of the router that has two ethernet interfaces enp2s0 and enp3s0 and wireless wlp4s0. I made the drawing in a way that the router is between the Internet (enp2s0) and my private network(enp3s0 and wlp4s0). Then I add some interesting words on top of the interfaces like macvlan, vlan, and bridge. I'll explain in details these in Part-2.

The left side show how I connect the ethernet cables. The red and green solid lines represent my VLANs. The red dotted line show access permissions between networks. The blue dotted lines show how I use my two external IP addresses.

Why 2 VLANs Peter?

Basically for isolation. I want to be able to have multiple dhcp servers if I need to, and I want the freedom to do interesting things on my work network without interfering with the home network. I measure the success of my setup by the number of times wife comes with "You are messing with the Internet again, aren't you?". At the time of writing, I'm clean for more than 30 days. But on first week of my router adventures I was getting in average 3 complaints per day.

I also don't like guests having access to my embedded devices. So no access to my VLANs from wifi.

Yeah, right but why 2? I use one for my workstation and for the embedded devices, and recently I added a second one for a test lab.

Part 2, how to turn Fedora into a router?

On Part 2 I'll describe in details how to configure Fedora as a router. There a thousand details, but it is fun. Some keywords for Part 2: hostapd, 4addr, bridge, vlan, macvlan, firewall-cmd, systemd-networkd, routing tables, masquerade

Sep 11, 2016

Swiss driving license exchange

For exchanging my Brazilian driving license for the Swiss one I needed to do a street test. The entire process is straightforward and efficient(The driving license arrived 48 hours after I passed the exam). There are many pointers of how the process works, so I'm not covering that in details. I think the only relevant detail is the canton: Zug.

I have 15 years and 500.000+ km of driving experience, and I consider myself a very, very good driver. My "auto"-esteem is not related to agressive driving skills, but my focus on safety, understanding of the car, environmental awareness, and traffic flow. Just as an silly example, when I get a new car, I adjust the mirrors and do some experimenting to "see" in practice where the blind spots are on that car before I feel comfortable with the mirrors. I'm also on a lazy path to become an airline pilot, so I'm the guy really interested in the rules and what motivated them.

I got my Swiss driving license on the first attempt and I passed with a rigorous examiner. I didn't consider that a great deal due my "auto"-esteem, but many Swiss friends congratulated me, and some told me cases of people failing repeatedly. Failing the test is expected.

My examiner's choice was a path that crossed _all_ kinds of roads, that went from 120km/h multi-lane highway to a 1,5 lane wide two-way road between pretty small villages. In 30 minutes of driving, the speed limit changed at least 20 times, which requires loads of attention, but is not exactly complex. I did ok on that.

My main problem was the lack of familiarity with the car. I spent like 3 hours driving it, including the time spent on the exam. That considerably reduced the speed in which I would feel comfortable driving. And that was a problem for the examiner. Here in Switzerland, if the speed limit is 50km/h, and there are no impediments like traffic or children playing around, you should drive at that speed. So he was not happy with me driving under the speed limit, but that was acceptable as I was telling him about the current speed limit and from where I took the speed limit information from.

But the real issue, the issue that almost costed me my license was environmental awareness, and this is what I really want to share. The fact that I'm aware of the environment, that I know where the blind spots are, don't mean a lot for the examiner. His main interest was in my ability to achieve environmental awareness in the Swiss way, which basically involves using less the mirrors, and more the neck. In at least two moments, he felt so uncomfortable with me turning right without turning neck, that he looked to check there was really nothing there.

So if you are exchanging your driver license to the Swiss one, I recommend you getting lessons from a professional instructor, and to get enough lessons. I did only 3 lessons, and that was not enough from the perspective of my examiner. I guess that getting 5-15 lessons may put you in a more comfortable position on the exam.

But the main advise I can give you is to not focus only on signs and traffic rules. You may be expected to behave in certain ways, even when there are multiple perfectly fine ways of achieving same goals. Learn and practices signs, traffic rules, but don't forget that the examiner will be looking for a Swiss driver when examining you, so go practice how to be that Swiss driver. One tip is to get a ride on the passenger seat with your instructor to get a feel of how she drives in places where you struggle. Do that after taking a few lessons.

And for more that I consider "my" way to be safe simply because it allows me to achieve environmental awareness without depending on slow neck movements, I really like the traffic here, so let me use more the neck and less the mirrors.

Nov 3, 2015


I was a customer from November 2008 to November 2015. When I joined, they offered great service for the price, but the price is not interesting for at least two years now. Besides some minor technical issues, the company lost a lot when it was sold, maybe more than once. In 2008 there was a good feeling that they cared about me, and that they were always innovating. This has gone for a long time.

I've been avoiding to move to another provider because I was expecting a lot of pain. I don't have anything complex: 7 domains, and about 400 MB of static content. How to choose my next registrar and hosting provider?

Gandi SAS is a sponsor of the Kernel Recipes, a Linux kernel conference that happens every year in Paris. But, besides sponsoring the event, they go to the conference, which offers me the chance to meet people who works for Gandi, and I met them many times there.

About prices, was asking me € 157.54 ($ 172.66) to renew my hosting plan for one year. Gandi charged me € 57,60 for an equivalent plan. Saving € 100 is a nice way of starting the week. However I wasn't expecting to have to pay a to transfer the registrar of my domains to Gandi. The transfer added € 84.84 to the bill, with an average price of € 12.12 / domain. The good news is that the transfer adds one year to the period the domain is already registered which makes it a good deal as I would neet to pay € 13.68 ($ 14.99) per domain per year. So financially I saved € 15.16 immediately and an extra € 95.76 on the first year as my domains are renewed for one extra year.

Also Gandi registrar can handle all kind of top level domains(More than 500 now) while could not even register a .org when I needed one in 2012.

Comparing the interfaces, offers an icon based interface with one button for each action, while Gandi has a more efficient interface that allows you to do the same tasks in less steps.

It took me around 4 hours to have everything up and running at Gandi. Registrar and hosting problem solved until at least 2022.

Gandi efficient interface icon based interface

Mar 3, 2015

Making steam work with Ubuntu 14.04.2 with Kernel 3.16

I have Ubuntu 14.04 LTS for playing Steam. Steam stopped working after upgrading to the 3.16 Kernel with newer X. I've upgraded Ubuntu following:

To make Steam work again, I just:

$ sudo apt-get install --install-recommends
libgl1-mesa-glx-lts-utopic:i386 libegl1-mesa-drivers-lts-utopic:i386

And then rebooted.

Jun 8, 2014

Omron HBF-701 English Manual

I'm learning how my body works in terms of fat and muscle levels. My main tool is a body composition monitor from Omron. I just bought a version that is made for the Japanese market, with no manual available in English. I'm making one, and I'll be glad if you help me. You can fill issues on Github or send me pull requests.

The manual:

Github page:

HBF-701 at Amazon:

Oct 28, 2013

Fedora: Booting Fedora LIVE to RAM

Fedora live images do not include the "Boot to RAM" option any more. This is not a big problem as the scripts needed to boot to RAM are still there.

You just need to add as boot option.

To do that, highlight "Start Fedora Live" using the keyboard keys and press TAB to edit boot command line. Add and press Enter.

Press TAB to edit boot command line



Oct 20, 2013

Fedora: Creating Arch Linux chroot with ssh server

I made a fork of a clone detection tool named CCFinderX. Two days ago I got a message from an user telling that the compilation was not working on Arch Linux. As some Kernel developers, such as Greg KH, has mentioned Arch Linux as being nice, I decided to try it.

I prefer chroots over virtual machines due higher performance, and due the fact that I do not need insulation between my chroots. As for Debian, Fedora provides all tools needed to create chroots for Arch Linux. This is "very" nice, as one can setup the Arch Linux chroot in just a few minutes.

The steps will cover installing Arch Linux tools on Fedora, creating the Arch Linux chroot, and configuring it with a new user and ssh server.

Some data:
Target directory for the chroot: /opt/arch
Package groups to be installed: base base-devel (More groups available here)
User: peter
ssh server port of the chroot: 2227

Note that the text refers to "[fedora] $" and "[arch] $", but this strings will not show up. If you want it is possible to configure bash prompt for showing different strings. Here is guide on how to do it.

Installing Fedora packages:
[fedora] $ sudo yum install arch-install-scripts gpg

Setting up Arch Linux Keys:
[fedora] $ sudo pacman-key --init
[fedora] $ sudo pacman-key --populate archlinux
Create the target directory:
[fedora] $ sudo mkdir /opt/arch

Creating the Arch Linux chroot:
[fedora] $ sudo pacstrap -d -i /opt/arch base

Prepare chroot directory (Hint: Save this to a script, or check my start/stop chroot scripts). Note that lines with -o bind mount the host directory inside the chroot. So if you delete something there, it will affect the host:
[fedora] $ sudo mount /tmp /opt/arch/tmp -o bind
[fedora] $ sudo mount /lib/modules /opt/arch/lib/modules -o bind
[fedora] $ sudo mount proc /opt/arch/proc -t proc -o nosuid,noexec,nodev
[fedora] $ sudo mount sysfs /opt/arch/sys -t sysfs -o nosuid,noexec,nodev
[fedora] $ sudo mount devtmpfs /opt/arch/dev -t devtmpfs -o mode=0755,nosuid
[fedora] $ sudo mount devpts /opt/arch/dev/pts -t devpts -o gid=5,mode=620
[fedora] $ sudo cp -a /etc/resolv.conf /opt/arch/etc/resolv.conf

Entering the chroot:
[fedora] $ sudo chroot /opt/arch su -
[arch] #

Changing root password:
[arch] # passwd

Adding a new user:
[arch] # useradd -m -g users -G wheel,storage,power -s /bin/bash peter
[arch] # passwd peter

Installing base-devel group:
[arch] # pacman -Sy base-devel

Installing openssh tools, configure server port:
[arch] # pacman -Sy openssh
[arch] # vi /etc/ssh/sshd_config
[arch] # cat /etc/ssh/sshd_config |grep 2227
Port 2227

Create ssh keys:
[arch] # /usr/bin/ssh-keygen -A

Start ssh server:
[arch] # /usr/bin/sshd -f /etc/ssh/sshd_config

Exit chroot
[arch] # exit
[fedora] $

ssh to chroot:
[fedora] $ ssh localhost -p 2227
[arch] $

Nice resources:
 - How to install Arch Linux, while keeping it simple
 - Arch Linux Website
 - My start/stop chroot scripts

Aug 17, 2013

Script to add custom display resolution on Linux / X / Gnome

Toshiba R830-10P is a nice notebook as it lightweight, and very powerful, but the Graphics are poor. The integrated LCD has miserable resolution of 1366 x 768, and as it uses Intel HD Graphics 3000 it do not officially support high resolution displays such as 2560 x 1440.

See the problems I've faced to use high-res monitor here.

I made a script to help people with similar problem. If you have a monitor that is not officially supported by your video card, you can try this approach. You need to tune the Hz parameter to find one value that is supported by the hardware, that is comfortable and stable. For comfort the higher the Hz the best.

Please note that there is no warranty that this script works for you, and there is no warranty that this script is safe for your hardware. I'm quite sure that playing with Modelines can burn some old CRT monitors. I've never heard that you can burn LCD / LED monitors, but I'm not sure.

The script is available at:

Jul 24, 2013

New monitor and old notebook

When I arrived at the office today there was a new monitor on my desk. Acer PB278Q 27” 16:9 2560 x 1440 WQHD LED-backlit Monitor. It is very nice monitor.

My notebook uses the second generation Core i7 processor i7-2620M. The embedded Intel HD Graphics 3000 officially has as maximum resolution 1900x1200 for 60 Hz refresh rate.

If using lower refresh rate, it is possible to use higher resolution. One good source of information is the page:

I was not able to use more than 40 Hz as refresh rate when they say 55 Hz worked with Intel HD Graphics 3000. I can set modes up to 44 Hz but then the image is not stable and goes black for one second some times.

What I did:

$ gtf 2560 1440 40

  # 2560x1440 @ 40.00 Hz (GTF) hsync: 58.92 kHz; pclk: 200.80 MHz
  Modeline "2560x1440_40.00"  200.80  2560 2712 2984 3408  1440 1441 1444 1473  -HSync +Vsync


$ xrandr --newmode "2560x1440_40.00"  200.80  2560 2712 2984 3408  1440 1441 1444 1473  -HSync +Vsync

$ xrandr --addmode HDMI3 "2560x1440_40.00"

$ xrandr --output HDMI3 --mode "2560x1440_40.00"

But I would like to increase the refresh rate. Do you have the 55Hz ModeLine for Acer PB278Q?

Also, how can I tell Gnome display settings about the new resolution? See my question here.

See how cool it is! :-)

Jul 23, 2013

CCFinderX, the new CCFinder

Finding code clones is far from trivial. For a nice explanation about the challenges of finding clones in source code, I suggest reading: "Comparison and evaluation of code clone detection techniques and tools: a qualitative approach". You can start by reading sections 2 and 6.

There are at least two tools with source code available under permissive free software licenses. Deckard and CCFinderX. CCFinderX is an evolution of CCFinder, made by the same author.

Deckard is easy to build and test, however CCFinder was not. For Linux users, I made a fork from gpoo/ccfinderx, and made some changes to simplify the build on Linux. The main change is to separate the core from the GUI. I have now two repositories:


Both are clones from gpoo/ccfinderx, but I've spited things. At the moment the GUI do not work but you can build CCFinderX-core without wired OpenJDK dependencies. And it works producing textual output. My goal with this repositories is provide source code that can be compiled, packed, and distributed.

Jun 14, 2013

Creating 32 bits chroot on 64 bits system

I use Fedora 64 bits on my workstation but I need 32 bits chroot of Debian. It is easy to do.

Create the chroot following the instructions from:

The first difference is that you need to add --arch=i386 to the debootstrap command.

Then for entering the chroot add linux32 as the first argument after sudo. Something like:

$ sudo linux32 chroot debian-wheezy

After that even uname -a will show 32 bits instead of 64. The linux32 tool is on the util-linux Fedora package.

Mar 27, 2013

Fedora: Creating Debian chroot with ssh server

I use Fedora on the Desktop but I need to do some development on Debian. chroots gives you no performance overhead, while virtual machines gives you CPU and memory insulation. Also the chroot is only a directory on my development tree.

I'm using Fedora 17 on my workstation and Debian 7 inside the chroot. The debootstrap command will save the files on the directory debian7-chroot/ under the current directory.

1 - Install debootstrap and dpkg on Fedora:
Fedora # yum install debootstrap dpkg

2 - Create the basic Debian:
Fedora # debootstrap wheezy debian7-chroot/

3 - Enter your new Debian:
Fedora # chroot /path/to/destdir

4 - Install additional useful packages:
debian-chroot: # apt-get install locales less vim openssh-server sudo aptitude

5 - Configure openssh server to start server on port 2222:
debian-chroot: # vi /etc/ssh/sshd_config

Port 22

Port 2222

6 - Change root password
debian-chroot: # passwd

7 - Return to your desktop distro:
debian-chroot: # exit

8 - Create start and stop script for your chrooted Debian:
Fedora # cat

umount debian7-chroot/tmp debian7-chroot/proc debian7-chroot/sys debian7-chroot/dev/pts debian7-chroot/dev
umount debian7-chroot/tmp debian7-chroot/proc debian7-chroot/sys debian7-chroot/dev/pts debian7-chroot/dev

mount /tmp debian7-chroot/tmp -o bind
mount proc debian7-chroot/proc -t proc -o nosuid,noexec,nodev
mount sysfs debian7-chroot/sys -t sysfs -o nosuid,noexec,nodev
mount devtmpfs debian7-chroot/dev -t devtmpfs -o mode=0755,nosuid
mount devpts debian7-chroot/dev/pts -t devpts -o gid=5,mode=620

chroot debian7-chroot /etc/init.d/ssh stop
chroot debian7-chroot /etc/init.d/ssh start

Fedora # cat

chroot debian7-chroot /etc/init.d/ssh stop

umount debian7-chroot/tmp debian7-chroot/proc debian7-chroot/sys debian7-chroot/dev/pts debian7-chroot/dev
umount debian7-chroot/tmp debian7-chroot/proc debian7-chroot/sys debian7-chroot/dev/pts debian7-chroot/dev

9 - Start the ssh server inside the Debian chroot:
Fedora # ./

10 - Connect over ssh to Debian chroot:
Fedora # ssh root@localhost -p 2200

Jan 17, 2013

Toshiba R830 and 16GB of RAM

The datasheet of Toshiba R830-10P mentions that the maximum memory capacity is 8GB. See it here.

But Intel says that the i7-2620M supports up to 16GB of RAM. See it here.

I have asked for help on Toshiba Forums. Nothing useful from there. See it here.

I was curious as I have a very particular need for 16GB of RAM. Today I decided to give it a try. I bought two Patriot PSD38G13332S (8GB PC3 - 10600 1333MHz CL9 SoDimm) and installed it on the notebook. It just worked.

Bios screen showing 16384 MB of RAM.

Memtest86+ and some info about performance.

So if you have the need for 16GB of RAM and a similar notebook from Toshiba, you can install 16GB of RAM.

Dec 9, 2012

Coccinellery is a gallery of semantic patches made to inspire users of Coccinelle. Currently the semantic patches comes from patches we have submitted to the Linux Kernel. We are working on improving Coccinellery and your suggestions and contributions are welcome.

"Coccinelle is a program matching and transformation engine which provides the language SmPL (Semantic Patch Language) for specifying desired matches and transformations in C code. Coccinelle was initially targeted towards performing collateral evolutions in Linux. Such evolutions comprise the changes that are needed in client code in response to evolutions in library APIs, and may include modifications such as renaming a function, adding a function argument whose value is somehow context-dependent, and reorganizing a data structure. Beyond collateral evolutions, Coccinelle is successfully used (by us and others) for finding and fixing bugs in systems code."

Nov 4, 2012

Do you want to become a pilot? Read me first.

Fly by wire is a book written by William Langewiesche that has, as a central history, the successful landing of Airbus A320 on the Hudson river on January 15 2009.

But this is only the central history of the book. The author has a very funny way of writing, and shares details about many people involved, like bird strikes specialists, air traffic controllers, Airbus engineers and test pilots. There is a very interesting analysis about impact of Airbus fly by wire system and how turbulent, and boring, can be the career of commercial pilots.

If you are considering becoming a pilot, read this book first. It can direct you to the right kind of pilot, or convince you that there are better ways of living.

Sep 23, 2012

Free Mobile Wifi: FreeWifi_secure on Android

I'm on France and decided to give Free Mobile a try. They offer good pack of service for € 20 / month.


One important feature for me is having Internet at home, and the "Accès FreeWiFi illimité", or unlimited access to FreeWifi was what I was expecting to use at home.

The problem is that I bought my cell phone in Brazil and it was not working with FreeWifi. This is related to how the connection works. See the links:

But you may not need to do anything by hand on your phone. Just try FreeWifiConfig app:

It will automatically configure your phone for connecting on FreeWifi_secure.

1 - Requires Free Mobile GSM chip
2 - May not work with all phones

Sep 13, 2012

Winter of the World is on my Kindle!

Today Amazon sent the Winter of the World by Ken Follett to my Kindle! I think I'll not sleep for some nights. :-D

Aug 5, 2012

Benchmark: SanDisk Cruzer Blade USB Flash Drive 16GB

Both Kingston and SanDisk 16GB pendrive has the same price range. I was curious for comparing them. The overall performance is poor, but is a bit better than Kingston DT101.

Write performance: 4.2 MB/s
ReWrite performance: 3.5 MB/s
Read performance: 24.5 MB/s
Random Seeks: 657.4 / sec

Comparing to Samsung S2 Portable 500GB USB 2.0 External HD:
8.2 times slower for write
4.9 times slower for rewrite
1.8 times slower for reading
5.3 times more seeks / sec

Full performance output:

[root@ace ~]# bonnie++ -n 0 -u 0 -r 7000 -f -b -d /mnt
Using uid:0, gid:0.
Writing intelligently...done
Reading intelligently...done
start 'em...done...done...done...done...done...
Version 1.96 ------Sequential Output------ --Sequential Input- --Random-
Concurrency 1 -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP /sec %CP
ace.home 14G 4265 0      3576 0                            24593 3                         657.4 23
Latency           5727ms     11334ms                         1788ms                          86612us


See: Benchmark: Samsung S2 Portable 500GB USB 2.0 External HD
See more benchmarks:

Aug 4, 2012

Benchmark: Kingston DataTraveler 101 DT101 G2 16GB

I was curious about Kingston USB flash performance. The overall performance is poor.

Write performance: 3.7 MB/s
ReWrite performance: 3.0 MB/s
Read performance: 22.5 MB/s
Random Seeks: 4.3 / sec

Comparing to Samsung S2 Portable 500GB USB 2.0 External HD:
9.4 times slower for write
5.7 times slower for rewrite
2.0 times slower for reading
28.79 times less seeks / sec

Full performance output:

[root@ace ~]# bonnie++ -n 0 -u 0 -r 7000 -f -b -d /mnt
Using uid:0, gid:0.
Writing intelligently...done
Reading intelligently...done
start 'em...done...done...done...done...done...
Version  1.96       ------Sequential Output------ --Sequential Input- --Random-
Concurrency   1     -Per Chr- --Block-- -Rewrite- -Per Chr- --Block-- --Seeks--
Machine        Size K/sec %CP K/sec %CP K/sec %CP K/sec %CP K/sec %CP  /sec %CP
ace.home        14G            3708   0  3063   0           22568   3   4.3   0
Latency                        6309ms   22399ms             11761us   29385ms


See: Benchmark: Samsung S2 Portable 500GB USB 2.0 External HD
See more benchmarks:

Jul 21, 2012

Mounting and converting vdi and qcow2 image files

1. Convert VirtualBox VDI disk file for use with KVM
$ qemu-img convert -O qcow2 diskname.vdi newdiskname.qcow2

2. Mounting raw disk images
losetup /dev/loop0 image.img
# kpartx -a /dev/loop0
# mount /dev/mapper/loop0p1 /mnt/image

3. Mount qcow2 disk images

# modprobe nbd max_part=63
# qemu-nbd -c /dev/nbd0 image.img
# mount /dev/nbd0p1 /mnt/image

Optional: LVM
Scaning for LVM on disk images:

# vgscan
# vgchange -ay VolGroupName
# mount /dev/VolGroupName/LogVolName /mnt/image


# umount /mnt/image
# vgchange -an VolGroupName
# killall qemu-nbd
# kpartx -d /dev/loop0
# losetup -d /dev/loop0


Jun 20, 2012

Caboooo! Cabooooo! Acabooooo!

Assim que fiquei sabendo a última nota que faltava, me lembrei do Galvão bueno comemorando alucinadamente a final da copa de 1994.

Finalmente me formei!

Caboooo! Caboooo! Acabooo!

Jun 9, 2012

Enable power button on minimal install of Fedora 17

After fresh Fedora 17 minimal install, pressing the physical power button has no effect. This is valid for both virtual machines and physical servers. To fix it, just:

# yum install acpid
# reboot

Jun 3, 2012

Communication between two MSP430

I like the LauchPad kit due its price under USD 5. But I also like it due its simplicity.

The Lauchpad kit includes two MSP-430 chips. It is very easy to make the second chip to work with just a few components.

Schematic used for the second MSP430

This schematic is from:

I made two simple programs that communicate with each other. The source code is at:

Lightning fast boot with Fedora17

See Harald Hoyer article: Fedora 17 Boot Optimization (from 15 to 2.5 seconds).

One of the boot steps that consumes about 3 seconds is the decompression and running of initrd. If you do not use LVM, software RAID or partition encryption you may not need initrd.

But Grub2 is configured to always use initrd for booting. If you modify by hand the file /etc/grub2.cfg, it will last until your next Kernel update. To avoid this, I made a grub configuration file that will generate entries without initrd even for new Kernels. Check it out at:

[peter@ace Fedora17-fastboot]$ systemd-analyze
Startup finished in 1433ms (kernel) + 2150ms (userspace) = 3584ms

3.5 seconds is good for me and I still have a fully operational Fedora 17. :-D

May 1, 2012

Nobreak SMS no Linux

O software que a SMS disponibiliza para comunicar com os nobreaks é no mínimo precário. Não é bem acabado e consome uma enormidade de recursos. É difícil de acreditar que eles distribuem um servidor de aplicação apenas para isso. Resolvi fazer o meu software para comunicar com o nobreak. Veja a saída da versão 0.1:

É apenas um executável simples que não precisa de nada complexo. O código fonte está diponível para download em:

Também tem alguns binários em:

Tente usar o nut, Network UPS Tools. Os nobreaks da SMS aparecem na lista de dispositivos compatíveis. O nut está disponível na maioria das distribuições Linux.

Mar 18, 2012

Emdebian Grip 2.0

The Grip flavor of Emdebian project allows to create thinner Debian root file systems. I've created one that includes apt, vim-tiny, net-tools, iputils-ping, and isc-dhcp-client. Later I've added grub and Kernel 2.6.32-5-686. The total size of this Emdebian is about 66MB, which is 3.5 times smaller than the usual 230 MB required for regular Debian root file system.

Want to test it? I've created a 128MB bootable image file for x86 architecture. You will need at least 48MB of RAM to this image work. You can download it here. For testing use USB pen drive and a personal computer that allows booting from USB. The procedure:
1 - After downloading, uncompress using gzip:
# gzip -d peters-emdebian.img.gz

2 - Copy the image do destination pen drive using dd. Be careful to use correct destination as dd will overwrite it. Replace "X" with the correct drive letter. All data on destination storage will be lost.
# dd if=peters-emdebian.img of=/dev/sdX bs=8k

3 - Boot! Using the storage you've created. Don't tell anyone but the root password is: 3dp

You can use $ df -h and $ cat /proc/meminfo to check the resource consumption of this Emdebian install.

Generating the Emdebian root filesystem from a Debian Squeeze box is easy. Making a bootable image require a little bit more work but also works fine. To generate the rootfs, download this file and:
# multistrap -d grip-squeeze -f grip-squeeze.conf

The Emdebian root filesystem will be saved at the folder grip-squeeze.

More at Emdebian Grip web site.

Mar 7, 2012

Performance Overhead and Comparative Performance of 4 Virtualization Solutions

Virtualization is being sold as a solution for data center hardware idleness. Increasing the hardware usage level from less than 20% to more than 70% is possible with virtualization solutions. This may represent advantages like more available computing power and less servers consuming electricity, space and services. But at what cost? What is the price of virtualization solutions in terms of computing power and I/O consumption? What is the overhead of the virtualization layer? 

Sample graph showing read performance for Linux

Feb 4, 2012

GitHub Social Coding

Github is simple to use and powerful git repository with great web interface. If your project is open source, there is no problem if your repository is also open, right? What could be better to open source projects than having free hosting on feature rich and reliable service?

But if you are not the good guy and want to have your git repositories private, looks fair to charge you little money to keep your code safe. 

This looks to be the basic business model do Github and the prices are attractive.

For those have never being in touch with versioning and code repositories, Github is also good place to start. The step-by-step documentation will guide you over the process of using git. It is really easy to start.

Github also encourages you to make friends and to grow your social network around the code you share. I would like to be your friend on GitHub, so you are invited to see my profile:

If you are looking for a job, Github can also help you. You can make your "Job Profile" and select: "Available for hire". The link to your code looks to be that your "open" code repositories are your portfolio.

Jan 31, 2012

C code optimization benchmark

Steve Oualline talks about C code optimization on his book: Practical C Programming. I was curious about the real performance gains. The benchmark test results are at the end of the post.

How can this C code be optimized?

#define X_SIZE 60
#define Y_SIZE 30
int matrix[X_SIZE][Y_SIZE];
void initmatrix(void)
int x,y;
for (x = 0; x < X_SIZE; ++x){
for (y = 0; y < Y_SIZE; ++y){
matrix[x][y] = -1;
void main()
The first suggested optimization is to use the "register" qualifier for the indexes variables x and y:

#define X_SIZE 60
#define Y_SIZE 30
int matrix[X_SIZE][Y_SIZE];
void initmatrix(void)
register int x,y;
for (x = 0; x < X_SIZE; ++x){
for (y = 0; y < Y_SIZE; ++y){
matrix[x][y] = -1;
void main()
 Then the optimization suggestion is to order the for loops so that the innermost for is the most complex:

#define X_SIZE 60
#define Y_SIZE 30
int matrix[X_SIZE][Y_SIZE];
void initmatrix(void)
register int x,y;
for (y = 0; y < Y_SIZE; ++y){
for (x = 0; x < X_SIZE; ++x){
matrix[x][y] = -1;
void main()
The most tricky to understand is changing Y_SIZE from 30 to 32. This will activate one feature of most C compilers that converts multiples by a power of  2 (2, 4, 8, ...) into shifts. This will result in performance gains when the computer is doing pointer arithmetic to access the correspondent memory address of matrix[x][y]. The compiler will change one multiplication operation into one shift operation which is cheaper.
#define X_SIZE 60
#define Y_SIZE 32
int matrix[X_SIZE][Y_SIZE];
void initmatrix(void)
register int x,y;
for (y = 0; y < Y_SIZE; ++y){
for (x = 0; x < X_SIZE; ++x){
matrix[x][y] = -1;
void main()
Reducing the number of loops and taking control of the pointer arithmetic is great performance optimization.

#define X_SIZE 60
#define Y_SIZE 30
int matrix[X_SIZE][Y_SIZE];
void initmatrix(void)
register int index;
register int *matrix_ptr;
matrix_ptr = &matrix[0][0];
for (index = 0; index < X_SIZE * Y_SIZE; ++index){
*matrix_ptr = -1;

void main()
Reducing the number of variables that are necessary to do the pointer arithmetic also improves performance:
#define X_SIZE 60
#define Y_SIZE 32
int matrix[X_SIZE][Y_SIZE];
void initmatrix(void)
register int *matrix_ptr;
for (matrix_ptr = &matrix[0][0];
matrix_ptr <= &matrix[X_SIZE - 1][Y_SIZE - 1];
*matrix_ptr = -1;

void main()
Looks like that there is nothing more to optimize. You can always write some assembly but it may not be good idea. The library function memset() can be used to fill a matrix. "Frequent used library subroutines like memset are often coded into assembly language and may make use of special processor-dependent tricks to do the job faster than could be done in C".
#define X_SIZE 60
#define Y_SIZE 30
int matrix[X_SIZE][Y_SIZE];
void initmatrix(){
memset (matrix, -1, sizeof(matrix));

void main()
There is overhead in function call. It is possible to do better with macros.
#define X_SIZE 60
#define Y_SIZE 30
int matrix[X_SIZE][Y_SIZE];
#define initmatrix() \
memset (matrix, -1, sizeof(matrix));

void main()
The improvements looks good, but how much efficient each optimizations are? I've measured it in clock cycles. And found that the optimization level is processor dependent.

For clock cycles, lower is better.

Results for: Intel(R) Core(TM) i7-2620M CPU @ 2.70GHz

clock cycles times faster
matrix1() 11102.151556 1
matrix2() 6400.36597 1.7346119906
matrix3() 6379.460394 1.740296337
matrix4() 5952.497506 1.8651249404
matrix5() 2154.262528 5.153574094
matrix6() 1907.350431 5.8207193474
matrix7() 792.123493 14.0156827239
matrix8() 780.254779 14.2288799182

Results for: Intel(R) Core(TM)2 Quad CPU    Q8400  @ 2.66GHz

clock cycles times faster
matrix1() 17175.114362 1
matrix2() 8153.467501 2.1064797719
matrix3() 8063.182452 2.1300664427
matrix4() 8497.82453 2.0211189701
matrix5() 4300.083046 3.9941355035
matrix6() 4321.695819 3.9741608575
matrix7() 1569.097383 10.945856228
matrix8() 1560.792718 11.0040969335

Results for: AMD Athlon(tm) 7750 Dual-Core Processor @ 2.7GHz

clock cycles times faster
matrix1() 25319.969906 1
matrix2() 10329.498185 2.4512294259
matrix3() 8558.934585 2.9583086136
matrix4() 9480.851235 2.6706430972
matrix5() 5544.608885 4.5665926003
matrix6() 5577.454075 4.5397002943
matrix7() 643.046753 39.3750062307
matrix8() 631.545791 40.0920570873

So, it is real! For Intel you can get 2 times faster performance by doing simple changes and not using pointer arithmetic. If you do take control of pointer arithmetic and trash some variables, the performance gain can go up to almost 6 times faster. The performance gain can reach 14 times faster by using ultra specialized subroutines. It is much better then I was expecting.

For AMD the use of the specialized functions can result in speedup of more than 40 times.

The clock cycle count is not an integer because the values shown are average mean of 256 measurements.

For the graphs that shows results in clock cycles, lower is better.
C code optimization benchmark: Core i7

C code optimization benchmark: Core 2 Quad

C code optimization benchmark: Athlon X2

rdtscbench was used to do the benchmark testing. The source code is available here. The command line for rdtscbench was: "# ./rdtscbench 256 8". It is also available at:

Jan 23, 2012

How to recompile software with hardware optimization?

This may be useful for compiling local applications that you want to run faster.

Try this on your computer:
$ echo "" | gcc -march=native -v -E - 2>&1 | grep cc1
On my computer it has returned:
 /usr/libexec/gcc/x86_64-redhat-linux/4.6.1/cc1 -E -quiet -v - -march=corei7-avx -mcx16 -msahf -mno-movbe -maes -mpclmul -mpopcnt -mno-abm -mno-lwp -mno-fma -mno-fma4 -mno-xop -mno-bmi -mno-tbm -mavx -msse4.2 -msse4.1 --param l1-cache-size=32 --param l1-cache-line-size=64 --param l2-cache-size=4096 -mtune=corei7-avx
This command probes the local computer for optimization flags. To use it:
$ CFLAGS="[blue string from above]" ./configure
You may consider adding the "-O3" flag. The -O3 flag enables levels 1, 2 and 3 of compile time optimization. There are more information about -O3 on gcc man page. For doing it, instead of previous line, use:
$ CFLAGS="-O3 [blue string from above]" ./configure


Dec 2, 2011

Lego Mindstorm NXT - Programming Options

Option 1: Lego Mindstorms NXT Software version 2.0
The first and the official programming option for the NXT is Lego Mindstorms NXT software version 2.0 that is based on Labview from National Instruments. It is delivered with 8547 LEGO® MINDSTORMS® NXT 2.0.

Mindstorms software is a graphical programming environment. The programming is made connecting bricks and data lines. It is "a great tool" for learning and teaching programming, and it is also fun. It is possible to do non trivial tasks like multi-threading and functions. But for non-small programs it is not practical.

Mindstorms software is used to make programs, to send the compiled programs to the NXT, to remote control the NXT, and to update NXT firmware. Both USB and Bluetooth are supported. I've tested it under Windows but it is also supported under Mac. It does not work under Linux.

See my enhanced color sorter program:
The main program. Note the two threads. The bottom is for the dispenser and color sensor, while the top controls the tray.

Function: tray_next

Function: tray_previous

This robot is running the code shown above.

You can download my program here. You will need Mindstorms software to open the files.

Mindstorms software is the perfect development environment for starting playing with Lego. It is as intuitive as connecting lego bricks and it is also beautiful. But is not practical for non small programs. I would not recommend to implement large software using it. But I would recommend this visual language to introduction to robotics and to programming languages.

There is lots of information about LabView at:

Option 2: RobotC
LabView was successful on allowing me implementing the enhanced color sorter algorithm. But it becomes clear that LabView is not practical for complex and large programs.

I found Robotc and tried it. There is a 30 days trial version that I used for two weeks.

The first step is to upgrade the NXT firmware so it can support Robotc binaries. Do not worry about firmware upgrades. It is easy and safe on the NXT. You can always upgrade the firmware to the Lego Offical Firmware using the LabView.

RobotC offers complete development environment with functions similar to the LabView. But instead of connecting bricks and data lines you write C programs.

I found some limitations when I was using more than one thread simultaneously. I'm quite sure that those limitations are not insurmountable, but I did not like RobotC. For the basics there are good documentation and tutorials but I did not find free detailed information.

Like labview, RobotC works on Windows and does not works on Linux.

See RobotC web site.

Option 3: NXC

"Not eXactly C (NXC) is a high level language, similar to C, built on top of the NBC compiler. It can also be used to program the NXT brick. NXC is basically NQC for the NXT. To compile NXC programs just use the NBC compiler with source code files that have a .nxc file extension. A reference guide for NXC is available. You can also access online API help for NXC or download a compiled HTML help file. To take advantage of multi-dimensional array support and native shift operations be sure to download the enhanced NBC/NXC firmware and install it on your NXT."

I liked NXC. "To me", it feels more like C gcc than RobotC and it works on Linux. If you are Windows user, you should try Bricx Command Center that uses NXC/NQC, but if you are Linux user, NXC is great option. I'm using two tools that are official Fedora 15 packages: NQC and NXTRC. NQC is the compiler for the NXC while NXTRC is a tool for remote controlling the NXT and to send files to the Brick using bluetooth. I'm using the following packages:




Installing both on Fedora 15 is as hard as:
# yum install nxtrc nbc

To compile the color sorter on Fedora 15:
$  nbc dispenser4.nxc -O=dispenser4.rxe -sm-

Then, to send it to the NXT using bluetooth:
$ nxtrc -a 00:16:53:13:9A:70 -W dispenser4.rxe

The documentation for NXT is complete and freely available. Also, working on Linux is also very good to me. The binaries made by NXT works on Offical Lego Firmware but you can update to a firmware that is announced to offer better performance. I did not tried the high performance firmware yet.

The source code of the color sorter can be downloaded from: dispenser4.nxc

There is more information about NXC here.

I would start with LabView for initial fun and learning about sensors and motors, then switch to NXC for the complex tasks.
RobotC may have better processing performance and also richer debugging than Bricx Command Center. But for now, processing performance and richer debugging interface are not features that I'm looking for. If you need processing speed and/or rich debugging interface, give RobotC a try.