In Latex2e ist es möglich simple Programmierung durchzuführen, ohne das auf eine andere Programmiersprache zurück gegriffen werden muss. Nichtsdestotrotz unterstütz Latex natürlich eine Fülle an Programmierschnittstellen für alle gängigen Sprachen (z.B. Lua, Python, Perl, Bash …).

Das Grunddokument

Als Grunddokument dient folgender Aufbau, dass Paket ifthen stellt grundlegende Kontrollstrukturen, Vergleichsoperatoren und Schleifen zur Verfügung:

\documentclass[a4paper,10pt]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{ifthen}

\begin{document}

...

\end{document}

Einfache Funktionen und Variablen

Man kann einfache Funktionen definieren, indem man neue Kommandos erzeugt. Im folgenden Beispiel wird ein Kommando mit zwei Pflichtargumenten erzeugt:

\newcommand{\distanz}[2]{Geben Sie die Distanz zwischen #1 und #2 an!\\\\}

Das Kommando kann auch noch nachträglich verändert werden:

\renewcommand{\distanz}[3]{Geben Sie die Distanz zwischen #1, #2 und #3 an!\\\\}

Eine einfache String-Variable wird ebenso angelegt und verändert:

\newcommand{\zielort}{Bonn}
\renewcommand{\zielort}{Berlin}

Die Funktion kann nun aufgerufen werden:

\distanz{Kiel}{Hannover}{\zielort}

Ausgabe

Geben Sie die Distanz zwischen Kiel, Hannover und Berlin an!

ganzzahlige Variablen

Ganzzahlvariablen (auch negativ) heißen in Latex counter und werden folgendermaßen deklariert und mit einem Wert versehen:

\newcounter{zaehler}
\setcounter{zaehler}{100}

Der Wert eines counters kann auch inkrementiert werden:

\stepcounter{zaehler}   %zaehler++ -> 101

Das Addieren und Subtrahieren geht ebenso:

\addtocounter{zaehler}{10}  %111
\addtocounter{zaehler}{-11} %100

Kontrollstrukturen und Schleifen

Jetzt kommt das Paket ifthen zum Tragen. Es bietet eine if-then-else-Anweisung und eine while-Schleife. Die Gesamtdokumentation dieses Paketes findet man hier.

Um lesend auf eine Variable/einen counter zuzugreifen, z.B. für einen Vergleich, dient folgende Anweisung:

\value{zaehler}

Möchte man stattdessen den aktuellen Wert als Dezimalzahl ausgeben:

\arabic{zaehler}

Um die Anwendung der Schleife und der if-Kontrollstruktur zu verdeutlichen dient folgendes Beispiel:

\newcounter{i}
\setcounter{i}{100}

whiledo{\value{i} > 0}{
    \noindent Wie viele Flaschen Bier sind noch da?\\
    \addtocounter{i}{-1}

    Es sind noch \textbf{\arabic{i}} Flaschen Bier im Kühlschrank.\\\\

    \ifthenelse{\value{i} = 0}{\textbf{Es ist kein Bier mehr Da!}}

}

Ausgabe

Wie viele Flaschen Bier sind noch da?
Es sind noch 99 Flaschen Bier im Kühlschrank.

Wie viele Flaschen Bier sind noch da?
Es sind noch 98 Flaschen Bier im Kühlschrank.

...

Wie viele Flaschen Bier sind noch da?
Es sind noch 0 Flaschen Bier im Kühlschrank.

Es ist kein Bier mehr Da!

what I have

  • grml-2017.06.iso on a usb-stick (Kernel 4.9)

  • old Data from an BIOS installation -> Debian 9 (Kernel 4.9)

what I want:

  • a fully encrypted system (including /boot) with UEFI-Boot

  • btrfs with subvolumes

1. create Partitions using gdisk

On UEFI-Systems you have to use gpt partitions and create a UEFI partition.

/dev/sda1   512M    type EF00 # UEFI partition
/dev/sda2   X       type 8300 # DM-CRYPT-LUKS
/dev/sda3   Y       type 8200 # SWAP

mkfs.vfat /dev/sda1

2. create LuskContainer

The second partition is used for a LUKS-container:

cryptsetup luksFormat /dev/sda2

3 .map the container and create btrfs on top of it

cryptsetup luksOpen /dev/sda2 sda2_crypt

mkfs.btrfs -L system /dev/mapper/sda2_crypt

4. mount and create subvolumes

mount /dev/mapper/sda2_crypt /target

btrfs subvolume create /target/@            -> later mounted to /
btrfs subvolume create /target/@home        -> later mounted to /home
btrfs subvolume create /target/@var         -> later mounted to /var
btrfs subvolume create /target/@snapshots   -> later mounted to /.snapshots

5. mount new subvolumes

umount /target

mount -o subvol=@ /dev/mapper/sda2_crypt /mnt/NEW-SYSTEM

mkdir /target/{home,var,.snapshots}

mount -o subvol=@home       /dev/mapper/sda2_crypt /target/home
mount -o subvol=@var        /dev/mapper/sda2_crypt /target/var
mount -o subvol=@snapshots  /dev/mapper/sda2_crypt /target/.snapshots

6. set default subvolume (mounted if no subvol option given)

Get the volumed ids:

btrfs subvolume list -p /target

Set the default subvolume:

btrfs subvolume set-default VOL-ID /target

7. copy old files

mount -o ro /dev/OLD_DEVICE /source

rsync -aAHX --info=progress2 --exclude={"/proc/*","/sys/*","/run/*","/var/run/*", \
                                        "/dev/*","/tmp/*"} /source/ /target/

8. mount EFI partition and prepare chroot environment

mkdir /target/boot/efi

mount /dev/sda1 /target/boot/efi

sudo mount --bind /dev  /target/dev
sudo mount --bind /proc /target/proc
sudo mount --bind /sys  /target/sys

chroot /target

If your old System was installed on a BIOS-System, you need to have to install the grub2 version needed for efi systems.

apt-get install grub-efi-amd64

9. modify the fstab and cryptab

example /etc/crypttab:

sda2_crypt  UUID=9c562dde-650d-4de9-9462-faf22d75fea5    luks,discard

example /etc/fstab:

proc                    /proc       proc    defaults                            0       0
/dev/mapper/sda2_crypt  /           btrfs   subvol=@,defaults,noatime           0       0
/dev/sda3               none        swap    sw                                  0       0

UUID=X                  /home       btrfs   subvol=@home,defaults,noatime       0       0
UUID=X                  /var        btrfs   subvol=@var,defaults,noatime        0       0
UUID=X                  /.snapshots btrfs   subvol=@snapshots,defaults,noatime  0       0

UUID=Y                  /boot/efi   vfat    rw                                  0       0

10. modify grub settings

echo "GRUB_ENABLE_CRYPTODISK=y" >> /etc/default/grub

sudo grub-install --target=x86_64-efi --efi-directory /boot/efi --bootloader=debian \
                  --boot-directory=/boot/efi/EFI/debian --recheck

sudo grub-mkconfig -o /boot/efi/EFI/debian/grub/grub.cfg

sudo update-initramfs -u -k all

11. boot into your new system

You have to enter the luks-key two times, one time for grub and one time for Linux.

ToDo

LSO is used by modern operating systems like GNU/Linux. LSO is a performance capability where TCP segments, when transmitted from the network stack to the network adapter, melted to a large segment, often bigger then the MTU from the network adapter. This behaviour speeds up the transition a lot. The opposite of LSO (Large Send Offload) is called LRO (Large Receive Offload).

LSO often causes confusion, if network sniffing is not done directly from wire. Because tcpdump and wireshark are showing heavily overlength packets if a TCP stream is captured on a adapter connected to a Linux-Box.

LSO and LRO are implemented in the Linux kernel as TSO and GSO/GRO.

Your are able to deactivate this behaviour, then your network capture looks more like wiretapping. The following commands are executed as root on Linux 4.9, with wlp2s0 as the (wireless) network device.

check the state for this capabilities:

# ethtool --show-offload wlp2s0 | grep offload
tcp-segmentation-offload: off
udp-fragmentation-offload: off [fixed]
generic-segmentation-offload: on
generic-receive-offload: on
large-receive-offload: off [fixed]
rx-vlan-offload: off [fixed]
tx-vlan-offload: off [fixed]
l2-fwd-offload: off [fixed]
hw-tc-offload: off [fixed]

Obviously tcp-segmentation-offload (TSO) is not in use, but GSO generic-segmentation-offload and GRO generic-receive-offload are.

To disable GSO and GRO execute the following command

# ethtool -K wlp2s0 gro off
# ethtool -K wlp2s0 gso off

further reading:

Wikipedia-LRO

eduPERT

Wireshark-Wiki (example did not work for me)

Seitdem ich das erste mal an einem C64 saß und die Kompaktheit und Lautlosigkeit dieses formschönen Brotkastens genoss, fragte ich mich, warum niemals wieder ein bezahlbarer Rechner mit adäquater Leistung und ohne Lüfter produziert wurde. Sicherlich, gab es in den letzten Jahrzehnten eine Unmenge an lüfterlosen Rechnern, speziell im Industriebereich. Diese sind aber oft für spezielle Anwendungen konzipiert und für den SOHO bereich viel zu teuer gewesen. Auf der andern Seite gab es die Raspberries, von denen ich auch eine Handvoll besitze. Aber als Desktop-Ersatz sind sie ebenso wenig geeignet.

Als Desktop verstehe ich einen PC, welche mir die Möglichkeit bietet mindestens zwei Monitore anzuschließen und eine größere Anzahl an Schnittstellen mitbringt, als zum Beispiel ein Notebook. Die Leistung soll natürlich nicht unterirdisch sein und in etwa mit einem 5-6 Jahre alten PC mithalten können.

Ich bin fündig geworden, in einem Artikel bei Heise-online wurde ein neuer Barebone der Firma Shuttle vorgestellt. Der DX30 besticht durch sein Volumen von nur 1,35 Litern und einem aktuellen SOC-Prozessor der Intel Kaby Lake-Generation. Er ist Lüfterlos und bietet eine NVMe-kompatible M2-Schnittstelle für SSDs, sowie eine zusätliche SATA Schnittstelle. Mit zwei seriellen RS-232 Anschlüssen ist auch beim DX30 die Nutzung im industriellen Umfeld noch möglich. Der DX30 ist extrem sparsam und verbraucht nur noch ein zehntel der Energie den mein 8 Jahre alter Desktop-PC benötigte.

Zuletzt stellt sich jetzt noch die Frage, wieviel langsamer ist der DX30 im Vergleich zu meinem alten Desktop-Rechner. Da es nur ein einfacher vergleich sein soll, erinnerte ich mich an einen Beitrag von fefe, indem fefe eigentlich die Geschwindigkeit von Skriptsprachen miteinander vergleichen wollte. Ziel war es, eine große Datei einzulesen, die enthaltenen Worte zu zählen und diese und die Anzahl auszugeben. Zwar eine naive herangehensweise, aber als simpler Vergleich ausreichend. Als Eingagedatei diente mir ein Wikipedia-Dump der slovakischen Wikipedia vom 01.08.2016: skwiki-20160801-pages-articles-multistream.xml.


Benchmarks wordprocessing
SpracheNeu (real)Alt (real)
gcc 60m49,179s0m44.297s
g++ 61m11,920s1m2.738s
OpenJDK 1.81m12,677s1m12.558s
PHP 71m28,062s1m22.261s
perl 5.242m24,382s1m58.661s
python 2.73m11,056s2m36.912s
lua 5.33m6,586s3m1.549s
ruby 2.35m22,457s4m19.293s
bash 4.310m23,156s10m26.901s

Wie deutlich zu sehen ist, ist der DX30 langsamer als der alt PC mit einem Athlon II X4 2,3 Ghz. Aber die Vorteile, wie die Geräuschlosigkeit und der Stromverbauch relativieren diese Ergebnisse in meinen Augen wieder.

cluj.pm-logo

From August 24 to August 26 I attended to the YAPC::EU 2016 in Cluj-Napoca (Klausenburg). Thanks for the really good organization to the nice organization team from Cluj.pm.

All presentation are online (youtube).

RIPE NCC Logo

Since yesterday I own a RIPE Atlas probe, that means I am a part of the biggest Internet measurement network ever made. With the collected data from the probes it is possible to monitor a big part of the Internet, independent from the Internet service providers. The data is used for science and monitor purposes. The probe has the ability to do checks, some of the common checks are visualized. With every check (mainly uptime) you earn credits and with enough of them you can create checks of your own and the check will be executed by the Atlas-network.

At home I put the probe in a separated network, but in fact there is no socket (remote and local) running on the probe.

There are a lot of Atlas probes out there check out the network coverage.

The Atlas probe is for free. Please join the Network and help to monitor the Internet.

vim-logo

This morning I decided to create another vim cheat sheet. One that works for me. There are a lot of cheat sheets outside, but the most lack of complexity and the other ones are simply not printable on a single page. I wrote a cheat sheet that covers a lot of commands, for example: tabs, searching, splitting and comprehensive editing commands. This all fits on a single page. You may download the sheet (pdf) from my site or you can clone it from GitHub.

git clone https://github.com/meetunix/vimcheat.git

ffmpeg-logo

From time to time I need to encode or re encode videos. I use mencoder a lot, but since two or three years I use nothing except ffmpeg. Before you start with video encoding you have to know a little about common video and audio codecs and the containers. Some times I hear statements like “I decoded that video to mkv, now it is small an has a good quality” … Whatever, I like to post some ffmpeg command lines that work well for me.


USEFULL COMMANDS

Convert a MPEG2 Transport Stream to simple MPEG2 fo further use or DVD compatibility

ffmpeg -i video1.m2t -acodec copy -vcodec copy output.mpg

Cut videos from starting position to end position (use -t instead of -to to use relative time from starting point (duration))

ffmpeg -i input.mpg -ss 00:01:33 -to 00:44:55 -acodec copy -vcodec copy cut.mpg

ENCODING

Encode a video to the popular H264-codec and audio to the free Vorbis-codec

ffmpeg -i input.mpg -deinterlace -c:v libx264 -preset veryslow -crf 26 -codec:a libvorbis -qscale:a 3 output.mkv

CRF: Constant Rate Factor: bigger value means smaller file and smaller value means bigger file but better quality (standard 23)

preset: predefined templates for configuration parameters (slower means better quality), possible values are: ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo (standard medium)

qscale:a: quality level for Vorbis codec: 3 means an nominal bit rate of 112 KBit/s

deinterlace: used to merge the interlaced TV-signal

More information on H264 encoding

Encode a video with the newer H265/HEVC-codec

ffmpeg -i input.mpg -c:v libx265 -codec:a libvorbis -qscale:a 3  output.mp4

CRF standard = 28

Video encoding to the free Theora-codec

ffmpeg -i input.mpg -codec:v libtheora -qscale:v 7 -codec:a libvorbis -qscale:a 3 output.ogv

qscale:v: video quality range from 0 to 10, where 10 is highest quality.

2PASS encoding with a fixed bit rate of 1MBit/s:

ffmpeg -i input.mpg -deinterlace -b:v 1000K -c:v libtheora  -pass 1 -an -f rawvideo -y /dev/null

ffmpeg -i input.mpg -deinterlace -b:v 1000K -codec:v libtheora -pass 2 -codec:a libvorbis -qscale:a 3 output.ogv

Encoding to the free VP8 and VP9 codecs:

VP8 and VP9 are widely supported by all main browsers (except IE). The VP9 is the standard codec at YouTube.

VP8 at variable bitrate:

ffmpeg -i input.mp4 -c:v libvpx -crf 10 -b:v 1M -c:a libvorbis -qscale:a 3 output.webm

CRF: can be a value from 4 to 63, lower values mean better quality

b:v: This is the target bit rate, the encoder is trying to reach this value

VP9 at VBR variable bitrate (target 700KBit/s) and opus audio codec:

ffmpeg -i input.mp4 -c:v libvpx-vp9 -b:v 700K -c:a libopus -b:a 96000  output.webm  

VP9 in constant quality mode:

ffmpeg -i input.mp4 -c:v libvpx-vp9 -crf 38 -b:v 0 -c:a libopus -b:a 96000  output.webm

CRF: a value from 0 to 63, where lower values mean better quality


NVIDIA graphics card with CUDA:

For a little period of time I got a fast Geforce graphics card with CUDA support and H264 encoding capability. Therefore I had t recompile ffmpeg to activate the Nvidia H264 encoder named nvenc_h264.

The encoded videos with the nvenc_h264 engine are bigger, but your are able to encode like 100 times faster.

variable bitrate:

ffmpeg -i input.avi -c:v nvenc_h264 -preset hq  -codec:a libvorbis -qscale:a 3 output.mkv

Or you are using a constant bit rate, but in comparison with the x264 encoder the quality is worse.

constant bitrate:

ffmpeg -i input.mpg  -b:v 1000K -c:v nvenc_h264 -preset hq   -codec:a libvorbis -qscale:a 3 output.mkv

Fairphone-Logo

More or less two years ago I ordered my first smartphone: a Fairphone (FP1). The target of the Fairphone company is to build a phone with conflict-free resources, fair working condition and a open supply chain. I’m really happy with it. It was delivered with a rooted Android 4.2 out of the box. The Google apps are optional, you do’nt have to use them. In the next weeks there will be an upgrade to Android 4.4. This Android-version is already fully supported by Google, really good for security fixes in the near feature. Due to this positive experiences, I ordered the Fairphone 2 in the second half of 2015 for my wife.

In February 2016 the FP2 was delivered without root access for the stock Android 5.1. But right after the startup the torture started. The phone crashed and restarts immediately, mostly five times a day during use and in idle mode. No reproduction possible, actually without sim-card and deactivated wifi. But I have waited, because the OS has the version 1.0.0 and I do not trust those dot zero releases. But after two updates the version number seems to be more trustworthy: 1.3.6.. Nevertheless same behavior.

I decided to switch to the OpenSource version of the FairphoneOS, which was released on the 28th of April. Now there is root access, but from then the Fairphone does not restart if it crashes, now the accumulator has to be removed for a second. After that the FP2 restarts till the next crash…

There are a lot of people out there with the same problems and the official forum contains a lot of requests according to the crashes. There were Workarounds, but none of them worked. I was very patient with Fairphone and waited a lot of time, but in June I have opened a ticket at the Fairphone support-platform, I got no response so far.

Today my wife owns a standard HTC smartphone and the FP2 crashes continuously.

Without doubt, this is the baddest solution thinkable.

Padre Logo

Until Debian 8 (known as Jessie) there was a package for the Perl-IDE Padre. But at the time there is no working Package available for Debian 9 testing/stretch, because there seems to be a bug that prevents modern Perl to compile the IDE version 1.00. At CPAN, the available version is 1.00, but at github there is a bug-fixed Version 1.01 which works really nice, even though we had to do little more work previously:

Install some dependencies needed by Padre Makefile.PL

apt-get install libmodule-install-perl \
                liblocale-msgfmt-perl \
                libalien-wxwidgets-perl 

After cloning the Padre-repository you can run the Makefile.PL, and the script is showing you the rest of the required modules:

git clone https://github.com/PadreIDE/Padre.git && cd Padre
perl Makefile.PL

...
Warning: prerequisite Algorithm::Diff 1.19 not found.
Warning: prerequisite App::cpanminus 0.9923 not found.
Warning: prerequisite Capture::Tiny 0.06 not found.
Warning: prerequisite Class::Adapter 1.05 not found.
Warning: prerequisite Class::Inspector 1.22 not found.
...
Warning: prerequisite Wx 0.9916 not found.
Warning: prerequisite Wx::Perl::ProcessStream 0.32 not found.
Warning: prerequisite Wx::Scintilla 0.39 not found.
...

Most of that missing modules are available via the Debian repository, there is no need to install from CPAN.

apt-get install libalgorithm-diff-xs-perl \
                libalgorithm-diff-perl \
                cpanminus \
                libcapture-tiny-perl \
                libclass-adapter-perl \
                libclass-inspector-perl \
                libclass-xsaccessor-perl \
                libdbd-sqlite3-perl \
                libdbi-perl \
                libdevel-dumpvar-perl \
                libdevel-refactor-perl \
                libfile-copy-recursive-perl \
                libfile-find-rule-perl \
                libfile-sharedir-perl \
                libfile-pushd-perl \
                libipc-run-perl \
                libmodule-build-perl \
                libmodule-manifest-perl \
                libmodule-starter-perl \
                liborlite-perl \
                liborlite-migrate-perl \
                libpod2-base-perl \
                libppi-perl \
                libppi-xs-perl \
                libppix-editortools-perl \
                libppix-regexp-perl \
                libparse-errorstring-perl-perl \
                libparse-exuberantctags-perl \
                libpod-abstract-perl \
                libpod-pom-perl \
                libprobe-perl-perl \
                libsort-versions-perl \
                libtemplate-tiny-perl \
                libtest-exception-perl \
                libtest-mockobject-perl \
                libtest-nowarnings-perl \
                libtest-script-perl \
                libtest-warn-perl \
                libtest-pod-perl \
                libtest-pod-coverage-perl \
                libtext-diff-perl \
                libtext-findindent-perl \
                libtext-patch-perl \
                libwx-perl \
                libwx-perl-processstream-perl \
                libterm-readline-gnu-perl \
                libwx-scintilla-perl

If you rerun the Makefile.pl there are two modules which are not in the Debian repository:

perl Makefile.PL
...
Warning: prerequisite Debug::Client 0.29 not found.
Warning: prerequisite Parse::Functions 0.01 not found.
...

We have to install these Modules via cpanminus

cd ~
cpanm Parse::Functions
cpanm Debug::Client

Debug::Client fails, there seems to be the bug, that the whole Padre-IDE is not going to work. In fact: only one Test failed, some weeks ago I forced the Installation of the module and everything works fine. I had no stability issues till now:

cpanm --force Debug::Client

Now you can run the installation procedure:

cd Padre
make
make test
make install

If you don’t want to use a GUI-based editor for development, the following talk will show you cool vim-plugins for Perl-development: Youtube: YAPC::2016 Damian Conway - VIM as a Perl IDE