Posts on Linux

How to fix broken MathJax fonts on Linux


Posted by Diego Assencio on 2017.08.09 under Linux (General)

If you are using Linux and your MathJax fonts look ugly, and if you are certain that MathJax is correctly configured on the webpage you are accessing (e.g. by checking that things look fine on another device or browser), then your browser is probably selecting STIX fonts which are installed on your system instead of the ones offered by MathJax. The simplest way to solve this problem is by removing these STIX fonts. On Ubuntu/Debian, this can be done with the following command:

sudo apt remove fonts-stix

You can now see if this was the root cause of the problem by reloading the affected webpage with Ctrl+F5 (this will force your browser to bypass its cache).

Comments (0) Direct link

Separating iPhone photos and videos by date on Linux


Posted by Diego Assencio on 2016.11.25 under Linux (Shell)

Unfortunately, iPhones (and iPads) do not offer the possibility of automatically grouping photos and videos by date on separate directories. If you prefer organizing your photos and videos that way, you can transfer them to your computer and then run the script below at the directory to which there were transferred; it will automatically determine the dates at which your photos and videos were created and place them in directories with names in the format YYYY-MM-DD (e.g. all photos and videos created on the 15th of January of 2016 will be placed under the directory 2016-01-15).

Before you can run the script, you need to install the mediainfo and exiv2 packages. For that, open a terminal and run:

sudo apt-get install exiv2 mediainfo

The script below can also be downloaded directly by clicking here.

#!/bin/bash

# make the script work even if the photos/videos have been renamed
IFS=$'\n'

# process the photos first
for file in $(ls *.JPG 2>/dev/null)
do
    # determine the date at which the photo was taken
    date=$(exiv2 $file 2>/dev/null | \
           grep timestamp | \
           cut -d ' ' -f 4 | \
           sed 's/:/-/g')

    if [ ! -z "$date" ]
    then
        mkdir -p $date
        mv $file $date
    else
        echo "Ignoring photo '$file' (no valid date found)"
    fi
done

# now process the videos
for file in $(ls *.MOV 2>/dev/null)
do
    # determine the date at which the video was recorded
    date=$(mediainfo --fullscan $file 2>/dev/null | \
           grep com.apple.quicktime.creationdate | \
           grep -Eo '[0-9]{4}-[0-9]{2}-[0-9]{2}')

    if [ ! -z "$date" ]
    then
        mkdir -p $date
        mv $file $date
    else
        echo "Ignoring video '$file' (no valid date found)"
    fi
done
Comments (0) Direct link

Negating globbing patterns in bash


Posted by Diego Assencio on 2015.11.12 under Linux (Shell)

Shell users often run commands with globbing patterns. For example, in the command below, the star (*) expands into a list of all files and subdirectories inside the current working directory which end with .pdf:

ls *.pdf

Bash also allows you to negate globbing patterns. For example, in the command below, the expression !(*.pdf) expands into a list of all files and subdirectories which do not end with .pdf (e.g. file.txt or song.mp3):

ls !(*.pdf)

This works for any globbing pattern. Notice that in expressions with curly braces, the negation is applied to each globbing pattern individually. To be precise, the command:

ls !({*.pdf,prefix*})

is identical to the one below:

ls {!(*.pdf),!(prefix*)}
Comments (0) Direct link