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 / len.cpp
Created June 25, 2012 11:06
Wide-character handling in C++
#include <cstdlib>
#include <iostream>
#include <locale>
#include <stdexcept>
int main() {
std::string line;
std::string input;
std::size_t bytes = 0;
std::size_t characters = 0;
@klmr
klmr / Application.cs
Created July 10, 2012 20:57
Starting without a main method
using System;
namespace Demo {
class Application {
static Application() {
String args = Environment.CommandLine;
Console.WriteLine("Called with arguments {0}", args);
Environment.Exit(0);
}
@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
@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 / .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 / 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 / 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 / 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 / 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 / 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;