Skip to content

Instantly share code, notes, and snippets.

View knudmoeller's full-sized avatar

Knud Möller knudmoeller

View GitHub Profile
@knudmoeller
knudmoeller / kasabi-geography-example-district.ttl
Created February 9, 2012 22:22
Example data for a city district in the Kasabi World Geography dataset
@prefix places: <http://purl.org/ontology/places#> .
@prefix geonames: <http://www.geonames.org/ontology#> .
@prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
<http://data.kasabi.com/dataset/world-geography/cities/kreuzberg-2884163>
# this entity is a city district:
a places:District ;
@knudmoeller
knudmoeller / kasabi-geography-example-city.ttl
Created February 9, 2012 22:44
Example data for a city (Berlin) in the Kasabi World Geography dataset
@prefix places: <http://purl.org/ontology/places#> .
@prefix geonames: <http://www.geonames.org/ontology#> .
@prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
<http://data.kasabi.com/dataset/world-geography/cities/berlin-2950159>
# this entity is a city:
a places:City ;
@knudmoeller
knudmoeller / grep_sed_filtering.sh
Last active November 15, 2018 12:31
Filtering stuff with grep, sed, etc.
# From an online DCAT catalog RDF/XML, get all dcat:accessURLs (likely the ressource URLs)
wget -q -O - https://datenregister.berlin.de/catalog.rdf | grep "dcat:accessURL" | grep -o '".*"' | sed 's/"//g'
# From an online JSON Schema, make HTML <option> elements for each member of the value enum of a given property
PROP_NAME="geographical_granularity"
curl -s https://datenregister.berlin.de/schema/berlin_od_schema.json | \
jq -r ".properties.${PROP_NAME}.enum[]" | \
sed 's/^\(.*\)$/<option value="\1">\1<\/option>/g'
@knudmoeller
knudmoeller / jq_stuff.sh
Last active December 4, 2018 08:56
Recipes for jq
# zip two arrays (from https://github.com/stedolan/jq/issues/609#issuecomment-61155381)
def input:{"id":["cc-by","cc-zero"], "labels":["Creative Commons Attribution", "Creative Commons Zero"]};
def output:
.id as $ids | .labels as $labels
| reduce range(0; $labels|length) as $i
([]; . + [{ "id": $ids[$i], "label": $labels[$i] }]);
input| output
-> [{"id":"cc-by", "label":"Creative Commons Attribution"}, {"id":"cc-zero", "label":"Creative Commons Zero"}]
@knudmoeller
knudmoeller / jq_add_index.md
Last active December 4, 2018 09:36
Add an index to an array of JSON objects with jq

Add an index field to an array of objects

input data.json:

[
  {
    "foo": "bar"
  } ,
 {
@knudmoeller
knudmoeller / json2csv.md
Last active July 12, 2023 07:43
Turn a JSON array into CSV

input data.json

[
  {
    "id": 0 ,
    "foo": "bar"
  } ,
  {
    "id": 1 ,
@knudmoeller
knudmoeller / create_tar.sh
Created December 20, 2018 09:22
I keep forgetting the order of the parameters.
tar -cvzf $ARCHIVE_NAME.tgz $CONTENT_1 $CONTENT_2 ...
@knudmoeller
knudmoeller / export_ckan.rb
Last active January 10, 2019 09:56
Ruby script to generate a JSON dump of all CKAN datasets, using the CKAN API via HTTP.
# coding: utf-8
require 'json'
require 'uri'
require 'net/https'
require 'optparse'
require 'logger'
# Send an HTTP request, interprete response as JSON
# and return as Ruby object.
@knudmoeller
knudmoeller / get_editble_thing.rq
Last active March 7, 2019 16:28
Wikidata Query to find edible products of plants
SELECT ?ediblething ?ediblethingLabel WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
wd:Q158657 wdt:P171+ ?parent_taxon . # Q158657 is "Malus pumila", the tree we want to find fruit for
?ediblething
wdt:P1582 ?parent_taxon ;
wdt:P279 ?superthing .
?superthing wdt:P361 wd:Q21925565 .
}
LIMIT 100
@knudmoeller
knudmoeller / berlin_open_data_example.geojson
Last active May 16, 2019 14:41
Example Data from daten.berlin.de
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.