Tips and Tricks

Some collected tips and guides for doing stuff.

SSH Proxy

Tired of using slow X-forwarding to access information that’s only available within the university network, like journal articles that KTH but not KI has access to? Use SSH as a proxy! You can use a machine in the biophysics network, e.g. login.tcblab.org. Then you use the command (won’t start a shell on the remote host):

$ ssh -N -D 127.0.0.1:8080 USERNAME@login.tcblab.org

All you have to do now is open your web browser and edit the browser’s network settings. In Firefox that is Preferences -> Advanced -> Network -> Settings. There you select “manual proxy configuration” and in the field “SOCKS Host” you enter 127.0.0.1 and select port 8080. In Google Chrome is Setting -> search for ‘proxy’ -> Open your computer’s proxy settings. In Ubuntu 18 it should look somethign like this:

When you terminate the SSH session you’ll have to revert these settings. Or you can use the add-on ProxySwitcheroo or FoxyProxy to quickly switch between different profiles or even configure it to switch automatically based on the site you visit. Another approach would be to set the SOCKS proxy as a system-wide proxy in your general network settings.

An example of usage of Git

From a watercooler discussion. This could be a starting point for a section about tips in managing repositories (local and remote).

I start from a repository called gromacs-flow-field-grid, forked from https://github.com/pjohansson/gromacs-flow-field.git. Here we are just relabelling the two repos I want to fetch from, and fetch from them.

$ git remote add gitlab https://gitlab.com/gromacs/gromacs.git
$ git fetch gitlab
$ git remote add pjohansson https://github.com/pjohansson/gromacs-flow-field.git
$ git fetch pjohansson

I need the code in the branch called flow-field-grid in pjohansson repo, let’s check the latest commits just to be sure it’s the right one.

 $ git log
 $ git log pjohansson/flow-field-grid

Here we git checkout from the branch we want the code of (the last two lines are just me manually checking that the CMakeLists.txt file for the new added directories is there).

$ git checkout  pjohansson/flow-field-grid --track
$ git log
$ ls src/gromacs/flow/
$ cat src/gromacs/flow/CMakeLists.txt

Here comes the interesting part: I want to integrate some local changes I did in src/gromacs/gmxana/gmx_energy.cpp. I would like to point out that while checkout was previously used to integrate a remote branch, now it is used to create a branch. Can you spot the difference? Yes, it’s just that -b option. Here we needed to do some manual merging, fortunately there is no major conflict, just a couple of input variables to add here and there.

$ cp ../gromacs-2022-flow-field-michele/src/gromacs/gmxana/gmx_energy.cpp src/gromacs/gmxana/
$ git diff
$ git status
$ git add src/gromacs/
$ git commit
$ git checkout -b flow-field-grid-visco
$ git push origin  flow-field-grid-visco
$ git remote -v
$ git merge gitlab/main
$ git status
$ vim src/gromacs/gmxana/gmx_energy.cpp
$ git status
$ git add src/gromacs/gmxana/gmx_energy.cpp src/gromacs/flow/flow_field.cpp src/gromacs/mdrun/md.cpp
$ git commit
$ git push origin flow-field-grid-visco

Lastly, I want to merge with the latest version of the branch containing the new deformation code (gitlab/bh-improve-deform). Here you can either use git rebase or git merge, I was convinced that merge is the safest option as it allows to easily go back to the closest pre-merge commit and basically undo it.

$ git merge --squash gitlab/bh-improve-deform
$ git commit
$ git log

Last but not least, let’s try to build Gromacs to be sure the C++ compiler is ok with the merged changes, too.

$ cd build/
$ make -j 12
$ sudo make install
$ source /usr/local/gromacs/bin/GMXRC
$ gmx help mdrun

Use latexdiff To View Changes Between LaTeX Files

If you are writing something in LaTeX, it might be useful to view changes from one version of your article or text to another (eg. when working with co-authors). This can be made easier by using the latexdiff tool, which takes two versions of your file and highlights changes between them when you compile it.

The script can be downloaded from this site: https://ctan.org/tex-archive/support/latexdiff/

After installing it, use it like this to create a pdf with your changes:

$ latexdiff old.tex new.tex > diff.tex
$ pdflatex diff.tex # or whichever LaTeX compiler you use

Combining It With Git

If you are using Git to keep track of versions of your document (which is good!), there is an extension called git-latexdiff that runs latexdiff on your commits.

Get it from this site: https://gitlab.com/git-latexdiff/git-latexdiff

To highlight changes from your current version to your previous commit, run:

$ git latexdiff HEAD^

Example Output Page

Other Short Tips