Skip to content

Instantly share code, notes, and snippets.

Avatar

Lucas Werkmeister lucaswerkmeister

View GitHub Profile
@lucaswerkmeister
lucaswerkmeister / category-download
Created Aug 19, 2019
script to download all files in a Wikimedia Commons category
View category-download
#!/bin/bash
declare -A original_params=(
[action]=query
[generator]=categorymembers
[gcmtitle]="Category:${1:?category not specified}"
[gcmtype]=file
[gcmlimit]=max
[prop]=imageinfo
[iiprop]=size
@lucaswerkmeister
lucaswerkmeister / import.js
Created Apr 12, 2019
Client-side (in-browser) import of Wikidata entities into another Wikibase installation
View import.js
async function importEntitiesFromWikidata( wikidataEntityIds ) {
const params = new URLSearchParams();
params.set( 'action', 'wbgetentities' );
params.set( 'ids', wikidataEntityIds.join( '|' ) );
params.set( 'props', [ 'labels', 'descriptions', 'aliases', 'datatype' ].join( '|' ) );
params.set( 'format', 'json' );
params.set( 'origin', '*' );
const response = await fetch( `https://www.wikidata.org/w/api.php?${ params.toString() }` ),
json = await response.json();
for ( const wikidataEntityData of Object.values( json.entities ) ) {
@lucaswerkmeister
lucaswerkmeister / wipe-ssh-agent.service
Created Mar 19, 2019
systemd user units to wipe sensitive SSH keys from the SSH agent every night
View wipe-ssh-agent.service
[Unit]
Description=Wipe sensitive SSH keys from the SSH agent
[Service]
Type=oneshot
ExecStart=/usr/bin/ssh-add -d ${HOME}/.ssh/KEY-NAME-1 ${HOME}/.ssh/KEY-NAME-2 …
# don’t fail if the key wasn’t in the SSH agent in the first place
SuccessExitStatus=1
@lucaswerkmeister
lucaswerkmeister / increment.sed
Created Feb 18, 2019
sed script to increment an integer by one
View increment.sed
#!/bin/sed -f
# if the number is not negative:
/^-/! {
# increment the last digit; mark carry with an “X”
s/9$/X/
s/8$/9/
s/7$/8/
s/6$/7/
s/5$/6/
@lucaswerkmeister
lucaswerkmeister / de.md
Created Nov 25, 2018
Wikidata For Long-Time Wikipedians elevator pitch, written at the Wikidata Train the Trainers workshop in Berlin
View de.md

Elevator Pitch: Wikidata für langjährige Wikipedianer_innen

Du arbeitest bei Wikipedia mit, oder? Okay, stell dir vor:

Im südostasiatischen Hinterhuglhapfing wurde eine neue Volkszählung durchgeführt. Artikel in der bairischen Wikipedia für alle Orte in der Region wurden schon vor Jahren angelegt – wer aktualisiert jetzt die Einwohnerzahlen?

Oder: Eine schwedische Wikipedianerin war in Feuerland im Urlaub und hat einheimische Insektenarten fotografiert. Wie landen die Fotos jetzt in den entsprechenden Wikipedia-Artikeln in fünfzehn Sprachversionen?

View 0001-Run-new-batches-as-the-submitting-user.patch
From 38a7b52a3bb2d7d08639bdf46e5f3cba446fcde2 Mon Sep 17 00:00:00 2001
From: Lucas Werkmeister <mail@lucaswerkmeister.de>
Date: Thu, 18 Oct 2018 16:12:53 +0200
Subject: [PATCH] Run new batches as the submitting user
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This adds a new table storing OAuth details for a batch, and populates
it when any new batch is created. When running commands for a batch,
@lucaswerkmeister
lucaswerkmeister / setTransaction.js
Created Jun 6, 2018
inventaire.io: set the transaction status of all items by the current user to a certain status
View setTransaction.js
/**
* Set the transaction status of all items by the current user to the given status.
*/
async function setTransaction(transaction) {
const userId = await fetch('https://inventaire.io/api/user', { credentials: 'include' })
.then(response => response.json())
.then(json => json._id);
const items = await fetch(`https://inventaire.io/api/items?action=by-users&users=${userId}`)
.then(response => response.json())
.then(json => json.items);
@lucaswerkmeister
lucaswerkmeister / filterLemmasWithSpace
Created May 26, 2018
commands to find Wikidata lemmas with a space
View filterLemmasWithSpace
#!/bin/bash
while IFS=$'\t' read -r lid language lemma; do
if [[ $lemma = *' '* ]]; then
printf '%s\t%s\t%s\n' "$lid" "$language" "$lemma"
fi
done
View packlist.md

My packlist for Wikimedia events

  • power strip („Mehrfachsteckdose“)
  • Qurious Queryboo
  • swimming trunks, on the chance that there’s a pool around (they don’t take up much room)
  • …?
@lucaswerkmeister
lucaswerkmeister / openrefine.service
Created Apr 14, 2018
systemd unit file for running OpenRefine as a system service
View openrefine.service
# /etc/systemd/system/openrefine.service
[Unit]
Description=OpenRefine data reconciliation tool
Documentation=http://openrefine.org/
[Service]
ExecStart=/opt/openrefine-2.8/refine -d %S/%p -x refine.headless=true
DynamicUser=yes
NoNewPrivileges=yes
StateDirectory=%p
You can’t perform that action at this time.