Skip to content

Instantly share code, notes, and snippets.

View vegarsti's full-sized avatar

Vegard Stikbakke vegarsti

View GitHub Profile
"""
A program for investigating this property of coins:
If Alice tosses a coin until she sees a head followed by a tail, and Bob tosses a coin until he sees two heads in a row,
then on average, Alice will require four tosses while Bob will require six tosses (try this at home!),
even though head-tail and head-head have an equal chance of appearing after two coin tosses.
From https://www.quantamagazine.org/20160313-mathematicians-discover-prime-conspiracy/
"""
from numpy.random import randint
from sys import argv
@vegarsti
vegarsti / Git cheatsheet.md
Last active July 31, 2018 12:29
Thoughts, tips and tricks for Git
  • Write commit messages
    • If applied, this commit will... "Change that thing"
    • i.e., git commit -m "Change that thing"
    • Use imperative. Capitalize first letter, and no periods at the end.
  • Branches and merge
    • Create new branch, do stuff, and then merge
    git branch new-branch
    git checkout new-branch
    
    
@vegarsti
vegarsti / Unix cheatsheet.md
Last active August 13, 2018 06:21
Useful Unix commands
  • scp usage
    • scp *.png server:~ Copies all png files from current folder to home directory on server (which is a key specified in config)  - scp server:~*.png ~/pics the other way around
  • printing at ifi (w/ pullprint)
    • pullprint [file] or lpr [file] -P pullprint_ricoh
    • Pullprint
  • Bash shell shortcuts (from here)
    • Ctrl + a: Start of line
    • Ctrl + e: End of line
    • Ctrl + w: Erase word

I prefer a help rule in the Makefile, like so:

   help:
        @grep -P '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
Assuming that the trimmed Makefile read:

   build: ## Build the binary

 clean: ## Clean the binary and intermediate files
if (argc != 2) {
  fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
  return 0;
}

tmux cheatsheet

  • C-b %   split horizontally
  • C-b "   split vertically
  • C-b x   Quit current pane (window?)
  • C-b o   Jump to other pane

vim cheatsheet

  • C-w C-w [file]   split horizontally; open [file]
  • C-z: put Vim in the background
  • fg: put in foreground again
  • [n]dd: delete [n] lines (n defaults to 1) (and store in clipboard)
  • O: insert line before current line and enter insert mode
  • o: Same, but after current
  • :w save
  • %s/old/new/g: replace all occurrences of old with new
  • plot(x, y) + abline(a, b, col="red", lwd=2)
  • plot(x, y, type="b", col="red", pch=19) "dotdash" med filled
  • plot(x, y, type="b", col="red") "dotdash" uten filled
  • rm(list=ls(all=TRUE)) remove stuff
  • `sapply(.., simplify='array') == unlist(lapply(..))
  • save: C-x C-s (+ enter)
  • open file: C-x C-f
  • switch to buffer: C-x b
  • meta key M is escape and left alt (option)
  • C-k: kills from cursor until end of line
  • C-/ (7) -- undo!
  • C-a start of line
  • C-e start of line
  • M-f forward one word
  • M-b back one word
  • plt.savefig(filename, bbox_inches='tight') --> get the entire plot when saved
  • Reset to factory default matplotlib style
import matplotlib as mpl
mpl.rcParams.update(mpl.rcParamsDefault)
  • plt.axes('tight') removes all space around the area of the curve
  • plt.axes('equal') ensures x-y even
  • plt.axhline(y=production_accuracy, linewidth=2, color='k', label='production') horizontal line