Category: BrainDamage

Using rsync to create backup

rsync is mostly used to synchronize files between Internet servers, but this powerful tool also can be used to create local backup.

I have an external harddisk for backup. Instead just using copy command to save my computer file to the external harddisk I want to verify first if the file saved there is exactly the same I have in the computer. Case the files are different I want to save a newer version and rename the older version.

It is easy to do using rsync:

rsync --suffix="_`date +%Y.%m.%d.%H.%M`" -bacH localdirtobackup /media/user/external_harddisk/

If the file exist in the external harddisk, but its content is different then it will be renamed to filename_YEAR.month.day.Hour.Minute

It also could interesting to know when some file was corrupted in the computer or external harddisk, or if some virus is changing your files.

AER: Corrected error received: 0000:00:1d.6

I was getting these errors:

[ 1089.225561] pcieport 0000:00:1d.6: AER: Corrected error received: 0000:00:1d.6
[ 1089.225586] pcieport 0000:00:1d.6: PCIe Bus Error: severity=Corrected, type=Data Link Layer, (Transmitter ID)
[ 1089.225593] pcieport 0000:00:1d.6: device [8086:a336] error status/mask=00001000/00002000
[ 1089.225597] pcieport 0000:00:1d.6: [12] Timeout

Unfortunately these error are repeating too fast and avoiding other messages to be shown in the dmesg command.

The solution is easy, just add “pci=noaer” to GRUB_CMDLINE_LINUX_DEFAULT in the /etc/default/grub to include it on Linux kernel command line when grub boots Linux:

$ vi /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash pci=noaer”

$ sudo update-grub

The reboot and the above message will desappear

Source: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1521173

Windows 10 only see 2MB partition on USB Flash Drive

I created a boot disk using Ubuntu “startup” program to install Linux on other computer, it worked fine, but when I put the USB Flash Drive on my computer that is running Windows 10 it only show 2MB.

It happens because the boot disk has two partitions and Windows only see the FAT partition. Fortuntately I found an way to fix it:

C:\> diskpart
DISKPART> list disk
DISKPART> select disk 1 (make sure its the right one)
DISKPART> clean (if it complains about permission, just type clean again)

It removed the partitions, but now I need to create other partition:

DISKPART> create partition primary

Then after removing and inserting the disk I format it and everything worked fine.

Source: https://askubuntu.com/questions/586118/16gb-pen-drive-showing-2mb-space-after-formatting-on-windows-7

Testing Mozilla DeepSpeech

These are the steps to test deepspeech 0.4.1 on Linux Ubuntu 18.04:

Install libsox and fake it as libsox2:

$ sudo apt-get install libsox-dev

$ ln -s libsox.so.3.0.0 libsox.so.2

Record your voice:

$ rec -c 1 -r 16000 -b 16 recording.wav

Alternatively download the audio from google translator and convert to wav 16bit 16khz mono:

$ ffmpeg -i the_quick_fox_jump_over_the_lazy_dogs.mp3 -acodec pcm_s16le -ac 1 -ar 16000 recording.wav

Test it:

$ ./deepspeech --model ../deepspeech-0.4.1-models/models/output_graph.pbmm --alphabet ../deepspeech-0.4.1-models/models/alphabet.txt --lm ../deepspeech-0.4.1-models/models/lm.binary --trie ../deepspeech-0.4.1-models/models/trie --audio recording.wav
TensorFlow: v1.12.0-10-ge232881
DeepSpeech: v0.4.1-0-g0e40db6
the quick brown fox jump over the lazy dog

Using sed command to replace newlines

WordPress is always modificating their software to improve speed and try to bring good things to users. Unfortunately the Block editor is not a good these things, at least not for me.

Recently while editing my post about my list of musics ( https://acassis.wordpress.com/2008/10/22/msicas-mais-ouvidas/ ) it placed the new lines between Music (Musica) and Artist (Cantor).

Then it became:

Music: Blablabla

Artist: Blabla

Music: Blablabla2

Artist: Blabla2

I wanted to restore the old organization:

Music: Blablabla
Artist: Blabla

Music: Blablabla2
Artist: Blabla2

Instead editing it be hand I tried to use VIM text editor, but vim recognizes \n as \0. And although there are some other ways to get it working on vim, Ctrl+J etc didn’t work as expected.

Then I remembered that sed -i could do the trick:

I tested this idea:

sed -i 's/\n\nCantor/\nCantor/g' musics.txt

It didn’t work, then searching in the Internet I found this post:
http://www.benjiegillam.com/2011/09/using-sed-to-replace-newlines/

Then the command became:

sed -i ':a;N;$!ba;s/\n\nCantor/\nCantor/g' musicas.txt

Now the order was restored.

Imposto de Renda 2019 no Linux

Tentei instalar o programa de declaração de imposto de renda no Ubuntu 18.04 e tive alguns problemas:

$ chmod a+x IRPF2019Linux-x86_64v1.5.bin 
$ ./IRPF2019Linux-x86_64v1.5.bin 
/tmp/ijtmp_BAA7A551-D3D8-3B70-2DF2-FF72C5CFA51F/bin/xdg-open: 255: /tmp/ijtmp_BAA7A551-D3D8-3B70-2DF2-FF72C5CFA51F/bin/xdg-open: gnome-open: not found

Então instalei a libgnome2-bin para ver se resolvia o problema:

sudo apt install libgnome2-bin

Ao executar novamente notei que não havia instalado o Java 8 no meu computador, então segui estes passos para instalar:

How to Install JAVA 8 on Ubuntu 18.04/16.04, Linux Mint 19/18

Creio que o IRPF deveria ter uma forma mais inteligente de rodar no Linux, imagine uma pessoa leiga tentando instalar isso? Creio que este é um dos problemas que dificultaram o uso do Linux no Desktop.

Fake chip makes me nervous

I was trying to configure the Microchip/Atmel SAMD21 USART to work at 110BPS to use with an old ABNT CODI protocol.

I noticed that the Silabs CP2102 on Linux doesn’t support such low baudate:

$ sudo stty 110 cs8 -parenb -F /dev/ttyUSB0 
stty: /dev/ttyUSB0: unable to perform all requested operations

“Fortunately” I had a FTDI USB/Serial module that accepts this low baudrate. Then after spending many days trying to figure out why the communication at 110 BPS wasn’t working I decided to use the Logic Analyzer and discovered that the FTDI chip wasn’t generating the 110BPS.

Then I realized there are some FTDI fake chips that don’t work correctly at high speed. Now I can confirm they will not work correct at low speed either. Probably these fake chips use a microcontroller instead of a real IP for USB/Serial and they have loss of precision at low and high baudrates.

Then I decided to use two SAMD21 boards to test the communication, the first board will transmit at 110BPS and the second one will received the data at same baudrate. It worked fine.

Then I found a Prolific PL2303 USB/Serial dongle here and decided to test it. And to my surprise the PL2303 worked fine at 110 BPS and I could test it from computer to the board.

In the computer:

$ sudo stty 110 cs8 -parenb -F /dev/ttyUSB0
$ echo "Hello" > /dev/ttyUSB0

In the SAMD21 board:

nsh> dd if=/dev/ttyS0 of=/dev/console bs=1 count=10                             
Hello

This is a good 110BPS waveform:

Note that it wasted 90.752ms to transmit 10 bits, then each bit wasted 9.0752ms to be transmitted. Therefore to transmit 110 Bits it wastes 9.0752 * 110 = 998,272 ms. Nearly 1 second to transmit 110 bits, the error is only 0,17%.

So, never trust on your serial communication if you are using a USB/Serial from China.