Skip to content

Instantly share code, notes, and snippets.

@thorstenhenke
thorstenhenke / load_MNIST.R
Last active December 11, 2017 21:07 — forked from daviddalpiaz/load_MNIST.R
Load the MNIST handwritten digits dataset into R as a tidy data frame
# modification of https://gist.github.com/brendano/39760
# automatically obtains data from the web
# creates two data frames, test and train
# labels are stored in the y variables of each data frame
# can easily train many models using formula `y ~ .` syntax
# download data from http://yann.lecun.com/exdb/mnist/
download.file("http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz",
"train-images-idx3-ubyte.gz")
download.file("http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz",
@thorstenhenke
thorstenhenke / S3_func-dispatch.R
Created November 21, 2017 12:40
R S3 dispatch on more than one function argument.
# S3 dispatch on more than one function argument.
f <- function(x, y) UseMethod("f")
f.numeric <- function(x, y) UseMethod("f.numeric", y)
f.numeric.numeric <- function(x, y) cat("Type <n,n>\n")
f.numeric.character <- function(x, y) cat("Type <n,c>\n")
f.character <- function(x, y) UseMethod("f.character", y)
f.character.character <- function(x, y) cat("Type <c,c>\n")
f.character.numeric <- function(x, y) cat("Type <c,n>\n")
@thorstenhenke
thorstenhenke / iban.py
Created November 6, 2017 11:06
Checks or calculates the IBAN. TODO: implement a proper cli interface
# -*- coding: utf-8 -*-
import getopt, sys
ALPH = "abcdefghijklmnopqrstuvwxyz"
SHORT_OPT = "a:b:i:c:"
LONG_OPT = ["account-number=","bank-number=", "iban=", "coutry-code="]
def country_code(c = "DE"):
f = c.lower()[0]
@thorstenhenke
thorstenhenke / mat_mult_for_dummies.R
Last active November 6, 2017 10:32
If you are sometimes, like me, just too tired or "stupid" to multiply tqo matrices, here is a short R script that does this for you "symbolically".
row_vec <- function(x) {
n <- length(x)
matrix(x, nrow = 1, ncol = n)
}
col_vec <- function(x) {
n <- length(x)
matrix(x, nrow = n, ncol = 1)
}
@thorstenhenke
thorstenhenke / Makefile
Last active January 23, 2018 16:39
This is a Makefile for creating pdf's which highlight changes between two versions of texfile or changes in a specific docx wordfile. You can find the original version of the file on the homepage of Timothée Poisot (http://timotheepoisot.fr/2014/07/10/markdown-track-changes/)
OPTS=--standalone
all: diff.pdf comments.md
diff: diff.pdf
comments.md: src.docx
pandoc $< -o $@ --track-changes=all $(OPTS)
acc.tex: src.docx