Use Minion Pro / Myriad Pro with LaTeX on Mac

Get Sebastian Schubert’s FontPro and the LCDF Typetools:

git clone git@github.com:sebschub/FontPro.git
brew install lcdf-typetools
cd FontPro

Repeat the following commands with each font you want to install:

mkdir -p otf
cp /Library/Fonts/MinionPro-* otf
./scripts/makeall MinionPro
mkdir -p ~/Library/texmf
./scripts/install ~/Library/texmf
updmap --enable Map=MinionPro.map
./scripts/clean

Replace MinionPro with MyriadPro and others.

Run ./scripts/install /usr/local/texlive/texmf-local and use updmap-sys for system-wide installation.

To get the default Texmf installation directory, run kpsexpand '$TEXMFLOCAL' or kpsexpand '$TEXMFHOME'. See this and this for details.

Set primary monitor in Ubuntu

I use two monitors for my Ubuntu box. At some point, for whatever reason, the two monitors were swapped. I switched back in system settings. But it kept behaving strangely. When it boots up, the two were still swapped, and swapped back after I logged in. After logging in the mouse cursor strangely sticks to the border between the two monitors.

Later I found a tip here to set the primary monitor in Ubuntu and this fixed all problems.

Copy part of a Git repository to another repository with all history preserved

You want to copy part of repository A to repository B with all history of the part you copy preserved. We assume the part you want to move is within a subdirectory. This can be done in two steps.

Step 1: Retain only the part you wish to copy in repository A using history modification

Clone repository A. Detach from the upstream branches if you want to prevent accidental push to the remote repository. Remove all files except those within the subdirectory you want to separate, say some/module here:

git filter-branch --tag-name-filter cat --prune-empty --subdirectory-filter some/module -- --all

After this the content of the subdirectory some/module will be in the root of the local repository. If you want to keep it in the same directory structure as before, move it to the directory where it originally was:

git filter-branch -f --index-filter 'git ls-files -s | sed "s-\t\"*-&some/module/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' HEAD

On Mac, this won’t work because BSD sed doesn’t recognise \t – use gsed or enter Ctrl-V followed by Tab key instead of \t.

Optionally, to annotate the commit messages:

git filter-branch -f --msg-filter 'sed "s/^/[some prefix] /"' HEAD

Step 2: Merge the modified repository A to repository B

Go to repository B to which you want to move the separated subdirectory. Pull the modified version of repository A and that’s it:

git pull path/to/A HEAD

Alternative way using git-subtree

If you have git-subtree installed, the first step can be done simply by splitting the subdirectory into a new branch:

git subtree split --prefix some/module --branch some/module --annotate '[prefix to commit messages] '

Annotation is optional. If you wish to move the files back to their original directory, run the same git filter-branch above:

git filter-branch -f --index-filter 'git ls-files -s | sed "s-\t\"*-&some/module/-" | GIT_INDEX_FILE=$GIT_INDEX_FILE.new git update-index --index-info && mv "$GIT_INDEX_FILE.new" "$GIT_INDEX_FILE"' some/module

When pulling the modified repository A, be sure you pull the very branch you created by git-subtree:

git pull path/to/A some/module

Recover iPhone contacts from the iTunes backup

Locate your most recent iPhone backup created by iTunes, which will be in %AppData%\Roaming\Apple Computer\MobileSync\Backup and ~/Library/Application Support/MobileSync/Backup on Windows and Mac respectively.

Make a copy of the entire backup directory and work on the copy.

Now locate the file which contains your contacts. I worked on Mac and what I did is:

  1. to come up with a friend’s first (or last) name which is of a single word and not very common,
  2. grep the name to find out the files containing it,
  3. read each file’s first line to see if it’s an SQLite database file, which starts with the magic string SQLite format 3,
  4. load the database file using the SQLite command-line client, e.g., sqlite3 <database>, and check if there’s any table that contains the contact, which for me was a table named ZCONTACT,
  5. and identify which fields contain the name and the phone number, which in my case were ZNAME and ZKEY respectively.

To see the list of tables in a database and the schema of a table, issue the command .tables, and .schema <table>, respectively.

Once you identify the SQLite database, you simply export the contact details in the table you've just found by issuing the following commands in the SQLite console:

.header on
.mode csv
.output contacts.csv
select zname as Name, zkey as Number from zcontact order by zname;
.quit

You will find all your contacts in contacts.csv as in the comma-separated values format, which opens in Numbers or in Excel for instance.

You could also save them as an HTML file by setting the mode to HTML, e.g., .mode html, or something else as you like.

Python Subprocess usage summary

Preamble
import subprocess
cmd = ['command', 'option1', 'option2', '...']
Run a command, block until it finishes, and get the return code
returncode = subprocess.call(cmd)
Run a command, block until it finishes, and get its output to stdout and stderr and the return code
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
returncode = proc.returncode
Run a command, do not block but read the output from the process, and get the return code when it finishes
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)

import sys
output_text = ''
while True:
	output = proc.stdout.read(1)
	if output == '': break
	sys.stdout.write(output)
	output_text += output

returncode = proc.wait()
Run a command, and send the input to the process
input_text = 'some input to the process'
proc = subprocess.Popen(cmd, stdin=PIPE)
proc.communicate(input=input_text)