Skip to content

Instantly share code, notes, and snippets.


Simon Knapp Sleepingwell

  • Canberra, ACT, Australia
View GitHub Profile


Contributor License Agreement ("Agreement") v1.1.0

Thank you for your interest in the apsrm open source Project which is being administered by CSIRO Data61. This document describes the terms under which You may contribute software, bug fixes, configuration changes, documentation, or any other materials that you send to Us related to the Project (each a "Contribution") to the Project. This contributor license agreement ("Agreement") documents the rights granted by You to Us with respect to your Contributions.

Once agreed, these terms apply not only to your initial Contribution but also to all past Contributions and subsequent Contributions by You to the Project, unless we change the terms. When we change the terms, you will be asked to sign the new version of the agreement the next time you contribute.

We appreciate your participation in our Project, and your help in improving the Project, so we want you to understand what will be done with the Contributions. This license is for your protection

View prem-to-data.R
# Script for extracting various data from
# Contact matricies for Australia
AusOtherLocationsContactMatrix <- as.matrix(read.xlsx(
Sleepingwell / question-13.R
Created Dec 15, 2018
Datalab quiz workings
View question-13.R
mb <- rbind(
b <- c(24, 14, 26, 12, 12, 29, 11, 30, 12)
Sleepingwell / zlib_wrapper.cpp
Created May 6, 2016
A little wrapper around zlib. Not sure if I ever used this.
View zlib_wrapper.cpp
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "zlib.h"
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include <fcntl.h>
# include <io.h>
# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
Sleepingwell / emperical_dist.cpp
Created May 6, 2016
Very basic empirical distribution (for unordered data).
View emperical_dist.cpp
#include "stdafx.h"
#include "emperical_dist.h"
void emperical_dist(double* vals, double* res, int* vlen, int* dlen) {
int i, j, tmp, n = *vlen;
double *valsAt, val;
for(i=0; i<*dlen; ++i, ++res){
valsAt = vals;
val = *res;
tmp = 0;
Sleepingwell /
Created Dec 18, 2015
Summary of git commands for submodules

This is based on this very informative post.

Configuration settings

  • diff.submodule = log (so you get clearer container diffs when referenced submodule commits changed).
  • fetch.recurseSubmodules = on-demand (so you are confident new referenced commits for known submodules get fetched with container updates).
  • status.submoduleSummary = true (so git status gets useful again when a referenced submodule commit changed).

Adding or cloning

  • Initial add: git submodule add
Sleepingwell / boost_mpl_pair_sequence.cpp
Last active Aug 29, 2015
Create a sequence of types (std::pair in this dummy example) containing the outer product of two input sequences of types.
View boost_mpl_pair_sequence.cpp
* A 'functor descriptor' that can be used to generate a runtime polymorphic functor
* for a set of input/ouput types. To be used to create python extensions in C++ for
* wrapping with boost::python, such that the functors can be configured in Python
* then applied to a number (greater than 1) of non-polymorphic input/output types
* in C++ (the types used in practice will not be those in first_types and second
* types, which are just for convenience).
#include <new> // placement new
Sleepingwell / gist:8588c5ee844ce0242d05
Created Nov 3, 2014
Holding a large number of SEXPs in C++
View gist:8588c5ee844ce0242d05
#include <vector>
#include <utility>
#include <iterator>
#include <R.h>
#include <Rdefines.h>
template<typename Iter>
SEXP makePolygon(Iter b, Iter e) {
Sleepingwell / gist:9612041
Created Mar 18, 2014
Timings of data.table Vs by for a specific problem
View gist:9612041
nl <- 100
stp <- 50000
ss <- stp
ss <- seq(stp, length.out=20, by=stp)
times <- sapply(ss, function(ss) {
mydata <- data.frame(
to_location_id = as.factor(sample(nl, ss, T)),
Sleepingwell / deep_thought.R
Last active Aug 29, 2015
An example how to make R code hard to find using C.
View deep_thought.R
.External('the_meaning_of_life', environment())
.External('the_meaning_of_multiple_lives', 42, environment())