This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setwd("c:/dir/containing/compiled/binary") | |
dyn.load("deep_thought") | |
.External('the_meaning_of_life', environment()) | |
.External('the_meaning_of_multiple_lives', 42, environment()) | |
dyn.unload("deep_thought") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <boost/iterator/iterator_categories.hpp> | |
#include <boost/iterator/transform_iterator.hpp> | |
#include <boost/range/adaptor/transformed.hpp> | |
#include <boost/range/any_range.hpp> | |
#include <boost/range/numeric.hpp> | |
#include <boost/timer/timer.hpp> | |
#include <iostream> | |
#include <fstream> | |
#include <vector> | |
#include <numeric> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <utility> | |
#include <algorithm> | |
#include <boost/ref.hpp> | |
#include <boost/type_traits/remove_reference.hpp> | |
#include <boost/iterator/iterator_facade.hpp> | |
#include <boost/range/iterator_range.hpp> | |
using namespace std; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This code is subject to the unlicense (http://unlicense.org/). | |
* | |
* I used it to compare the performance of C++ code called from R against native Julia. | |
* It is based on the blog at: | |
* | |
* http://feedly.com/e/B5JIqzW8?goback=%2Egde_77616_member_5811511767066509316#%21 | |
* (accessed on 29 Nov, 2013) | |
* | |
* The Julia equivalent is given below (just incase that link disappears). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(XML) | |
MYDATA <- readLines('candidate1.xml') | |
MYDATA <- sub("UTF-16", "UTF-8", MYDATA) | |
MYDATA <- xmlInternalTreeParse(MYDATA, asText = TRUE) | |
MYDATAlist <- xmlToList(MYDATA, addAttributes = TRUE, simplify = FALSE) | |
tmp <- MYDATAlist[names(MYDATAlist) == 'Item'] #MYDATAlist[names(MYDATAlist) != '.attrs'] | |
tmp <- lapply(tmp, function(x) tryCatch( | |
cbind(Item_ID=x$.attrs['Item_ID'], do.call(rbind, x[names(x) == "Answer_Item"]))[,1:3], | |
error=function(e) NULL | |
)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# dummy data | |
maxN <- 10 | |
listLen <- 6 | |
Ns <- sample(as.integer(maxN/2):maxN, listLen) | |
dat <- lapply(Ns, function(N) data.frame(country=sample(maxN, N), var=rnorm(N))) | |
# function that (recursively) does the merging | |
merger <- function(lst, var.name) if(length(lst) == 1) lst else merge(lst[[1]], merger(lst[-1], var.name), by=var.name, all=T) | |
# do the merge and put sensible names on the result, and fix the NAs (set to zero) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
opt.env <- new.env() | |
setOption <- function(auth_token, remaining_limit) { | |
cl <- as.list(match.call()[-1]) | |
invisible(mapply(assign, names(cl), cl, MoreArgs=list(envir=opt.env))) | |
} | |
getOption <- function(opt) if(exists(opt, envir=opt.env)) get(opt, envir=opt.env) else NA | |
#---- test --- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<!-- based example found at: http://blog.harakys.com/blog/2012/02/21/embed-markdown-into-your-html/ --> | |
<header> | |
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script> | |
<script src="https://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script> | |
<script src="https://google-code-prettify.googlecode.com/svn/loader/prettify.js"></script> | |
<script src="http://www.showdown.im/showdown/example/showdown.js"> </script> | |
<script type="text/javascript"> | |
var generateHTML = function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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: |