# Category Archives: Text

How-tos, software recommendations, code snippets, my opinion on stuff.

Subcategories: Energy, How-tos, Git, LaTeX, Linux, Python

# How to git push to multiple remotes with one command

There are multiple questions with even more answers on this exact question at Stack Overflow. The simplest answer, which I failed to find again, looks like this. Add the following lines to your repo’s .git/config:

[alias]
pushall = !git push origin master && git push github master && git push remote3 master


Simply change remote and branch names to fit yours and from thereon, a git pushall will do all the work.

# How to use TikZ for inline polygons

The trick is to define inner sep=0pt when beginning the tikzpicture environment, as I learned from pgf bug report #172 minimum size in regular polygon fails for small length from last year. Here is a minimum working example, adapted to my use case of inline polygon symbols with roughly text height, i.e. 2ex in my case:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}

\newcommand{\poly}[2]{\tikz[inner sep=0pt] {%
\node[regular polygon,%
regular polygon sides=#1,%
regular polygon rotate=#2,%
minimum size=2ex, fill] (0,0) {};}}

\begin{document}
Triangle upwards \poly{3}{0},
triangle downward \poly{3}{180}
and diamond \poly{4}{45}.
\end{document}


This snippet yields the following result:

# How to change the default matplotlib font

The default fonts for matplotlib are set in file matplotlibrc in the folder \$USER_HOME/.matplotlib. You can find them here, depending on your operating system:

• Windows: C:\Users\YourName\.matplotlib\matplotlibrc
• Linux: /home/YourName/.matplotlib/matplotlibrc

Within the file, search for the font section, and uncomment (remove the hash symbol # at beginning of line) or add the following settings as desired. In the shown example, I set Arial as the default:

font.family         : sans-serif
#font.style          : normal
#font.variant        : normal
#font.weight         : medium
#font.stretch        : normal

# ...

#font.serif          : Times New Roman, ...
font.sans-serif     : Arial, ...
#font.cursive        : ... cursive
#font.fantasy        : ... fantasy
#font.monospace      : ... monospace


Upon the next start of the Python interpreter, your plots should be labelled with the new font.

# How to autoreload packages while using them in IPython

I use IPython to interactively use and debug code that I edit in a text editor at the same time. Unfortunately, Python does not automatically reload packages and functions after an initial import foo, simply for performance reasons.

Fortunately, there is a solution: the IPython extension autoreload does what its name says: either all (how I use it) or only selected (imported using magic function %aimport) are refreshed, whenever I hit the Enter key. Here’s a short how-i-use-it demo, involving a minimal package foo with a helloworld function bar:

In [1]: %load_ext autoreload
In [2]: %autoreload 2
In [3]: import foo
In [4]: foo.bar()
Hello World!

In [5]: !cat foo.py
def bar():
print('Hello World!\n')

In [6]: # edit foo.py in editor
In [7]: !cat foo.py
def bar():
print('Hello me!\n')

In [8]: # bar() is automagically reloaded
In [9]: foo.bar()
Hello me!


How do you get it? It’s already bundled with IPython by default! Happy hacking!

# How to use custom colours in LaTeX

I will post short minimum working examples (MWEs) of minimal LaTeX documents, showing a certain feature in action. Though the well-maintained LaTeX Wikibook is a much more extensive resource than a collection of such examples could ever be, they show directly compilable examples compared to isolated snippets.

I start simple: custom text colours, using different colour models. Shown here are RGB (0-255) and HTML (00-FF) style definitions. The text shows two different ways to access them. Bonus: these colours can be used in TikZ as well.

\documentclass{article}
\usepackage{xcolor}
\definecolor{cool}{RGB}{0, 110, 220}
\definecolor{heat}{RGB}{240, 120, 40}
\definecolor{pink}{HTML}{FF00FF}
\begin{document}
I am some \textcolor{heat}{really hot},
though \textcolor{cool}{also cold} text.
{\color{pink}Bright colors} are discouraged.
\end{document}


# How to list size of directories in current folder

Note to self, it’s deceptively simple, once one manages to read the manpages properly:

du -hd 1 /path/to/directory

If directory is the current folder, this shortens to:

du -hd 1

# Stikked – a self-hosted open source alternative to Pastebin

Ever wanted to share or loosely collaborate on a document, but did not feel save enough to put it on a public text hosting service like Pastebin?

Thanks to Ben McRedmond and Claude Hole, there is Stikked. It is a small text pasting script. It needs a webserver with PHP 5 and a MySQL database. Installation is manual, but easy and well documented. Continue reading

# Random Dilbert bookmarklet

I’m addicted to the webcomic Dilbert by Scott Adams. He publishes one comic strip a day. With its archive ranging more than twenty years back, a random function to discover new old comics would be quite handy. That is what the following code snippet does: Create a random date between January 1st 1990 and today and navigate to that day’s comic address:

javascript:function pad(n){return n<10 ? '0'+n : n} var now = Date.now(); var offset = (new Date(1990, 01, 01)).valueOf(); var rdate = new Date(offset + Math.round(Math.random() * (now-offset))); location.href = 'http://dilbert.com/strips/comic/' + rdate.getFullYear() + '-' + pad(rdate.getMonth()+1) + '-' + pad(rdate.getDate()) + '/';

Just copy the text and add it as the URL to a new bookmark called “Random Dilbert”. Whenever you click on it, it takes you to a different comic.

# How to convert video to MPEG 422 HD format for import in Lightworks Free

The best freely available video editing software for Windows is Lightworks (version 11.0.1). While it is free (as in beer), it has very restricted selection of import video formats at the moment. My camera (Canon EOS D550) delivers H.264 encoded MOV files, which—without other software—would require a 50 €/year codec license if you want to import them directly. Fortunately, I found a way to import my videos… Continue reading

# DESERTEC studies: AQUA-CSP

AQUA-CSP is one of three conceptual studies which explored different parts of the DESERTEC project, a concept which relies on solar power from the world’s desserts as a major energy source for Europe. In previous posts I already talked about the two other studies MED-CSP andTRANS-CSP, the first focused on generation, the second on transportation of the generated electricity. This article deals with the third, often overlooked, aspect if this undertaking: desalination of huge quantities of sea water. Continue reading