Skip to content

Instantly share code, notes, and snippets.

View Sleepingwell's full-sized avatar

Simon Knapp Sleepingwell

  • Canberra, ACT, Australia
View GitHub Profile
@Sleepingwell
Sleepingwell / Makefile
Last active January 12, 2023 03:12
A minimal example of calling a python function via a callback passed to a fortran subroutine.
.PHONY: venv
VENV_PATH=venv
TIMESTAMP_FILE=$(VENV_PATH)/.f2pytest-creation-timestamp
test: venv test.f90
. $(VENV_PATH)/bin/activate && \
python -m numpy.f2py -c test.f90 -m test
venv: $(TIMESTAMP_FILE)
@Sleepingwell
Sleepingwell / cla.md
Created July 29, 2022 00:29
CLA for apsrm

apsrm

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

# Script for extracting various data from https://doi.org/10.1371/journal.pcbi.1005697.s002
#-------------------------------------------------------------------------------
# Contact matricies for Australia
#-------------------------------------------------------------------------------
library(openxlsx)
AusOtherLocationsContactMatrix <- as.matrix(read.xlsx(
'contact_matrices_152_countries/MUestimates_other_locations_1.xlsx',
sheet='Australia'))
save(AusOtherLocationsContactMatrix,
@Sleepingwell
Sleepingwell / question-13.R
Created December 15, 2018 11:03
Datalab quiz workings
install.packages('pracma')
mb <- rbind(
c(1,1,0,0),
c(0,0,1,1),
c(1,0,1,0),
c(0,1,0,1)
)
b <- c(24, 14, 26, 12, 12, 29, 11, 30, 12)
@Sleepingwell
Sleepingwell / zlib_wrapper.cpp
Created May 6, 2016 15:03
A little wrapper around zlib. Not sure if I ever used this.
#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)
#else
@Sleepingwell
Sleepingwell / emperical_dist.cpp
Created May 6, 2016 13:44
Very basic empirical distribution (for unordered data).
#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
Sleepingwell / git_submodule_commands.md
Created December 18, 2015 03:29
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
Sleepingwell / boost_mpl_pair_sequence.cpp
Last active August 29, 2015 14:25
Create a sequence of types (std::pair in this dummy example) containing the outer product of two input sequences of types.
/*
* 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
Sleepingwell / gist:8588c5ee844ce0242d05
Created November 3, 2014 03:50
Holding a large number of SEXPs in C++
#include <vector>
#include <utility>
#include <iterator>
#include <R.h>
#include <Rdefines.h>
template<typename Iter>
SEXP makePolygon(Iter b, Iter e) {
SEXP
coords;
@Sleepingwell
Sleepingwell / gist:9612041
Created March 18, 2014 01:44
Timings of data.table Vs by for a specific problem
library(data.table)
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)),