Skip to content

Instantly share code, notes, and snippets.

View RubenVerborgh's full-sized avatar

Ruben Verborgh RubenVerborgh

View GitHub Profile
@RubenVerborgh
RubenVerborgh / chai-as-promised-and-chai-things.coffee
Last active December 10, 2015 18:58
Chai as Promised and Chai Things didn't work nicely together.
#!/usr/bin/env mocha --compilers coffee:coffee-script --reporter spec
(require "mocha-as-promised")()
chai = require "chai"
Q = require "q"
chai.should()
chai.use require "chai-as-promised"
chai.use require "chai-things"
array = [{ a: 1 }, { b: 2 }]
arrayPromise = Q.resolve(array)
@RubenVerborgh
RubenVerborgh / chai-as-promised-performance.js
Last active December 10, 2015 21:18
Chais as Promised performance issues
#!/usr/bin/env mocha --reporter spec --timeout 5000
var chai = require("chai");
var Q = require("q");
chai.should();
chai.use(require("chai-as-promised"));
describe("The string", function() {
it("should eventually be string", function() {
'x'.should.be.a('string');
});
@RubenVerborgh
RubenVerborgh / eventually-with-flags.js
Last active December 11, 2015 01:38
Demo implementation of eventually with flags.
(function (chaiModule) {
"use strict";
// NodeJS
if (typeof require === "function" && typeof exports === "object" && typeof module === "object")
module.exports = chaiModule;
// AMD
else if (typeof define === "function" && define.amd)
define(function () { return chaiModule; });
// Other
else

Accessing data through APIs

Update: my blog post The lie of the API details the issues with current APIs.

Background: I'm a researcher in semantic hypermedia, at the moment comparing different APIs for accessing metadata for human and machine consumption.

Story: I am browsing a cultural website and want to retrieve the metadata of the object I'm looking at in a machine-readable format. The steps below are the actual steps that I've undertaken on different sites.

Example: Cooper-Hewitt museum

I'm looking at the object http://collection.cooperhewitt.org/objects/35460799/.

@RubenVerborgh
RubenVerborgh / paper.tex
Created February 8, 2014 11:15
Decrease space above copyright notice
\documentclass{sig-alternate-2013}
% Fix for copyright block height
\makeatletter
\def\@copyrightlength{2.5} % Increase this value to leave more space above copyright notice
\def\ftype@copyrightbox{8}
\def\@copyrightspace{
\@float{copyrightbox}[b]
\begin{center}
\setlength{\unitlength}{1pc}
@RubenVerborgh
RubenVerborgh / gist:9372495
Created March 5, 2014 17:47
Requesting a representation through HTTP with GZIP compression
var request = require('request'),
zlib = require('zlib');
var headers = { 'Accept-Encoding': 'gzip' };
var response = request({ url:'http://perdu.com/', headers: headers });
response.on('response', function (response) {
// decode the stream if necessary
if (response.headers['content-encoding'] === 'gzip')
response = response.pipe(zlib.createGunzip());
@RubenVerborgh
RubenVerborgh / acronyms.tex
Created December 4, 2014 09:15
Easily typeset acronyms
\usepackage{xspace}
\newcommand\Acronym[1]{%
\expandafter\def\csname#1\endcsname{{\scshape #1}\xspace}%
\expandafter\def\csname#1s\endcsname{{\scshape #1}s\xspace}%
}
\Acronym{api}
\Acronym{rest}
\Acronym{sparql}
\sparql is not a \rest \api.
# Without content negotiation, we get back an invalid content type
$ curl -LI http://rdf.ebi.ac.uk/dataset/atlas/13.07
HTTP/1.1 303 See Other
Server: Apache/2.2.15 (Red Hat)
Content-Type: text/html; charset=iso-8859-1
Date: Wed, 04 Feb 2015 11:36:31 GMT
Location: https://www.ebi.ac.uk/rdf/services/atlas/servlet/explore?uri=http://rdf.ebi.ac.uk/dataset/atlas/13.07
Transfer-Encoding: chunked
Connection: Keep-Alive
@RubenVerborgh
RubenVerborgh / fragment.trig
Last active August 29, 2015 14:21
Example Triple Pattern Fragment
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX dc: <http://purl.org/dc/terms/>
PREFIX dcterms: <http://purl.org/dc/terms/>
PREFIX dc11: <http://purl.org/dc/elements/1.1/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
@RubenVerborgh
RubenVerborgh / results.log
Created August 27, 2015 11:49
IRI resolution of different Turtle parsers
A. Resolving without leading ./ or ../
BASE http://example.org/xxx/yyy/zzz, resolving aaa/bbb/ccc
EYE http://example.org/xxx/yyy/aaa/bbb/ccc
cwm http://example.org/xxx/yyy/aaa/bbb/ccc
N3.js http://example.org/xxx/yyy/aaa/bbb/ccc
Serd http://example.org/xxx/yyy/aaa/bbb/ccc
B. Resolving with non-leading ./ or ../
BASE http://example.org/xxx/yyy/zzz, resolving aaa/./bbb/ccc