Skip to content

Instantly share code, notes, and snippets.

View jindrichmynarz's full-sized avatar

Jindřich Mynarz jindrichmynarz

View GitHub Profile
PREFIX pc: <http://purl.org/procurement/public-contracts#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
DELETE {
?s ?p ?o .
}
WHERE {
{
SELECT DISTINCT ?p
@jindrichmynarz
jindrichmynarz / marcxml_field_frequency.xquery
Last active August 29, 2015 14:15
MARCXML field and subfield frequencies
xquery version "3.0";
declare default element namespace "http://www.loc.gov/MARC21/slim";
declare option saxon:output "omit-xml-declaration=yes";
declare option saxon:output "method=text";
declare variable $records := /collection/record;
declare variable $total := count($records);
string-join(
@jindrichmynarz
jindrichmynarz / red_vs_green.py
Last active August 29, 2015 14:18
Is an image mostly red or green?
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, sys
from PIL import Image
def get_red_green_balance(filename):
im = Image.open(filename)
r, g = reduce(lambda c1, c2: [c1[0] + c2[0], c1[1] + c2[1]], im.getdata(), [0, 0])
percent = (r + g) / 100.0
@jindrichmynarz
jindrichmynarz / dcv_aggregation.ttl
Created June 5, 2015 20:10
Aggregation in the Data Cube Vocabulary using hierarchical code lists
@prefix ex: <http://example.com/> .
@prefix qb: <http://purl.org/linked-data/cube#> .
@prefix sdmx-dimension: <http://purl.org/linked-data/sdmx/2009/dimension#> .
@prefix skos: <http://www.w3.org/2004/02/skos/core#> .
# Individual observations
[] a qb:Observation;
sdmx-dimension:refPeriod <http://reference.data.gov.uk/id/gregorian-interval/2004-01-01T00:00:00/P1M> ;
ex:measure 101.1 .
@jindrichmynarz
jindrichmynarz / leaflet_with_krovak.js
Last active August 29, 2015 14:23
Leaflet.js using Křovák
var APP = {
// Definition of the Křovák projection
// EPSG:102067 instead of EPSG:5514 needs to be used with IPR's WMS.
crs: new L.Proj.CRS("EPSG:102067",
"+proj=krovak +lat_0=49.5 +lon_0=24.83333333333333 "
+ "+alpha=30.28813972222222 +k=0.9999 +x_0=0 +y_0=0 "
+ "+ellps=bessel +towgs84=589,76,480,0,0,0,0 +units=m "
+ "+no_defs",
{origin: [-951499.37, -930499.37],
// The difficult part
@jindrichmynarz
jindrichmynarz / core_test.clj
Created November 12, 2015 22:31
Example of generative testing of a SOAP API in Clojure
(ns soap-test.core-test
(:require [clojure.test :refer :all]
[clojure.test.check.generators :as gen]
[clojure.test.check.properties :as prop]
[clojure.test.check.clojure-test :refer [defspec]]
[clj-soap.core :as soap :refer [obj->soap-str]]))
; Boilerplace method required by the clj-soap library
(defmethod obj->soap-str :currency [obj argtype] (str obj))
@jindrichmynarz
jindrichmynarz / dub_techno_in_sonic_pi.rb
Created December 8, 2015 19:11
Dub techno in Sonic Pi
use_debug false
use_bpm 130
# Our mixer!
master = (ramp *range(0, 1, 0.01))
kick_volume = 1
bass_volume = 1
revbass_volume = 1
snare_volume = 0.5
hats_volume = 0.5
@jindrichmynarz
jindrichmynarz / wd_prime_ministers.rq
Created January 21, 2016 11:04
Prime ministers from Wikidata
PREFIX bd: <http://www.bigdata.com/rdf#>
PREFIX p: <http://www.wikidata.org/prop/>
PREFIX q: <http://www.wikidata.org/prop/qualifier/>
PREFIX v: <http://www.wikidata.org/prop/statement/>
PREFIX wd: <http://www.wikidata.org/entity/>
PREFIX wikibase: <http://wikiba.se/ontology#>
SELECT DISTINCT ?countryLabel ?primeMinisterLabel
WHERE {
?country p:P31 ?countryStatement .
@jindrichmynarz
jindrichmynarz / dump_one_graph_nt.sql
Created February 25, 2016 10:41
OpenLink Virtuoso procedure for dumping a graph to N-Triples
CREATE PROCEDURE dump_one_graph_nt
( IN srcgraph VARCHAR
, IN out_file VARCHAR
, IN file_length_limit INTEGER := 1000000000
)
{
DECLARE file_name VARCHAR
; DECLARE env
, ses ANY
; DECLARE ses_len
@jindrichmynarz
jindrichmynarz / time_sparql.sh
Created June 24, 2016 20:48
Compute average response time for given SPARQL query and endpoint
#!/bin/bash
#
# Compute average response time for given SPARQL query and endpoint
#
# Note: For proper benchmarking use SPARQL Query Benchmarker instead.
# <https://sourceforge.net/p/sparql-query-bm/wiki/Introduction/>
set -e
die () {