ITahák

My cheatsheet of random computer-related stuff.

Bootable clone of a macOS drive (Big Sur, Monterey)

sudo asr restore --no-personalization --source / --target /Volumes/xyz --erase --verbose

See www.prosofteng.com/blog/how-to-create-a-bootable-external-hard-drive-clone-on-macos

GNU Fortran compiler

https://gcc.gnu.org/onlinedocs/gfortran

MacPorts

port selfupdate
port outdated
port upgrade outdated
port installed inactive
port uninstall inactive
port uninstall inactive and not <portname>
port echo depends:<portname>
port dependents <portname>
port installed requested and rdependentof:<portname>
port installed requested
port echo leaves
port setrequested <portname>
port unsetrequested <portname>
port uninstall --follow-dependencies leaves
port select --list python
port select --set python python34

Anaconda

conda update -n root conda … update conda itself
conda update --all … update all packages in the current environment

FEniCS in Anaconda
conda activate fenicsproject
conda deactivate

FEniCS in Docker

fenicsproject run

FEniCS

fenicsproject.org
fenics-handson.readthedocs.io … FEniCS hands-on by Jan Blechta, Roland Herzog, Jaroslav Hron, Gerd Wachsmuth 
fenics-solid-tutorial.readthedocs.io … FEniCS hand-on by Jaroslav Schmidt, Petr Pelech, Mark Dostalík, Jiří Malík

Password-less ssh

First generate an authentication key on the host you intend to run the code from:

% ssh-keygen -t rsa

During this procedure you will be prompted for a passphrase – set one or leave empty (no passphrase). Then send the contents of the file “~/.ssh/id_rsa.pub” created by the previous command to one of the networked Linux machines you wish to use:

% cat ~/.ssh/id_rsa.pub | ssh user@machine2 'cat >> .ssh/authorized_keys'

If the file “~/.ssh/authorized_keys” doesn’t exist, create it.

Now password-less ssh to the workstation should work.

screen (e.g., here)

Start screen: screen
Exit screen: exit
Detach from screen (it keeps running in the background): Ctrl+A+D
Return to screen screen -r
If multiple screens running, then screen [-d] -r [pid.]tty.host (list of screens from running screen -r)

Command line to reduce PDF file size

gs -sDEVICE=pdfwrite -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf

Gnuplot examples

set terminal png
set output 'file.png'
plot 'horiz_avg.0' using 2:1 with lines, '' using 6:1 w l, '' u 7:1 w l

Backup using rsync

Backup of home directory:

rsync -Pavvz --delete /Users/johndoe/* /Volumes/Backup/Users/johndoe/

Backup of home directory with exclusion of a directory:

rsync -Pavvz --delete --delete-excluded --exclude 'VirtualBox VMs' /Users/johndoe/* /Volumes/Backup/Users/johndoe/

Backup that involves ssh:

rsync -Pavz -e ssh --delete johndoe@machine:~/* /Volumes/Backup/Machine/

-P = --partial --progress keep partially transferred files, show progress
-a = -rlptgoD archive mode (recursive, copy symbolic links as they are, preserve permission, time, group, owner, devices)
-v = --verbose increases verbosity, -vv talks a lot
-z = --compress compresses the data on transfer
--delete delete files on receiver, that do not exist on sender

Bootable backup (from www.bombich.com/mactips/image.html)

Ditto is a command-line utility that ships with Mac OS X. Ditto preserves permissions when run as root and preserves resource forks by default. Ditto can be used to clone your system with the following step:

sudo ditto -X / /Volumes/Backup

rsync can be used to make a bootable clone as well. In addition to basic file copying, rsync also offers the ability to synchronize the source and target volumes — it can copy only the items that have changed, thus subsequent clones, or backups, are much faster. The syntax is pretty easy:

sudo rsync -xrlptgoEv --progress --delete / /Volumes/Backup

That will backup your entire drive, deleting anything from the target that is not on the source drive (synchronizing, that is). Rsync also preserves resource forks (that’s what the “E” argument is for) and will give you a bootable backup just as well as ditto. Learn more about using rsync to regularly backup your drive to a remote machine.

Linux tools

sort, uniq, tr, wc, xargs

New Linux X server restart key combination: AltGr-PrintScreen-K

ssh tunneling

Example: need to connect to lyon through praha

1. Edit /etc/hosts and change

127.0.0.1    localhost

to

127.0.0.1    localhost lyon.colorado.edu

2. Edit .ssh/config and put there

Host lyon.colorado.edu
port 4444

3. Run

ssh -X -f johndoe@praha.colorado.edu -N -L 4444:lyon.colorado.edu:22

4. Then run

ssh -X johndoe@lyon.colorado.edu

(see docs.cs.byu.edu/general/ssh_tunnels.html)

ImageMagick

Swapping colors:

convert input.jpg -fill to_color -opaque from_color output.jpg

Make a color tranparent (note jpeg’s cannot have transparent bg, need to use gif or png):

convert input.jpg -transparent color output.gif

Mercurial (mercurial.selenic.com)

~/.hgrc
$ hg init project
$ cd project
$ echo 'print("Hello")' > hello.py
$ hg add
$ hg forget
$ hg commit  OR  $ hg commit -m 'message'  NOTE  commit = ci
$ hg log
$ hg status
$ hg diff
$ hg cp a b
$ hg mv a b
$ hg log -p -r 3
$ hg update 1   NOTE   update = up
$ hg update tip
$ hg update null
$ hg identify -n
$ hg merge
$ hg resolve --list
$ hg resolve conflicting_file
$ hg resolve --mark conflicting_file
...

Paper sizes and printing

8.5×11 “letter” | 8.5×14 “legal” | 11×17 “tabloid” | 17×11 “ledger”

xdvi -paper letter|legal|tabloid|ledger file.dvi
dvips -t letter|a4 file.dvi
ps2pdf file.ps
dvipdfm -p a4 file.dvi
a2ps --medium=A4 -o file.ps file.txt
a2ps -M A4 -o file.ps file.txt

pdflatex creates pdf of correct size corresponding to specification in geometry setting.

Linux double-sided printing long-edge binding:

lpr -Palenka -o Duplex=DuplexNoTumble file.pdf

Linux double-sided printing short-edge binding:

lpr -Palenka -o Duplex=DuplexTumble file.pdf

DVDs

Handbrake or Mac The Ripper

Strings in Mail

Automatic strings in reply messages, forwarded messages, etc… – edit file:

/System/Library/Frameworks/Message.framework/Versions/B/Resources/English.lproj/Delayed.strings

HP Printer WiFi setup

First part following this YouTube video: www.youtube.com/watch?v=Rjd1ZqJ89N4 but first connect to hpsetup and then print the first network config page

Then should see it in Add printer -> Default (on OS X 10.6)

Thunderbird: specify different “Trash” folder

Linux: Edit → Preferences → Advanced – General tab → Config Editor. Get the server number # from inspecting different mail.server.server#.name values. Right click somewhere in the box, select New → String, name is mail.server.server#.trash_folder_name (with the correct value for #), value is the name of the desired trash folder (e.g. “Deleted Messages”). Restart Thunderbird.

Slow Safari

Disable DNS prefetching: defaults write com.apple.safari WebKitDNSPrefetchingEnabled -boolean false

Re-enable: defaults delete com.apple.safari WebKitDNSPrefetchingEnabled

Rebuild the LaunchServices database (clean up “Open with” drop-down menu)

sudo /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain system -domain local -domain user

UCB 7th floor printers

hp2=128.138.191.39hp3=128.138.191.40copier=128.138.191.45

Compiling on lstcluster

lstcluster.univ-lyon1.fr, 134.214.125.165, access through lstblende, lstblende.univ-lyon1.fr, 134.214.125.167

ifort -lscs -O3 -r8 -o 2phase 2phase.f90

lstblende – RAM 15.9 GB, 64 arch