Skip to content

Instantly share code, notes, and snippets.

View simongray's full-sized avatar

Simon Gray simongray

View GitHub Profile
simongray /
Created September 24, 2021 13:40
Query the DanNet pre-release dataset using SPARQL
import requests
from rdflib import Graph
# Fetch data
url = ''
r = requests.get(url)
open('dannet-expanded.ttl', 'wb').write(r.content)
# Build a graph
g = Graph()
simongray / dataurl.clj
Created June 17, 2019 10:57
Helper functions for converting a DataURL to an image and saving to a file
(defn dataurl->mime-type
"Extract the mime-type from a data URL."
(->> (str/split dataurl #",")
(re-find #":(.*?);")
(defn dataurl->image
"Extract the image data from a data URL."
simongray / dataurl.cljs
Created June 17, 2019 10:52
Conversion functions between DataURL and Blob type
;; Based on the implementations found here:
(defn dataurl->blob
(let [arr (str/split dataurl #",")
mime (second (re-find #":(.*?);" (first arr)))
bstr (js/atob (second arr))
n (count bstr)
u8arr (-> (map (fn [i] (.charCodeAt bstr i)) (range n))
(defn enumerated
(apply str (concat (interleave (drop-last 2 xs) (repeat ", "))
(interpose " og " (take-last 2 xs)))))
(println (enumerated ["a"]))
(println (enumerated ["a" "b"]))
(println (enumerated ["a" "b" "c"]))
(println (enumerated ["a" "b" "c" "d"])))