• Verbose LaTeX errors  

  • Vectorize photos  

    I used this technique to vectorize smartphone photos of hand-drawn pencil sketches to be included in a presentation using comic sans typeset and xkcd style charts:

     convert -channel RGB -compress None input.jpg bmp:- | potrace -s - -o output.svg
    
  • Python unbuffered  

    Pythons stdout/stderr are buffered by default, leading to weird behavior, especially when running massively parallel. Running with python -u to activates unbuffered stdout/stderr and therefore helps finding all kinds of strange bugs in such environments.

  • Profile Python  

    Profiling Python apps (e.g., app.py)

    pip3 install cProfile
    sudo apt install pyprof2calltree
    

    launch your code via:

    python3 -m cProfile -o app.cprof app.py
    
    pyprof2calltree -k -i app.cprof
    

    Note that the latter will call kcachegrind. On old versions of kcachegrind the time unit is not given directly. It should be in the Short description field of the event type and is nanoseconds on my device.

  • LaTeX continuous building  

    Working on LaTeX documents while continuously rebuilding in the background on changes and displaying can be done using latexmk:

    latexmk -pvc main.tex
    
  • Inspect binary files  

  • Generic setenv  

    Imagine you just installed a package into $PREFIX via:

    $ ./configure --prefix=$PREFIX
    $ make install
    

    To now execute the recently installed piece of software it would be cool to have a generic environment setup script:

    $ source generic-setenv.sh $PREFIX
    

    And here it is generic-setenv.sh - to be put in your $PATH:

    export PREFIX=$1
    export PATH=$PREFIX/bin:$PATH
    export LD_LIBRARY_PATH=$PREFIX/lib:$LD_LIBRARY_PATH
    export LD_LIBRARY_PATH=$PREFIX/lib64:$LD_LIBRARY_PATH
    export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig:$PKG_CONFIG_PATH
    export PKG_CONFIG_PATH=$PREFIX/lib64/pkgconfig:$PKG_CONFIG_PATH
    
  • How to clean filenames from special characters  

    I use this script (toWindowsFilename.sh) to clean my mp3 filenames:

    #!/bin/bash
    # usage: toWindowsFilename.sh '*.mp3' for dryrun
    # usage: toWindowsFilename.sh --no-dry '*.mp3' for real rename.
    DRY=1
    if [ "$1" = "--no-dry" ];
    then
      DRY=0
      input=$2
    else
      input=$1
    fi
    
    for f in $input;
    do
      new_name="$f"
    
      re[1]=" /_"
      re[2]="ä/ae"
      re[3]="ö/oe"
      re[4]="ü/ue"
      re[5]="Ä/AE"
      re[6]="Ö/OE"
      re[7]="Ü/UE"
      re[8]="ß/ss"
    
      # convert special chars
      i=1
      while [ "$i" -le "${#re[@]}" ];
      do
        new_name=`echo "$new_name" | sed -e"s/${re[i]}/g"`
        i=$((i+1))
      done
    
      # strip lasting special chars
      new_name=`echo "$new_name" | tr -cd '.A-Za-z0-9_-'`
    
      echo $new_name
      if [ "$DRY" == "0" ];
      then
        mv "$f" $new_name
      fi
    done
    

    To run it in the current directory on all mp3 files:

    toWindowsFilename.sh --no-dry '*.mp3'
    
  • cmake extract version  

    This shows a way to set the version variables in cmake by parsing the version string

    execute_process(COMMAND  mpirun --version OUTPUT_VARIABLE mpi_version_output)
    STRING(REGEX REPLACE "^.+([0-9]+)\\.([0-9]+)\\.([0-9]+)(\n.*)*$" "\\1;\\2;\\3"
      RESULT ${mpi_version_output})
    
    list(GET RESULT 0 MAJOR_VERSION)
    list(GET RESULT 1 MINOR_VERSION)
    list(GET RESULT 2 PATCH_VERSION)
    
    message(${MAJOR_VERSION})
    message(${MINOR_VERSION})
    message(${PATCH_VERSION})
    
    • copy version string into array string (1.10.2 -> 1;10;2)
    • now we can access it with the list command
  • Generate playlists  

    Recursively generate m3u files containing all music files of a directory, which is an especially useful thing to do for music libraries on smartphones without a folder player (e.g. Blackberry, Android standard player!?)

    execute in music dir:

    prepath="$(pwd)/"
    for sufpath in **/;
    do
            echo processing $sufpath
            cd "$prepath$sufpath"
            dirname=${PWD##*/}
            ls | grep -i ".*\.\(mp3\|ogg\|m4a\|wma\)\$" > "$dirname.m3u"
    done;
    
  • Flatten directory  

    To flatten a unix directory structure (indir) one can use find with -exec-parameter:

    $ find indir -iname '*.jpg' -exec cp {} outdir/ \;
    

    outdir should not be inside of indir to avoid recursion hell. If copying needs too much space generating hard links instead is a good idea:

    $ find indir -iname '*.jpg' -exec ln '{}' outdir/ \;
    

    This is especially useful when generating folders for photo slide shows.

  • Shortest clean script  

    Shortest clean up script for git using code bases:

    rm -rf *; git reset --hard
    
  • Make LaTeX \paragraph behave like a paragraph  

    - drschaf -

    Since the LaTeX command \paragraph{} doesn’t start a paragraph but a subsubsubsection environment, I spent hours in debugging the spacings of my \paragraphs.

    So I redefined the command to just look like the \paragraph command but acting like a paragraph:

    \renewcommand{\paragraph}[1]{\par\noindent\textbf{\textsf{#1}}\hspace{\parindent}}

    Written at the beginning of a paragraph, this will insert a bold non-serif text in front of the indentation.

  • Steps to create js-modules  

    Steps to perform once

    • install npm
    • install grunt-cli

      sudo npm install -g grunt-cli
      

      which gives you the opportunity to run Gruntfile.js-files by typing $ grunt. Gruntfiles are a bit like makefiles for c/c++, ants for java or rakefiles for ruby…

    • install grunt-init to automate project initialization

      sudo npm install -g grunt-init
      
    • install some grunt templates

      git clone https://github.com/gruntjs/grunt-init-commonjs.git ~/.grunt-init/commonjs --depth 1
      git clone https://github.com/gruntjs/grunt-init-gruntfile.git ~/.grunt-init/gruntfile --depth 1
      

      Steps to perform for every new module

    • create a project-folder e.g. by cloning the new projects repo from github. Then cd in this folder.
    • create the gruntfile - choose one of the following:

      • simple gruntfile:
        grunt-init gruntfile
        
      • commonjs:
        grunt-init commonjs
        
    • now let’s install all used grunt-modules and add them to package.json as development dependencies

      ( --save-dev )

      npm install grunt --save-dev
      

    Now take a look at package.json, Gruntfile.js and node_modules/. package.json stores information about the packages to install with npm install into node_modules.

    Gruntfile.js is read when typing grunt.

  • Adding 'extern' libs to python search path  

  • Editing markdown like a boss  

  • Disable selinux  

  • chrome kiosk  

    chrome kioskmode with no same origin policy (e.g. allows loading files through xss from hdd)

    $ chrome -kiosk -allow-file-access-from-files www.google.de

    allow even more cross origin with: -disable-web-security

  • Fedora packages search engine  

subscribe via RSS