Skip to content

Instantly share code, notes, and snippets.

Avatar

Knud Möller knudmoeller

View GitHub Profile
View wordle_filter.py
import subprocess
# read the dictionary file:
result = subprocess.run(['egrep', '^.{5}$', "/usr/share/dict/words"], stdout=subprocess.PIPE)
words = result.stdout.decode('utf-8').splitlines()
present = ['a', 'n', 'g', 't'] # letters that we know are in the word
not_present = ['o', 'i', 's', 'e', 'u'] # letters we know are not in the word
# filter words with all() and not any()
View jq_multi_query.md
  • Input data are multiple json files in sorted/ with this minimal structure:
{
  "dump_finished": "2021-12-14T10:43:42+01:00",
  "datasets": [
    ...
  ]
}
@knudmoeller
knudmoeller / jq_multi_query.sh
Created Dec 21, 2021
Query multiple files with jq, slurp results into one large array
View jq_multi_query.sh
jq "{date: .dump_finished, count: .datasets | length}" sorted/*.json | jq -s
@knudmoeller
knudmoeller / bulk_purge.py
Created Nov 18, 2021
Bulk-purging Datasets in CKAN with ckanapi
View bulk_purge.py
from ckanapi import RemoteCKAN
import os
# require ckanapi: https://github.com/ckan/ckanapi
package_names = [
"versickerung-aus-niederschlagen-2017-umweltatlas-wfs-beb56dfa",
"versickerung-aus-niederschlagen-ohne-versiegelung-2017-umweltatlas-wfs-e4a931f6",
"versiegelung-2005-unkorrigierte-versiegelungsgrade-rasterdaten-atom-451f714b",
"versiegelung-2011-unkorrigierte-versiegelungsgrade-rasterdaten-atom-c973b948",
@knudmoeller
knudmoeller / drush_count_nodes.sh
Created Oct 21, 2020
Drush/SQL command to count number of nodes for each node type
View drush_count_nodes.sh
drush sqlq 'select count(node.nid) as node_count, node_type.type from node inner join node_type on node.type = node_type.type group by node_type.type'
@knudmoeller
knudmoeller / or_queries_for_outlook_categories.md
Last active Jan 22, 2022
Perform OR queries for categories on Microsoft Outlook for Mac
View or_queries_for_outlook_categories.md

Perform OR queries for categories on Microsoft Outlook for Mac

Bizarrely, one cannot make OR queries in Microsoft Outlook for Mac, at least not easily. For example, I want a smart folder that contains all messages tagged with either the FIS Broker category or the Dubletten category.

The way to do it non-easily is to select Raw Query as the query rule type (in Search > Advanced), and then enter a Spotlight query string. The attribute to query for categories is com_microsoft_outlook_categories. That attribute takes a numeric id - but what the hell is the id for a category like FIS Broker? Outlook doesn't tell me, so I have to go even deeper down the rabbit hole. Here is how:

@knudmoeller
knudmoeller / recent_data_updates.sh
Created Mar 11, 2020
Get the most recent data updates in Berlin's Open Data Portal
View recent_data_updates.sh
#!/bin/bash
# The CKAN Action-API endpoint:
DATENREGISTER_API_BASE="https://datenregister.berlin.de/api/3/action/"
# Query filtering datasets that came in through the FIS-Broker harvester
QUERY="berlin_source:harvest-fisbroker"
# date_updated refers to the when the data (not the metadata) was updated last
SORT="date_updated+desc"
@knudmoeller
knudmoeller / dcat-catalog-lastpage.sh
Last active Jan 6, 2020
bash command to retrieve index of last page for DCAT catalog endpoint
View dcat-catalog-lastpage.sh
curl ${BASE_URI}/catalog.jsonld | jq -r '.[] | select(."@id" | endswith("/catalog.jsonld?page=1")) | ."http://www.w3.org/ns/hydra/core#lastPage" | .[0]."@value" | split("=") | .[1]'
@knudmoeller
knudmoeller / unescape.rb
Created Jan 3, 2020
Unescape URI-escaped file line by line to STDOUT
View unescape.rb
require 'cgi'
filename = ARGV[0]
File.open(filename).each { |line| puts CGI.unescape(line) }
@knudmoeller
knudmoeller / victoriapark_tree.geojson
Created Oct 26, 2019
Bäume im Viktoriapark in Berlin
View victoriapark_tree.geojson
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.