Skip to content

Instantly share code, notes, and snippets.

View knudmoeller's full-sized avatar

Knud Möller knudmoeller

View GitHub Profile
@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 / 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 / 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 / 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 / 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 ;