Skip to content

Instantly share code, notes, and snippets.

View pchampin's full-sized avatar

Pierre-Antoine Champin pchampin

View GitHub Profile
@pchampin
pchampin / example.ttl
Last active June 25, 2022 13:09
RDF-star "ocurrence" pattern vs. Schema.org "role" pattern
@prefix s: <http://schema.org/>.
# simple (unqualified) statement
:dr_strangelove a s:Movie ;
s:actor :peter_sellers.
# RDF-star with "ocurrence" nodes
@pchampin
pchampin / pyld.py
Last active April 3, 2022 09:17
pyld command-line tool
#!/usr/bin/env python
#
# Command-line JSON-LD processor based on PyLD
#
# Copyright © 2021-2022 Pierre-Antoine Champin <pierre-antoine@w3.org>
import argparse
import json
import sys
from urllib.parse import urljoin, urlsplit
@pchampin
pchampin / test_ref_opacity.py
Created November 15, 2020 18:43
Testing Referential Opacity in RDF* triple stores
#!/usr/bin/env python3
"""
This script checks different triple stores implementing RDF*,
to see how opaque/transparent are the terms used in embedded triples.
"""
from sys import argv, stderr
import base64
try:
import requests
except:
@pchampin
pchampin / gist:a7986233be1f158f277dbf94937a47d5
Created September 22, 2020 12:38
N3 axiomatization of builtin predicate `list:memberAt`
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>.
@prefix math: <http://www.w3.org/2000/10/swap/math#>.
@prefix : <#>.
{ (?lst 1) :memberAt ?elt } <= { ?lst rdf:first ?elt. }.
{ (?lst ?i) :memberAt ?elt } <= { ?lst rdf:first ?elt. ?i math:equalTo 1. }.
{ (?lst ?i) :memberAt ?elt } <= { ?lst rdf:rest ?rest. (?rest ?j) :memberAt ?elt. (?j 1) math:sum ?i. }.
{ ((41) 1) :memberAt 41 } => { :TEST :PASS 1 }.
{ ((41) 1.0) :memberAt 41 } => { :TEST :PASS 2 }.
//! This is an experiment on how to get rid of lifetime parameters in
//! Sopghia's Graph and Dataset traits. It demonstrates the general idea
//! on a simplified version of Triple and Graph.
//!
//! Graph iterators no longer return Graph::Triple's,
//! they return a safe abstraction around it: GuardedTRiple<'a, Graph::Triple>.
//!
//! Graph::Triple itself can be one of several options:
//! * T (where T implements Triple)
//! * *const T (where T implements Triple)
@pchampin
pchampin / object_vs_tuple_comp.py
Last active October 20, 2016 07:06
Comparing performance of comparison operators between different implementation styles in Python
from collections import namedtuple
from timeit import default_timer
from itertools import repeat
class Classic(object):
def __init__(self, a, b, c):
self.a = a
self.b = b
self.c = c
@pchampin
pchampin / vsparqlstore.py
Last active November 5, 2020 09:22
A subclass of rdflib SPARQLUpdateStore with BNode support, for Virtuoso
from rdflib import BNode, URIRef
from rdflib.plugins.stores.sparqlstore import SPARQLUpdateStore, _node_to_sparql, _node_from_result, SPARQL_NS
from uuid import uuid4
def _virtuoso_compatible_generator():
return unicode(uuid4().int % 2**61)
# monkey patch BNode to make it virtuoso compatible
BNode.__new__.func_defaults = (None, _virtuoso_compatible_generator, 'b')
@pchampin
pchampin / IterablePromise.js
Last active February 8, 2017 09:53
An extension of JS Promises with a forEach method.
/* global Promise */
/**
* An IterablePromise is used to combine the ease of use of loops,
* with the power of Promises.
*
* Assume you want to apply an asynchronous function process(),
* returning a Promise, to each item of an array ``a``,
* but wait for each element to be processed before processing the next one.
* You would do it like this:
@pchampin
pchampin / httpgen.wsgi
Created September 25, 2014 12:13
HTTP response generator
#!/usr/bin/env python
"""
This simple service is aimed at web application developers. It allows them to
specify in the URL the HTTP response they want to get, in order to test the
behaviour of client codes.
The PATH_INFO is the desired status code, optionnally followed by a custom
message, e.g.:
/200

Keybase proof

I hereby claim:

  • I am pchampin on github.
  • I am pchampin (https://keybase.io/pchampin) on keybase.
  • I have a public key whose fingerprint is BCB1 45FD 5531 F653 C422 89F0 9D1E DAEE EF98 D438

To claim this, I am signing this object: