17 April, 2018

Python on the rise

In 2017 year I happily learned to program Python and became a big fan of the language. And as you may know, the language is on the rise, even though Python has its quirks. However, did you expect the rise to be that big:

Very soon it will outpace good-old PHP and some day maybe even Java. I say that is not bad for a single-threaded interpreted language in today's highly concurrent world. 😉

Here is another version of the trends, adding JavaScript and removing the still dominating Java:


29 April, 2016

Testing my "new" network using netcat (nc)

Last week, I connected my 8-wired "phone cable" of unknown quality to two CAT6 Ethernet wall plugs. The OS then claimed I now have Gigabit Ethernet.

Today I tried to verify this using netcat (see first comment). I connected my PC an Laptop to the router and started on the laptop:

nc -l -p 44444 > /dev/null

and on my PC:

yes | pv | nc 44444

Here is the result:

In the other direction is was even a bit faster. So, yes this is roughly GbE speed and I guess my cables are at least CAT5, which I did not expect.

04 December, 2015

Useful command to help tuning your WiFi antenna

WiFi throughput depends on the placement of your router and connected WiFi adapters, i.e., the position of their antennas.

I just tuned my WiFi, by testing various placements and observing the detailed signal quality in real time using the following bash command,

while sleep 0.5; do clear; iwconfig wlan1 | grep -iE "rate|quality"; done

which will continuously output the data rate and signal quality of your WiFi adapter wlan1. Note that, depending on your setup, your device name may be different, e.g., wlan0, wlan2, etc.

19 October, 2015

Enable sectioned bibliography in LaTeX/LyX under Linux

Today I switched my dissertation workplace from my corporate MacBook to my Ubuntu Linux PC at home. Nearly everything worked fine, since I already carefully defined all figures and child documents to use relative paths.

However, I got one error that puzzled me:
LaTeX Error: File `bibtopic.sty' not found
Obviously some LaTeX package was missing, which did not happen before under Linux. Now what to do -- in absence of a LaTeX package manager on Linux? 

Answer: Just use your Linux package manager!

So I did a search for "bibtex":
$ aptitude search bibtex
p   bibtex2html                - filters BibTeX files and translates
p   bibtexconv                 - BibTeX Converter                   
p   bibtexconv:i386            - BibTeX Converter                   
p   jbibtex-base               - make a bibliography for ASCII p(La)
p   kbibtex                    - BibTeX editor for KDE              
p   kbibtex:i386               - BibTeX editor for KDE              
p   libtext-bibtex-perl        - Perl extension to read and parse Bi
p   libtext-bibtex-perl:i386   - Perl extension to read and parse Bi
p   nbibtex                    - Powerful, flexible replacement for 
p   nbibtex:i386               - Powerful, flexible replacement for 
p   nbibtex-doc                - Documentation of source code for nb
p   python-bibtex              - Python interfaces to BibTeX and the
p   python-bibtex:i386         - Python interfaces to BibTeX and the
v   python2.7-bibtex           -                                    
v   python2.7-bibtex:i386      -                                    
p   texlive-bibtex-extra       - TeX Live: BibTeX additional styles 
OK, "texlive-bibtex-extra", "additional styles". This was what I was missing and installing this package fixed the problem.
$ sudo aptitude install texlive-bibtex-extra 

22 September, 2015

LaTeX \sloppy and \fussy line breaking

In my thesis, I use words like "visualization-related" a lot. Such words should not be further hyphenated, since it may look awkward.

Example: manual hyphenation

Words  break awkwardly

like visualization-rel-
ated or like visualiza-

The hyphenation for line breaking will interfere with the initial hyphenation and impair readability.

In LaTeX, the default line breaking mode is \fussy. This mode tries to present the words on each line very condensed, not allowing for the space between two words becoming too large. However, this causes problems with hyphenated words that should not be hyphenated any further. If the entire word would be moved to the next line, then the inter-word space on the current line would suddenly be too large. LaTeX then decides not to hyphenate AND not to break, but instead let the word flow over.

Example: default \fussy mode

All words break normally but
may overflow like visualization-
related or visualization-related.

The overflow can be removed by setting \sloppy mode instead of \fuzzy mode in your preabmle or locally using {\sloppy ... }. This forces overflowing words to move to the next line, but may lead to large inter-word spaces on the current line.

Example: alternative \sloppy mode

All  words  break  normally
and  without  overflow like 
visualization-related,  but
also   like   visualization-
related.   But   inter-word
space can be very large.

Getting to best of both worlds

Lately, I am writing my documents as follows:
  1. Start writing your document in \sloppy mode.
  2. Extend, rewrite, review, revise the document until it is nearly ready for publication/submission.
  3. Switch to \fuzzy mode and fix any problems manually.
Manual fixing will be mostly done by (1) rewriting a few sentences, or by (2) telling LaTeX exactly where to break.

For Option 1, just add a few words, such as a "the" or rephrase some words from short nouns to using a phrase with an "ing"-form. Exchanging verbs also helps. 

Example: rephrasing to push over hyphenated words (before and after)

All words break normally but
may overflow like visualization-
related or visualization-related.

All words break normally but
also  suffer  from  overflow

like visualization-related or

The problem is that the overflow may be pushed down, i.e., other words following long hyphenated words may not be allowed to wrap over,  due to the prioritization of inter-word spaces. In this case, LaTeX can be told where to break and thus occasionally violate the inter-word spacing rule.

Therefore, you need Option 2, the \linebreak{} command to manually wrap over while leaving the previous line justified; however awkward it may look thereafter. In LyX this special line break can be inserted via Insert > Formatting > Justified Line Break and depending on your OS it should have a hotkey you should remember. 

Example: additional line breaks (before and after)

All words break normally but
also  suffer  from  overflow
like visualization-related or

All words break normally but
also  suffer  from  overflow
like   visualization-related \linebreak{}
or visualization-related.

The broken line may suffer from larger inter-word space. You just have to find a nice compromise here. In texts with more words per line than the shown examples, additional white-space is less notable and the fixes should be easier, i.e., the overflow will not be pushed down to following words.

There is also an Option 3: Instead of manually fixing, you can wrap a paragraph with {\sloppy ... } to temporarily allow large inter-word spaces. However, I like Options 1 and 2 better.

05 September, 2015

How to fix a broken Logitech mouse that is clicking multiple times on single click

My Logitech was sending false mouse up and down events to my MacBook. I first though it was a software problem or that the mouse, which I bought as used hardware on Ebay, has some broken electronic component. Other users had similar problems. However, here is how I fixed it.

02 September, 2015

Copy & paste tabular data to tables in LyX

As it can be cumbersome to manually transfer data from an external source to a table in LyX, here is trick to speed up the process.

Let's assume the data is stored comma-separated in a text file with the following content.
Then copy&pasting (CMD+SHIFT+V or CTRL+SHIFT+V) this text into a table in LyX will only fill the first table column. However, if the data were TAB-separated as follows,
1920 1080 48 24 40 45 1920 1080 0%
1920 1080 46 23 41 46 1886 1058 3.8%
1920 1080 45 23 42 46 1890 1058 3.6%
1920 1080 44 22 43 49 1892 1078 1.6%
1920 1080 43 22 44 49 1892 1078 1.6%
1920 1080 42 21 45 51 1890 1071 2.4%
1920 1080 41 21 46 51 1886 1071 2.6%
1920 1080 40 20 48 54 1920 1080 0.0%
then LyX will nicely fill your table. This should also work for data that is copy pasted from spreadsheet applications.

If your spreadsheet does not copy&paste using TAB-separated data in the clipboard, then you can use some Vim magic. Paste the, e.g., space-separated, data into Vim and replace spaces with tabs, i.e., type :%s# #\t#gc (ENTER).

Note: Don't forget to use format-preserving paste (CMD+SHIFT+V or CTRL+SHIFT+V) instead of the normal paste in LyX (CMD+V or CTRL+V)

PS: I know that LyX also offers to import external files, but I often like to have all my text editable inside the document, e.g., to add colors, change font sizes, add footnotes, or use Math enviroments in the data.