Author Archive

Using Powershell to calculate/compare MD5 hashes

This entry is part 1 of 4 in the series MD 5 Calculation

Here’s some code to a) calculate a MD5 hash for a given file and b) to compare the hash with a MD5 provided in an external file. The scripts expects the MD5 file to have the same name, but MD5 extension. Credit goes to the friendly souls providing the original code, I just copied and pasted everything together.

The comparison is just visual, both MD5 hashes — the calculated and the provided one — are printed on the screen, it’s easily to extend it for an automated comparison.

# Reference: http://onlinemd5.com/
 
### Step A: Get the name of the file
# http://blogs.technet.com/b/heyscriptingguy/archive/2009/09/01/hey-scripting-guy-september-1.aspx
Function Get-FileName($initialDirectory)
{  
 [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") |
Out-Null
 
 
$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.initialDirectory = $initialDirectory
$OpenFileDialog.filter = "All files (*.*)| *.*"
$OpenFileDialog.ShowDialog() | Out-Null
$OpenFileDialog.filename
} #end function Get-FileName
 
# *** Entry Point to Script ***
$file =  Get-FileName -initialDirectory "H:\MD5"
 
### Step B: Create a file handle from this string and calculate the MD5 sum
 
$filehandle = Get-ChildItem $file
 
# write-host "file: " $file
# write-host "DirectoryName: " $filehandle.DirectoryName
write-host "Name: " $filehandle.Name
# write-host "pure Name: " $filehandle.BaseName
 
# http://stackoverflow.com/questions/10521061/how-to-get-an-md5-checksum-in-powershell
$md5 = New-Object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$hash = [System.BitConverter]::ToString($md5.ComputeHash([System.IO.File]::ReadAllBytes($filehandle))).ToLower().Replace("-","")
 
write-host "Calculated Hashsum: "  $hash
 
### Step C: Get the MD5 sum from the MD5 sum file matching the other filename
 
$md5handle =  Get-ChildItem $($filehandle.DirectoryName + "\" + $filehandle.BaseName + ".md5")
$md5sum = [IO.File]::ReadAllText($md5handle)
 
write-host "Provided MD5        " $md5sum

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Animating TikZ Graphics

After drawing the cubic Bezier a few days ago I wanted to animate it. Using the animate package this is fairly simple:

\documentclass{article}
\usepackage[paperwidth=5.5cm,paperheight=5.3cm,left=0cm,right=0cm,bottom=0cm,top=0.25cm]{geometry}
\usepackage{tikz}
\definecolor{fom}{RGB}{0,153,139}
 
\newcommand{\dat}{0.7} % 0.67
\usepackage{animate}
 
\begin{document}
 
\begin{animateinline}[poster=last, controls, palindrome]{10}
\multiframe{70}{Ry=0.1+0.01}{
\begin{tikzpicture}[x=4cm,y=4cm]
\draw[line width=1pt,lightgray] (0,0) -- (1,1);
\draw (0,0) -- (1,0) -- (1,1) -- (0,1) -- (0,0); 
\draw (0,0) -- (0.17,0.67); 
\draw (1,1) -- (0.83,\Ry); 
 
\draw [magenta,fill=magenta](0.17,0.67) circle (.5ex); 
\draw [fom,fill=fom](0.83,\Ry) circle (.5ex); 
 
\draw[line width=1pt] (0,0) .. controls (0.17,0.67) and (0.83,\Ry) .. (1,1);
 
\node[label={[label distance=0.0cm,text depth=-1ex,rotate=90]left:Fortschritt in \%}] at (-0.1,.8) {};
\node[label={[label distance=0.0cm,text depth=-1ex]right:Zeit-Achse}] at (0,-0.05) {};
\end{tikzpicture}}
\end{animateinline}
 
\end{document}

I am animating in the TeX code (not externally) so I use animateinline with 10 frames per second. Inside this environment I prepare 70 frames, where I have the y-coordinate of the second point loop from 0.1 in steps of 0.01. The looping is controlled via Ry (that translates to \Ry in the loop). That’s it!

Here is the resulting PDF: bezier

PS: I used pdflatex from the TeX Live 2014.

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Drawing Bezier Curves with TikZ

To visualize an example for cubic-Bezier CSS animations (http://cubic-bezier.com) I decided to try TikZ. That was in fact a pretty good idea, as — with the help of Google (and mostly tex.stackexchange.com) I managed to complete the following example in just a few minutes:

\documentclass{article}
\usepackage[paperwidth=5.5cm,paperheight=5.3cm,left=0cm,right=0cm,bottom=0cm,top=0.25cm]{geometry}
\usepackage{tikz}
\definecolor{fom}{RGB}{0,153,139}
\begin{document}
 
\begin{tikzpicture}[x=4cm,y=4cm]
\draw[line width=1pt,lightgray] (0,0) -- (1,1); % gray line for the linear animation path
\draw (0,0) -- (1,0) -- (1,1) -- (0,1) -- (0,0); % frame
\draw (0,0) -- (0.17,0.67); % (0,0) to 2. point
\draw (1,1) -- (0.83,0.67); % (1,1) to 3. point
 
\draw [magenta,fill=magenta](0.17,0.67) circle (.5ex); %circle 1
\draw [fom,fill=fom](0.83,0.67) circle (.5ex); % circle 2
 
\draw[line width=1pt] (0,0) .. controls (0.17,0.67) and (0.83,0.67) .. (1,1); % cubic bezier curve
 
% labels
\node[label={[label distance=0.0cm,text depth=-1ex,rotate=90]left:Fortschritt in \%}] at (-0.1,.8) {};
\node[label={[label distance=0.0cm,text depth=-1ex]right:Zeit-Achse}] at (0,-0.1) {};
\end{tikzpicture}
\end{document}

The result is pretty impressive.

bez

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Windows Phone versus iPhone

Since my iPhone 4 was getting slower and I was not willing to purchase a new iPhone for hundreds of Euro I decided to give a Windows phone a try. I purchased a rarely used Nokia Lumia 630 with dual-SIM option via Amazon Marketplace for slightly more than 100 Euro.

I have been using it for a few weeks now, here’s a subjective comparison of the pros & cons:

PRO Lumia 630

Battery
The accu is not glued to the case but can simply be switched.
Price
With littler more than 100 Euro it is much cheaper if compared to the iPhone
Size
Compared with my iPhone 4 the Lumia has a bigger screen, so watching videos on the treadmill is a significantly experience
SD Card
The Lumi comes with 8GB Flash and a SD card slot accepting cards with up to 128 GB. Going from a 16 GB iPhone to 64 GB would have cost around 200 Euro for the iPhone 5.
no more iTunes
No iTunes or any other app is needed, Windows recognizes the phone as standard storage device, I can easily add content to the flash memory or the SD card.
Tiles
Not a bad idea by Microsoft to divide the start screen into tiles. It works, I guess, as good as the iPhone’s icons
Apps
The store comes with only a small part of apps if compared to the Apple or Google store. However as I do not intend to play with my phone I must confess, I have not missed anything in the app selection. One can even get offline navigation for free.
Radio
The Lumia comes with builtin radio, usable as soon as headphones are plugged in. Nice feature!

CON Lumia 630

Okay, now the Con part

Headset
My Sennheiser in-ears with builtin microphone do not work completely, I can’t adjust the volume. I could buy some new ones from Nokia, but they most likely inferior to my Sennheisers.
Audio Player
The Audio player is simply not a thought through as the corresponding Apple app. I guess it’s just a matter of user experience, but it „ain’t feel right“
Video Player
The Video Player sucks! It really sucks in two ways: It constantly nags me that a XBox account would need to be created. Microsoft, if I wanted I would but I DON’T WANT TO! It also has a technical bug: sometimes when I want to continue watching a video a click on the play button does NOTHING! Only pausing and pushing the play button again does the trick.
SMS and Call
Not sure but I haven’t found a way to call a number from which a SMS was sent. Need to investigate further…
Bluetooth Keyboards
I own two BT keyboards, one from HP, the other one the Apple BT keyboard. None is working with the Windows phone, which really sucks. Earlier versions of Windows Phone had Bluetooth HID support, Windows Phone 8.1 does not! (more info)

Conclusion

As of today I am satisfied with the Lumia, unfortunately not because it is technically superior or at least on a similar level as my iPhone, but because of the value I got for a small buck. To have a modern smartphone it’s not necessary to invest hundreds of Euros. Windows had delivered a good, but not very good, operating system that can handle everyday tasks pretty good. The Lumia 630 had good hardware, I was really suprised what is possible for 100 Euro. To get rid of the App issues I will have a closer look on the app market, I’t likely that I will be able to find simpler apps which do not bother me to create unwanted accounts.

Will I keep the Lumia: Yes, but probably not as long as my iPhone 4 which I used since 2010.

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

LaTeX \\ in externe Dateien schreiben

Ich hatte kürzlich die Notwendigkeit, Adressen wie die folgende aus KOMA Briefen in eine externe Datei zu schreiben:

\newcommand{\Anschrift}{John Doe \\ Berlin}

http://stackoverflow.com/questions/2115379/write-and-read-from-a-latex-temporary-file funktionierte leider nicht, da LaTeX das Schreiben der „\\“ bemängelte.

Auch der Weg über \unexpanded führte nicht weiter, da LaTeX dann nur den Befehl, nicht die Expansion in die Datei schreibt.

Die Lösung steckte dann in einer anderen Frage auf TSX: http://tex.stackexchange.com/questions/110883/writing-to-a-file

Das folgende Beispiel ist dabei rausgekommen:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{xpatch}
 
\makeatletter
% get a copy of `\protected@write
\let\protected@iwrite\protected@write
% patch the copy to add \immediate
\xpatchcmd{\protected@iwrite}{\write}{\immediate\write}{}{}
\makeatother
 
\newwrite\tempfile
\newcommand{\Anschrift}{John Doe \\ Berlin}
\immediate\openout\tempfile=Anschrift.txt
\makeatletter
\protected@iwrite\tempfile{\let\\\relax}{\Anschrift}
\immediate\closeout\tempfile
\makeatother
 
\begin{document}
 
\input{Anschrift.txt}
 
\end{document}

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Typesetting Chessboard with the chessboard package

I recently started Chess again, so I wanted to typeset some chessboards. With the chessboard package by Ulrike Fischer this is pretty much straight forward. Here’s a 2-page example what the package can do. It can do much more, I’ll post additional examples if I find some time.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[left=1cm,right=1cm,top=2cm,bottom=2cm]{geometry}
\usepackage{chessboard,xskak}
\usepackage{graphicx,booktabs}
\pagestyle{empty}
\setlength{\parindent}{0pt}
\begin{document}\centering
 
\scalebox{2}{\chessboard[setpieces={Ne4,Ka1,ka2}]}
 
\scalebox{2}{%
\setchessboard{showmover=false}
\newchessgame
\chessboard}
 
\scalebox{2}{%
\setchessboard{showmover=true}
\chessboard[setpieces={Ka1,ka2,Rb1,rb2,Nc1,nc2,Qd1,qd2,Be1,be2,Pf1,pf2,Qd3},
    pgfstyle=straightmove,
    arrow=stealth,
    linewidth=.25ex,
    padding=1ex,
    color=red!75!white,
    pgfstyle=straightmove,
    shortenstart=1ex,
    showmover=true,
    markmoves={d3-h7,d3-a6,d3-b1,d3-f1,d3-d8,d3-d1,d3-a3,d3-h3}]
}
 
Capital letters for white, small letters for black.
 
\begin{tabular}{cll} \toprule
Letter & English & German \\ \midrule
K & King & König \\
Q & Queen & Dame \\
R & Rook & Turm \\
N & Knight & Pferd \\
B & Bishop & Läufer \\
P & Pawn & Bauer \\ \bottomrule
\end{tabular}
 
\end{document}

chess

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Cross-referencing labels in other files

With the xr package one can pull labels from different files, however it is not possible to create hyperref-Hyperlinks with this package.

Fortunately there is a was around this challenge:

„Label-Dokument.tex“ with the label inside

%!TEX TS-program = Arara
% arara: pdflatex
\documentclass[12pt]{scrartcl}
 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{hyperref}
\hypersetup{
    bookmarks=true,                     % show bookmarks bar
    unicode=false,                      % non - Latin characters in Acrobat’s bookmarks
    pdftoolbar=true,                        % show Acrobat’s toolbar
    pdfmenubar=true,                        % show Acrobat’s menu
    pdffitwindow=false,                 % window fit to page when opened
    pdfstartview={FitH},                    % fits the width of the page to the window
    pdftitle={Title},                        % title
    pdfauthor={Author},                 % author
    pdfsubject={Subject},                   % subject of the document
    pdfcreator={LaTeX},                   % creator of the document
    pdfproducer={LaTeX},             % producer of the document
    pdfkeywords={keyword1} {key2} {key3},   % list of keywords
    pdfnewwindow=true,                  % links in new window
    colorlinks=true,                        % false: boxed links; true: colored links
    linkcolor=blue,                          % color of internal links
    citecolor=blue,                          % color of internal links
    filecolor=blue,                     % color of file links
    urlcolor=blue                        % color of external links
}
\begin{document}
 
\section{Some Section}
 
In this file I am setting a label. \label{lab:label1}
 
\end{document}

„Ref-Dokument“ with the reference to „Label-Dokument“

%!TEX TS-program = Arara
% arara: pdflatex
\documentclass[12pt,ngerman]{scrartcl}
 
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{graphicx}
\usepackage{hyperref}
\hypersetup{
    bookmarks=true,                     % show bookmarks bar
    unicode=false,                      % non - Latin characters in Acrobat’s bookmarks
    pdftoolbar=true,                        % show Acrobat’s toolbar
    pdfmenubar=true,                        % show Acrobat’s menu
    pdffitwindow=false,                 % window fit to page when opened
    pdfstartview={FitH},                    % fits the width of the page to the window
    pdftitle={Title},                        % title
    pdfauthor={Author},                 % author
    pdfsubject={Subject},                   % subject of the document
    pdfcreator={LaTeX},                   % creator of the document
    pdfproducer={LaTeX},             % producer of the document
    pdfkeywords={keyword1} {key2} {key3},   % list of keywords
    pdfnewwindow=true,                  % links in new window
    colorlinks=true,                        % false: boxed links; true: colored links
    linkcolor=blue,                          % color of internal links
    citecolor=blue,                          % color of internal links
    filecolor=blue,                     % color of file links
    urlcolor=blue                        % color of external links
}
\usepackage{zref-xr,zref-user}
\usepackage{nameref}
\zxrsetup{toltxlabel}
\zexternaldocument*{Label-Dokument}
\begin{document}
 
In this document I reference the external label in section \ref{lab:label1} on page \pageref{lab:label1} of the external document.
 
\end{document}

ref

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Using LaTeX to generate PDFs for mobile phones and tablets

Here’s an example how LaTeX can be used to create PDF files for small screens. The following example is made for the Nokia Lumia 630 but can but easily adjusted.

%!TEX TS-program = LuaLaTeX
\documentclass[7pt,smallheadings]{scrartcl}
\usepackage[paperwidth=56mm,paperheight=92.5mm,top=1mm,left=1mm,bottom=1mm,right=3.5mm]{geometry}
\usepackage[T1]{fontenc}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{csquotes}
\usepackage{xkeyval,polyglossia}
\setmainlanguage[spelling=new]{german}
\usepackage{fontspec}
\setmainfont{Verdana}
\usepackage{microtype}
\usepackage{blindtext}
\pagestyle{plain}
\begin{document}
 
\section{Ein Abschnitt}
\subsection{Ein Unterabschnitt}
 
\blindtext[2]
 
\end{document}

lumia

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Folien von der FrosCon 2014

Hier meine Folien vom heutigen LaTeX-Vortrag auf der FrosCon.

Froscon-2014-Folien (PDF)

TeX Dateien (zip)

Für Einsteiger in Sachen LaTeX sind folgende Dokumente interessant:

Als Buch für Einsteiger empfehle ich das Einführungsbuch von Herbert Voss: http://www.dante.de/index/Literatur/Einfuehrung.html

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website

Dateien verschlüsseln mit ccrypt

Auf der Suche nach einem Werkzeug, das Dateien mit hinreichender Sicherheit verschlüsseln kann, bin ich jetzt auf ccrypt (http://ccrypt.sourceforge.net/) gestoßen.

Dieses kleine Programm läuft unter allen möglichen Betriebssystemen und verschlüsselt eine Datei per AES.

Mit ccrypt --help bzw. man ccrypt kommt man an die Hilfeseite von ccrypt.

C:\Windows\System32>ccrypt --help
ccrypt 1.10. Secure encryption and decryption of files and streams.

Usage: ccrypt [mode] [options] [file...]
       ccencrypt [options] [file...]
       ccdecrypt [options] [file...]
       ccat [options] file...

Modes:
    -e, --encrypt         encrypt
    -d, --decrypt         decrypt
    -c, --cat             cat; decrypt files to stdout
    -x, --keychange       change key
    -u, --unixcrypt       decrypt old unix crypt files

Options:
    -h, --help            print this help message and exit
    -V, --version         print version info and exit
    -L, --license         print license info and exit
    -v, --verbose         print progress information to stderr
    -q, --quiet           run quietly; suppress warnings
    -f, --force           overwrite existing files without asking
    -m, --mismatch        allow decryption with non-matching key
    -E, --envvar var      read keyword from environment variable (unsafe)
    -K, --key key         give keyword on command line (unsafe)
    -k, --keyfile file    read keyword(s) as first line(s) from file
    -P, --prompt prompt   use this prompt instead of default
    -S, --suffix .suf     use suffix .suf instead of default .cpt
    -s, --strictsuffix    refuse to encrypt files which already have suffix
    -F, --envvar2 var     as -E for second keyword (for keychange mode)
    -H, --key2 key        as -K for second keyword (for keychange mode)
    -Q, --prompt2 prompt  as -P for second keyword (for keychange mode)
    -t, --timid           prompt twice for encryption keys (default)
    -b, --brave           prompt only once for encryption keys
    -y, --keyref file     encryption key must match this encrypted file
    -r, --recursive       recurse through directories
    -R, --rec-symlinks    follow symbolic links as subdirectories
    -l, --symlinks        dereference symbolic links
    -T, --tmpfiles        use temporary files instead of overwriting (unsafe)
    --                    end of options, filenames follow

Wichtigste Funktionen

  • ccrypt Dateiname verschlüsselt die übergebene Datei, fragt das Passwort interaktiv ab. Über den Parameter -K kann das Passwort auch übergeben werden.
  • ccrypt -d Dateiname.cpt entschlüsselt die übergebene Datei, fragt das Passwort interaktiv ab. -d muss zum Verschlüsseln angegeben werden, sonst wird die verschlüsselte Datei erneut verschlüsselt.

Emacs Einbindung

ccrypt kann auch in Emacs eingebunden werden, Details dazu unter http://ccrypt.sourceforge.net/#emacs. Die mitgelieferte Lisp Datei habe ich in einen Unterordner meines Emacs-Verzeichnisses gelegt und lade diese in der .emacs:

;; CCrypt Support
(setq load-path (cons "C:/Programme/emacs-24.3/myLisp/ccrypt" load-path))
(require 'ps-ccrypt "ps-ccrypt.el")

Lade ich jetzt eine verschlüsselte Datei, so fragt Emacs nach dem Passwort und entschlüsselt den Inhalt im Buffer. Auf der Dateiablage bleibt die Datei verschlüsselt.

Uwe

Uwe Ziegenhagen likes LaTeX and Python, sometimes even combined. Do you like my content and would like to thank me for it? Consider making a small donation to my local fablab, the Dingfabrik Köln. Details on how to donate can be found here Spenden für die Dingfabrik.

More Posts - Website