Skip to content

Instantly share code, notes, and snippets.

Avatar

Jan van der Laan djvanderlaan

  • Statistics Netherlands (CBS)
  • The Netherlands
View GitHub Profile
View gtk4_custom_draw_example_with_stylus.cpp
// This example adds handling stylus input to the Custom Drawing example
// from the GTK4 Getting Started.
// See: https://docs.gtk.org/gtk4/getting_started.html#custom-drawing
#include <gtk/gtk.h>
/* Surface to store current scribbles */
@djvanderlaan
djvanderlaan / jaro.cpp
Last active Oct 14, 2015
Jaro similarity score C++ implementation with R-interface
View jaro.cpp
#include <cstring>
#include <cstdlib>
#include <R.h>
#include <Rdefines.h>
double jaro(const char* a, const char* b, double range = 0.5, double match_weight = 1.0,
double trans_weight = 1.0) {
unsigned int la = strlen(a);
unsigned int lb = strlen(b);
// create a buffers; these store for each character in a and b which have
@djvanderlaan
djvanderlaan / Vagrantfile
Created Jan 17, 2015
Vagrant setup for testing R packages with clang and UBSAN
View Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu-14.04"
config.vm.box_url = "http://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box"
@djvanderlaan
djvanderlaan / one_to_one.R
Created Dec 8, 2013
One to one matching using similarity measure
View one_to_one.R
library(lpSolve)
pairs_select <- function(x, y, w, n = 1, m = 1) {
d <- data.frame(x=as.numeric(as.factor(x)), y=as.numeric(as.factor(y)), w=w)
nx <- length(unique(d$x))
ny <- length(unique(d$y))
C <- cbind(c(d$x, d$y + nx), seq_len(nrow(d)))
C <- cbind(C, 1)
res <- lp("max", d$w, dense.const = C, const.dir = rep("<=", nx+ny),
const.rhs = c(rep(n, nx), rep(m, ny)), all.bin=TRUE, use.rw=TRUE)
@djvanderlaan
djvanderlaan / index.html
Last active Dec 15, 2015
Identity projection of map in d3.js
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="http://d3js.org/d3.v3.min.js"></script>
</head>
<body>
<div id="vis">
</div>
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<script src="http://d3js.org/d3.v3.min.js"></script>
<style>
.orbit {
stroke : #000000;