Skip to content

Instantly share code, notes, and snippets.

View EmmanuelOga's full-sized avatar
🕹️

Emmanuel Oga EmmanuelOga

🕹️
View GitHub Profile
@EmmanuelOga
EmmanuelOga / rainbowfish_jena.clj
Created July 8, 2020 07:48
Run a Jena Server
(ns rainbowfish.jena
(:require [clojure.java.io :as io]
[rainbowfish.config :as config])
(:import [org.apache.jena.fuseki.main FusekiServer]
[org.apache.jena.system Txn]
[org.apache.jena.query DatasetFactory QueryExecutionFactory ResultSetFormatter]
[org.apache.jena.rdf.model Model ModelFactory]))
(defonce
^{:doc "Instance of the Jena server for the lifetime of the program."}
@EmmanuelOga
EmmanuelOga / uri_resolver.clj
Created July 5, 2020 06:28
Example Saxon URI resolver that can talk to BaseX.
(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])
(:import java.io.ByteArrayInputStream
@EmmanuelOga
EmmanuelOga / formatBits.ts
Created June 23, 2020 11:29
Format bits on a JS number to a string
// Applying this mask shaves off any floating point components of the numbers.
const MASK32 = 4294967295; // = Math.pow(2, 32) - 1, or 32 ones.
function formatBits(num: number) {
const out : string[] = [];
for (let bit = 31; bit >= 0; bit--) {
out.push(num & (1 << bit) ? "1" : "0");
if (bit % 8 === 0) out.push(" ");
}
out.push(` : ${num & MASK32}`);
@EmmanuelOga
EmmanuelOga / read.xq
Created June 8, 2020 05:19
Read text and/or parse XML from BaseX binary store
xquery version "3.1";
declare namespace sd = 'http://eoga.dev/sdoc';
declare function sd:read-string($path as xs:string) as xs:string {
convert:binary-to-string(db:retrieve("rainbowfish", $path), 'UTF-8')
};
declare function sd:read-xml($path as xs:string) as item() {
fn:parse-xml(sd:read-string($path))
@EmmanuelOga
EmmanuelOga / core.clj
Created May 24, 2020 06:52
minimal ring session example
(ns anillo.core
(:require [ring.adapter.jetty :refer :all]
[ring.middleware.session :refer :all]
[ring.util.response :refer :all]))
(defn handler [{session :session}]
(let [n (session :n 1)]
(-> (response (str "You have visited " n " times"))
(assoc-in [:session :n] (inc n)))))
(ns minibench.core
(:import
java.util.Random
[org.basex BaseXServer]
[org.basex.api.client ClientSession]))
(defonce server (BaseXServer. (make-array String 0)))
(def running (atom true))
@EmmanuelOga
EmmanuelOga / deps.edn
Last active April 25, 2020 10:45
Validate ShEx from Clojure usign the Shaclex scala library and Jena. Started as a port of https://github.com/weso/simpleShExScala/blob/master/src/main/scala/es/weso/simpleShEx/Main.scala
{:paths
["src" "test" "target" "resources"]
:mvn/repos
{"bintray" {:url "https://dl.bintray.com/labra/maven/"}}
:deps
{; Clojure
org.clojure/clojure {:mvn/version "1.10.1"}
@EmmanuelOga
EmmanuelOga / sdoc.rnc
Created March 24, 2020 22:55
Simple document schema
datatypes xsd = "http://www.w3.org/2001/XMLSchema-datatypes"
namespace sdoc = "https://eoga.dev/sdoc"
default namespace = "https://eoga.dev/sdoc"
# Helper to allow any markup in specific areas.
# For instance, could be used to embed SVG or other formats.
any-markup = (text | element * - sdoc:* { attribute * { text }*, any-markup* })*
start = sdoc-element-topic
@EmmanuelOga
EmmanuelOga / relaxng.java
Created January 26, 2020 23:57
RelaxNG validation with error messages
package sardina;
import com.thaiopensource.util.PropertyMapBuilder;
import com.thaiopensource.validate.Flag;
import com.thaiopensource.validate.ValidateProperty;
import com.thaiopensource.validate.ValidationDriver;
import com.thaiopensource.validate.prop.rng.RngProperty;
import com.thaiopensource.validate.rng.CompactSchemaReader;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
'use strict';
const fs = require('fs');
const data = JSON.parse(fs.readFileSync('results.json'));
const results = {};
const langs = {};
for (const obj of data.test_metadata) {