Skip to content

Instantly share code, notes, and snippets.

View klmr's full-sized avatar
📦
Making your R code easier to reuse

Konrad Rudolph klmr

📦
Making your R code easier to reuse
View GitHub Profile
@klmr
klmr / check-md5.sh
Created October 12, 2012 11:10
Test checksum of gzipped FastQ files after download
#!/bin/bash
set -e
set -u
failed=0
for file in *.fq.gz; do
md5=$(gunzip -c "$file" | openssl md5 | cut -f2 -d " ")
gold=$(grep "${file/.gz/}" md5sums.txt | cut -f2)
if [ "$md5" != "$gold" ]; then
@klmr
klmr / gist:3752679
Created September 19, 2012 22:14
tRNA gene
TATA.\{6,\}T[AG]G[CT]..A...G.\{33,\}G[AT]TC[AG]A..C.*TTTT
@klmr
klmr / gist:3752300
Created September 19, 2012 21:14
iota iterator
template <typename T>
struct iota_iterator : std::iterator<std::random_access_iterator_tag, T> {
typedef std::iterator<std::random_access_iterator_tag, T> base_t;
typedef typename base_t::difference_type difference_type;
iota_iterator(T value = T()) : value(value) { }
iota_iterator& operator ++() {
++value;
return *this;
@klmr
klmr / MatchExample.cs
Created September 5, 2012 19:43
Simple pattern-based matcher for C#
var result = 42.Match()
.With(13, x => "thirteen")
.WithRange(13, 42, x => "between 13 and 42")
.WithRange(42, 45, x => "between 42 and 45")
.Default(x => "not found")
.Get<string>();
@klmr
klmr / range.hpp
Created September 2, 2012 15:06
Range-based for in C++
#ifndef UTIL_LANG_RANGE_HPP
#define UTIL_LANG_RANGE_HPP
#include <iterator>
namespace util { namespace lang {
namespace detail {
template <typename T>
@klmr
klmr / vertical.cpp
Created September 1, 2012 21:08
Display tabular data vertically
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <memory>
#include <sstream>
#include <stdexcept>
#include <string>
#include <vector>
@klmr
klmr / rs.r
Last active February 17, 2022 08:50
A versatile re-source file function for R
#' (Re-)source parts of a file
#'
#' \code{rs} loads, parses and executes parts of a file as if entered into the R
#' console directly (but without implicit echoing).
#'
#' @param filename character string of the filename to read from. If missing,
#' use the last-read filename.
#' @param from first line to parse.
#' @param to last line to parse.
#' @return the value of the last evaluated expression in the source file.
@klmr
klmr / .gvimrc
Created August 30, 2012 12:56
.gvimrc
" Basic settings {{{
set nocompatible
set nobackup
set ignorecase
set smartcase
set incsearch
set hlsearch
"set guifont=Consolas:h14
" Let's have a bit of fun!
@klmr
klmr / example.cs
Created July 21, 2012 10:54
Usage of ad-hoc interfaces in C#
interface Addable<T> {
T AddTo(T rhs);
}
T AddTwoThings(T lhs, T rhs) where T : Addable<T> {
return lhs.AddTo(rhs);
}
static class IntExtensions {
// Pseudo-syntax
@klmr
klmr / numbers.js
Created July 18, 2012 09:22
Add slide numbers to Google’s html5slides
var createSlideNumbering = function (skipFirstN) {
var num = 0;
$('.slides article').each(function () {
num += 1;
if (num <= skipFirstN)
return;
jQuery('<div/>', {
class: 'counter',
text: num