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 / mini.cpp
Created March 21, 2012 10:51
Ambiguous function call grammar
#include <iostream>
#include <iterator>
#include <string>
#include <boost/spirit/include/qi.hpp>
namespace qi = boost::spirit::qi;
template <typename Iterator>
struct mini_grammar : qi::grammar<Iterator, qi::ascii::space_type> {
@klmr
klmr / hashmap.hpp
Created March 25, 2012 17:01
Map that works with incomplete types.
#ifndef TEST_HASHMAP_HPP
#define TEST_HASHMAP_HPP
#include <vector>
namespace test {
template <typename F, typename S>
struct pair;
@klmr
klmr / failed_asserts.sh
Created March 31, 2012 21:03
Unit test harness for failed compile-time assertions
#!/bin/bash
set -e
set -u
# This script runs assertions that should fail at compile-time.
# This precludes the use of a conventional test runner. Instead, we build a
# harness and capture whether specific test cases compile successfully or
# not.
# Some preliminary definitions.
@klmr
klmr / example.cpp
Created May 15, 2012 15:54
Multicast function demo
#include <iostream>
#include "multicast.hpp"
void f(int n) {
std::cout << "f(" << n << ")\n";
}
struct g {
void operator ()(int n) {
@klmr
klmr / test.markdown
Created May 16, 2012 10:16
public-test

Test

Just a test to see whether we can get the rendered markdown via the API.

@klmr
klmr / ListNestedTypes.cs
Created May 16, 2012 13:02
List nested types
using System;
using System.Collections.Generic;
using System.Linq;
namespace CsConsole
{
class MainClass
{
static void WalkTypes(IEnumerable<Type> types, Action<Type> action) {
foreach (var nested in types)
@klmr
klmr / typeinfo.cpp
Created May 16, 2012 14:55
Runtime type information registry with C++
#include <typeinfo>
#include <iostream>
#include <vector>
#include <stdexcept>
#include <unordered_map>
struct Type {
std::string name;
std::vector<Type*> parents;
// TODO Extend by fully-qualified name (namespace) etc.
@klmr
klmr / make_array.hpp
Last active March 18, 2024 07:14
C++11 make_array function template
template <typename... T>
constexpr auto make_array(T&&... values) ->
std::array<
typename std::decay<
typename std::common_type<T...>::type>::type,
sizeof...(T)> {
return {std::forward<T>(values)...};
}
@klmr
klmr / first-approach.cs
Created June 10, 2012 10:29
Different methods of counting multiples of k
public static long CountDiv1(int a, int b, int k) {
if (k < 0)
return CountDiv1(a, b, -k);
// Adapt this if one of the bounds is exclusive.
long range = (long) b - (long) a + 1;
// Get the rough number of elements in the range.
long number = range / k;
@klmr
klmr / str.c
Created June 23, 2012 17:13
strlen test
#include <string.h>
#include <stdio.h>
int main(void) {
char * str = "hello, world";
for (int i = 0; i < strlen(str); ++i
printf("%c ", str[i]);
printf("\n");
}