Skip to content

Instantly share code, notes, and snippets.

@cheuerde
cheuerde / sed_1liner.txt
Created December 3, 2015 21:11
SED 1-liner
# Stolen from here: http://www.pement.org/sed/sed1line.txt
-------------------------------------------------------------------------
USEFUL ONE-LINE SCRIPTS FOR SED (Unix stream editor) Dec. 29, 2005
Compiled by Eric Pement - pemente[at]northpark[dot]edu version 5.5
Latest version of this file (in English) is usually at:
http://sed.sourceforge.net/sed1line.txt
http://www.pement.org/sed/sed1line.txt
@cheuerde
cheuerde / inra_glmm.r
Last active October 22, 2017 04:22
Animal Model in INLA (R-INLA) - GLMM
# Claas Heuer, November 2015
# install the package
install.packages("INLA", repos="http://www.math.ntnu.no/inla/R/stable")
# run a test on BGLR data
library(INLA)
library(BGLR)
data(wheat)
@cheuerde
cheuerde / powerline_setup.sh
Last active August 31, 2023 21:52
Powerline on Debian and Centos for BASH, VIM and TMUX
# Claas Heuer, November 2015
#
# Setup Powerline on Debian and Centos for BASH, VIM and TMUX
# source: https://fedoramagazine.org/add-power-terminal-powerline/
# install on debian
sudo apt-get install python-pip
sudo apt-get install powerline
@cheuerde
cheuerde / paper_skeleton.txt
Last active March 26, 2017 13:42
Paper sekelton in Markdown - for use with pandoc. Export to Latex, PDF and Microsoft Word docx
[//]: # (Claas Heuer, November 2015)
[//]: # (Run pandoc like this)
[//]: # (pandoc --filter pandoc-crossref -s -S --bibliography references.bib paper_skeleton.txt -o test.docx)
[//]: # (pandoc --filter pandoc-crossref -s -S --bibliography references.bib paper_skeleton.txt -o test.pdf)
# First Section {#sec:first_section}
This is the first section and we are writing an equation that we want to reference to later in
the document:
@cheuerde
cheuerde / fw_to_csv.sh
Last active October 29, 2015 18:53
Fixed Width File to CSV
#!/bin/bash
# Claas Heuer, October 2015
#
# requires 'littler' - sudo apt-get install littler
function fw_to_csv {
# first argument is lines to skip if there is some meta data before the actual header
local skip_lines=$1
local this_file=$2
@cheuerde
cheuerde / insert_sql.r
Last active February 8, 2022 17:51
Append data to existing SQL table from R
# Claas Heuer, October 2015
insert_sql <- function(conn, # the RJDBC connection
table, # the table in the database
dat, # an R dataframe
cols = NULL, # which columns to insert (non selected will be filled with NULL)
start_row = NULL, # from which row in 'dat' to start
end_row = NULL, # at which row in 'dat' to stop
verbose = TRUE) # print progress to the screen
@cheuerde
cheuerde / images_from_video_ffmpeg.sh
Created October 20, 2015 15:36
Extract images from video ffmpeg
# Claas Heuer, October 2015
#
# first get ffmpeg (http://superuser.com/a/865744)
sudo echo deb http://www.deb-multimedia.org stable main non-free >> /etc/apt/sources.list
sudo apt-get update
sudo apt-get install deb-multimedia-keyring
sudo apt-get update
sudo apt-get install ffmpeg
# go to video directory and extract images (http://unix.stackexchange.com/a/185879)
@cheuerde
cheuerde / docker_r.sh
Created October 14, 2015 19:22
Run a Docker container and execute program
# Claas Heuer, Oxtober 2015
#
# Helpful:
# https://docs.docker.com/installation/debian/
# https://hub.docker.com/u/rocker/
# https://hub.docker.com/_/debian/
# https://zeltser.com/docker-application-distribution/
# https://hub.docker.com/
# First install Docker: http://docs.docker.com/linux/step_one/
@cheuerde
cheuerde / progress_bar.sh
Last active October 8, 2015 20:09
Progress Bar in BASH
# Taken from here: http://stackoverflow.com/a/28044986/2748031
#!/bin/bash
# 1. Create ProgressBar function
# 1.1 Input is currentState($1) and totalState($2)
function ProgressBar {
# Process data
let _progress=(${1}*100/${2}*100)/100
let _done=(${_progress}*4)/10
let _left=40-$_done
@cheuerde
cheuerde / map.r
Last active October 13, 2015 21:06
Maximum A Posteriori Estimation
# Claas Heuer, October 2015
#
# Maximum A Posteriori Estimation
#
# Estimate mean and variance of normal iid variables
# with a normal prior on the mean
# the likelihood function = L(y;.) = y ~ N(mu, sigma) * mu ~ N(0,16)
lik <- function(par, y) {