Skip to content

Instantly share code, notes, and snippets.

@josephguillaume
josephguillaume / Index.ttl
Last active April 11, 2023 09:29
Pandoc json to json-ld
@prefix : <#>.
@prefix ex: <https://example.com/>.
@prefix : <./>.
<_:b0>
ex:blocks ( <_:b1> <_:b4> ); ex:meta <_:b9>; ex:pandoc-api-version ( 1 17 5 4 ).
<_:b1> a ex:Header; ex:attr :subject; ex:inline <_:b3>; ex:level 1 .
<_:b2> ex:about "https://example.com/subject".
@josephguillaume
josephguillaume / solid_request.R
Last active December 12, 2021 03:53
Login to an Identity Provider and request resource from a Solid Pod using DPoP
# Login to an Identity Provider and request resource from a Solid Pod using DPoP
# Following https://solid.github.io/solid-oidc/primer/
library(httr2)
library(jsonlite)
library(jose)
# httr2 uses req_oauth_{name} to cache access tokens from oauth_flow_{name}
# - we define req_oauth_solid_dpop
# - oauth_client has to be called manually. We instead register a client dynamically with the IDP
@josephguillaume
josephguillaume / getBoundsZoomLevel.R
Created July 26, 2018 14:53
Calculate zoom level
# Translated from https://stackoverflow.com/questions/6048975/google-maps-v3-how-to-calculate-the-zoom-level-for-a-given-bounds
getBoundsZoomLevel=function(bounds, mapDim) {
WORLD_DIM = list(height=256, width= 256);
ZOOM_MAX = 21;
latRad=function(lat) {
sin = sin(lat * pi / 180);
radX2 = log((1 + sin) / (1 - sin)) / 2;
return(max(min(radX2, pi), -pi) / 2);
@josephguillaume
josephguillaume / extract_endnote.R
Created January 12, 2018 09:13
Extract Endnote references embedded in Word document
library(xml2)
library(magrittr)
#extract document
unzip(docx,files = "word/document.xml",junkpaths = T)
doc=read_xml("document.xml")
#extract field code text
refs=xml_find_all(doc,"//w:instrText")
refs_text = sapply(refs,xml_text)
@josephguillaume
josephguillaume / reittiopas.js
Last active January 13, 2018 21:53
Reittiopas bookmarklet
//https://stackoverflow.com/questions/22757908/google-calendar-render-action-template-parameter-documentation
javascript:(function(){
var times=document.querySelectorAll(".itinerary-summary-row.open .itinerary-main .itinerary-time-column .itinerary-time-column-time");
if(times.length==0) return false;
var startTime=times[0].innerHTML.replace(":","");
var endTime=times[times.length-1].innerHTML.replace(":","");
var dateSelector=document.querySelector(".time-selectors .date");
var d=new Date(parseInt(dateSelector[dateSelector.selectedIndex].value)*1000);
var date=d.toISOString().substr(0,10).replace(/-/g,"");
var dates=date+"T"+startTime+"00/"+date+"T"+endTime+"00";
@josephguillaume
josephguillaume / gr4j_transformed_optim.R
Created March 14, 2016 12:40
Parameter estimation of GR4J using transformed parameters
#Prepare data
data(Cotter)
x <- Cotter[1:1000]
#Specify gr4j model
mod0 <- hydromad(x, sma = "gr4j", routing = "gr4jrouting",transformed=TRUE)
#Use transformed parameter ranges
mod0 <- update(mod0,newpars=gr4j.transformpar(c(hydromad.getOption("gr4j"),
hydromad.getOption("gr4jrouting")
@josephguillaume
josephguillaume / delayed_delsa_hydromad.R
Created November 6, 2015 07:49
Run DELSA on separately computed sample using hydromad
library(sensitivity)
library(hydromad)
data(Cotter)
x <- Cotter[1:1000]
obj <- hydromad(x, sma = "cwi", routing = "expuh",
tau_s = c(2,100), v_s = c(0,1))
objective=hmadstat("r.squared")
incompl <- delsa(model=NULL,
par.ranges=getFreeParsRanges(obj),
samples=100,method="sobol")
library(hydromad)
################################################################################
## Prepare example data
data(Cotter)
x <- Cotter[1:1000]
## Define exact model to be used
fitt <- hydromad(DATA = x, sma = "cmd",f=0.6,e=0.166,d=220,return_state=T,
@josephguillaume
josephguillaume / aggregated_et2.R
Created May 9, 2015 08:22
Hydromad evaluation of aggregated ET v2
library(hydromad)
################################################################################
## Prepare example data
data(Cotter)
x <- Cotter[1:1000]
## Define exact model to be used
fitt <- hydromad(DATA = x, sma = "cmd",f=0.6,e=0.166,d=220,return_state=T,
@josephguillaume
josephguillaume / aggregated_et.R
Created May 9, 2015 08:18
Hydromad evaluation of aggregated ET
library(hydromad)
################################################################################
## Prepare example data
data(Cotter)
x <- Cotter[1:1000]
## Define exact model to be used
fitt <- hydromad(DATA = x, sma = "cmd",f=0.6,e=0.166,d=220,return_state=T,