Skip to content

Instantly share code, notes, and snippets.

View simongray's full-sized avatar

Simon Gray simongray

View GitHub Profile
@simongray
simongray / dannet_rdf.py
Created September 24, 2021 13:40
Query the DanNet pre-release dataset using SPARQL
import requests
from rdflib import Graph
# Fetch data
url = 'https://github.com/kuhumcst/DanNet/releases/download/v2021.9.24/dannet-expanded.ttl'
r = requests.get(url)
open('dannet-expanded.ttl', 'wb').write(r.content)
# Build a graph
g = Graph()
@simongray
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."
[dataurl]
(->> (str/split dataurl #",")
(first)
(re-find #":(.*?);")
(second)))
(defn dataurl->image
"Extract the image data from a data URL."
@simongray
simongray / dataurl.cljs
Created June 17, 2019 10:52
Conversion functions between DataURL and Blob type
;; Based on the implementations found here: https://gist.github.com/wuchengwei/b7e1820d39445f431aeaa9c786753d8e
(defn dataurl->blob
[dataurl]
(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))
(into-array)
(js/Uint8Array.from))]
(defn enumerated
[xs]
(apply str (concat (interleave (drop-last 2 xs) (repeat ", "))
(interpose " og " (take-last 2 xs)))))
(do
(println (enumerated ["a"]))
(println (enumerated ["a" "b"]))
(println (enumerated ["a" "b" "c"]))
(println (enumerated ["a" "b" "c" "d"])))