Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View EmmanuelOga's full-sized avatar
🕹️

Emmanuel Oga EmmanuelOga

🕹️
View GitHub Profile
@EmmanuelOga
EmmanuelOga / tdb-query.json
Created November 30, 2020 09:44
A fishy unicode character in a TDB query
{
"@type": "woql:And",
"woql:query_list": [
{
"@type": "woql:QueryListElement",
"woql:index": {
"@type": "xsd:nonNegativeInteger",
"@value": 0
},
"woql:query": {
@EmmanuelOga
EmmanuelOga / schema.nquads
Created November 28, 2020 05:30
A TerminusDB request to add a schema of Topics
_:b0 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <woql:When> ;
<woql:consequent> _:b1 ;
<woql:query> _:b102 .
_:b1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <woql:And> ;
<woql:query_list> _:b12, _:b17, _:b2, _:b22, _:b27, _:b32, _:b37, _:b42, _:b47, _:b52, _:b57, _:b62, _:b67, _:b7, _:b72, _:b77, _:b82, _:b87, _:b92, _:b97 .
_:b10 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <woql:Node> ;
<woql:node> "rdfs:subClassOf" .
@EmmanuelOga
EmmanuelOga / json-ld.js
Created November 27, 2020 09:34
From JSON-LD to TriG, requires "jsonld" and "n3" npm packages.
import * as jsonld from "jsonld";
import * as n3 from "n3";
const doc = { "YOUR" : "JSONLD" };
const nquads = await jsonld.toRDF(doc, { format: "application/n-quads" });
const parser = new n3.Parser({ format: "application/n-quads" });
const writer = new n3.Writer({ format: "application/trig" });
await parser.parse(nquads, (error, quad, prefixes) => {
@EmmanuelOga
EmmanuelOga / index.md
Last active December 11, 2021 16:26
Simpler HTTP APIs

Simpler HTTP APIs

A quick note on writing HTTP APIs in an RPC style ... also sharing my enthusiasm for RDF and RDF schemas all around :-)

Typical HTTP API design

Someone put together a crazy big decision diagram explaining which status code to return under which circumstance, etc.

In practice, many HTTP service APIs work more like a Remote Procedure Call and less like a fully conforming "Hypermedia Service". Headers are usually considered "low level", used for things like caching, ETags, cookies, CORS, etc.

@EmmanuelOga
EmmanuelOga / 404.ttl
Created November 14, 2020 13:10
Home Page
@base <https://emmanueloga.com/> .
@prefix : <https://emmanueloga.com/> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix rf: <https://eoga.dev/rainbowfish#> .
@prefix schema: <http://schema.org/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
<topics/404>
a rf:topic ;
rf:title "Not Found"@en;
@EmmanuelOga
EmmanuelOga / Lanterna.kt
Last active October 19, 2020 04:33
Lanterna Demo
import com.googlecode.lanterna.TerminalPosition
import com.googlecode.lanterna.TextColor
import com.googlecode.lanterna.input.KeyType
import com.googlecode.lanterna.screen.TerminalScreen
import com.googlecode.lanterna.terminal.DefaultTerminalFactory
import com.googlecode.lanterna.terminal.swing.AWTTerminalFontConfiguration.BoldMode
import com.googlecode.lanterna.terminal.swing.SwingTerminalFontConfiguration
import java.awt.Font
import java.nio.charset.Charset
import javax.swing.JFrame
@EmmanuelOga
EmmanuelOga / lsbAndMsb.js
Last active October 20, 2020 05:48
Return least and most significant bits of a number.
function lsbMsb(bits) {
if (!bits) return {lsb: undefined, msb: undefined};
let lsb = 0;
for (; lsb < 31 && (bits & 1) === 0; bits >>= 1) {
lsb++;
}
let msb = lsb;
for (bits >>= 1; msb < 31 && bits !== 0; bits >>= 1) {
@EmmanuelOga
EmmanuelOga / no-override.cpp
Created October 12, 2020 17:44
When an override is not called because of move construction.
#include <iostream>
#include <stdexcept>
#include <utility>
struct Base {
virtual const char *test() const { return "Base!"; }
Base() = default;
Base(const Base& other) noexcept {
@EmmanuelOga
EmmanuelOga / print.cpp
Last active September 30, 2020 08:12
State of the art in printing unicode characters to the console on Windows
#include <boost/nowide/iostream.hpp>
#include <boost/nowide/convert.hpp>
using namespace std;
namespace nw = boost::nowide;
int main()
{
string str{ "书中自有黄金屋\n" };
nw::cout << str;
@EmmanuelOga
EmmanuelOga / uri-resolver.clj
Created September 29, 2020 22:28
A BaseX uri resolver
(ns rainbowfish.uri-resolver
"Extends saxon's standard URI resolver to open BaseX documents when an
URI has the `basex://` scheme."
(:gen-class
:name rainbowfish.UriResolver
:extends net.sf.saxon.lib.StandardURIResolver
:exposes-methods {resolve resolveSuper})
(:require [clojure.string :as str]
[rainbowfish.xmldb :as xmldb]
[ring.util.codec :as c])