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 / move_or_copy.py
Last active January 29, 2024 12:36
An example of how to copy or move a bunch of files matching a specific regex with python.
# Copyright (C) 2013 Simon Knapp
#
# This program is free software; you can redistribute it and/or
# modify it under the any terms you wish.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# To run this, type:
@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 / funkster.cpp
Last active February 8, 2022 13:44
A very simple example of holding a C++ class in Python.
#include <Python.h>
struct MyClass {
int val;
MyClass(void) : val(42) {}
};
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
@Sleepingwell
Sleepingwell / gist:7445312
Last active February 11, 2021 04:23
Example of using geoalchemy.
# A simple script to load data from a shapefile into a spatialite db.
# Transfering the geometries is slow. It would probably be much faster to
# use WKB directly for the load, but I cannot get this to work.
# This is largely copied from
# https://github.com/geoalchemy/geoalchemy/blob/master/examples/spatialite.py
import os, osgeo.ogr
from sqlite3 import dbapi2 as sqlite
from sqlalchemy.orm import sessionmaker
from sqlalchemy import event, create_engine, MetaData
@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