Skip to content

Instantly share code, notes, and snippets.

@mp4096
mp4096 / py-help.md
Last active December 18, 2015 16:19
How to install Python and all other packages on a Windows x86-64 system
@mp4096
mp4096 / tips.md
Last active April 5, 2017 07:42
Some advice for your thesis

Some advice for your thesis

Numbers, numbers, numbers

  • Please, round all the numbers to a reasonable number of digits. In engineering, four significant digits are enough. And if you can compute 10 significant digits, you can be world-famous and earn $100.
  • If you perform any experimental measurements, compute the confidence intervals too. alpha = 0.05 is a good default value for the significance level.
  • If you have less than ca. 30 measurements, use only nonparametric statistics. If you have more than 30 samples, it is a good idea to check them for normality.
  • Correlation does not imply causation
  • Always specify units of measurements. siunitx is a great LaTeX package for this.

Do not do the same work twice

@mp4096
mp4096 / pdf2png.bat
Created November 24, 2015 17:44
Convert all PDF documents in a folder to PNG images using ImageMagick
@ echo off
for /r %%i in (*.pdf) do convert -density 1200 -resize 25%% "%%i" "%%i.png"
@mp4096
mp4096 / kewlgitlog.sh
Last active December 22, 2015 09:02
Colourful and cool git log in shell
git log --graph --full-history --all --color --date=short --pretty=format:"%x1b[0m%h%x09%x1b[33m%d%x1b[32m%x20[%ad] %x1b[0m%s %x1b[36m(%an)"
@mp4096
mp4096 / fortran-notes.md
Last active February 24, 2022 02:10
Notes on Fortran

Notes on Fortran

These are some initial impressions of Fortran 2008 as seen by a MATLAB person.

Very generally, I would say Fortran is quite similar to MATLAB (I know that it's actually the other way round). Apart from this, here are some language features that I found quite interesting/quirky/nice/annoying (in no particular order):

  • Implicit typing:
    • Implicit typing in Fortran has nothing to do with modern type inference (a-la auto in C++11)! If it is active, the compiler tries to assign types based on variable names. 😱 So it is really necessary to always use implicit none.
  • Array indexing:
    • Can be specified by the programmer, e.g. one can start indexing with 0 or even use negative indices. On the other hand: Prepare to memorise scenarios in which indices are remapped to 1:N by default and a couple of cases when indices remain the same.
    • MATLAB slices are specified as <lower bound> : <step size> : <upper bound>, whereas Fortran uses ` :
@mp4096
mp4096 / rescale.py
Created February 25, 2016 20:04
Rescale TikZ coordinates
import re
def main(filename_in, filename_out):
re_coord_pattern = "\((?P<x>[-.\d]*),(?P<y>[-.\d]*)\)"
re_coord = re.compile(re_coord_pattern)
with open(filename_in, "r") as f_in, open(filename_out, "w") as f_out:
for line in f_in:
@mp4096
mp4096 / word2pdf.ps1
Created March 31, 2016 08:42
Batch convert Word files to PDF
# Batch convert all .doc/.docx files encountered in folder and all its subfolders
# The produced PDF files are stored in the invocation folder
#
# Adapted from http://stackoverflow.com/questions/16534292/basic-powershell-batch-convert-word-docx-to-pdf
# Thanks to MFT, takabanana, ComFreek
#
# If PowerShell exits with an error, check if unsigned scripts are allowed in your system.
# You can allow them by calling PowerShell as an Administrator and typing
# ```
# Set-ExecutionPolicy Unrestricted
@mp4096
mp4096 / normalize_whitespaces_tabs.py
Created April 15, 2016 15:52
Strip trailing whitespaces and replace hard tabs
import codecs
import os
import fnmatch
def delete_if_exists(filename):
if os.path.exists(filename):
os.remove(filename)
@mp4096
mp4096 / AsyncCall.m
Created April 20, 2016 09:16
Asynchronous processes in MATLAB
function AsyncCall(arg1, arg2)
batchFileLocation = 'mybatch.bat';
cmdArgs = sprintf('""%s" "%s" "%s""', batchFileLocation, arg1, arg2);
proc = System.Diagnostics.Process();
proc.StartInfo.FileName = 'cmd.exe';
proc.StartInfo.Arguments = ['/C', cmdArgs];
proc.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
proc.Start();
end