Skip to content

Instantly share code, notes, and snippets.

<?php
require __DIR__ . '/wmgUseGettingStarted.php'; // Modified to initialise $wmgUseGettingStarted
function getSitelinksByID( $id ) {
$url = "https://www.wikidata.org/w/api.php?format=json&action=wbgetentities&props=sitelinks&ids={$id}";
$responseBodyRaw = file_get_contents( $url );
$responseBody = json_decode( $responseBodyRaw, true );
$entity = $responseBody[ 'entities' ][ $id ];
$result = array();
@phuedx
phuedx / gist:0639a279b6efb1a71474
Created May 29, 2014 16:56
ext.guidedTour.animations.less
.fade-in-keyframes-for-direction(@direction, @dx, @dy) {
@-webkit-keyframes mwe-gt-fade-in-@{direction} {
.mwe-gt-fade-in-translate-frames(@dx, @dy);
}
@-moz-keyframes mwe-gt-fade-in-@{direction} {
.mwe-gt-fade-in-translate-frames(@dx, @dy);
}
@-o-keyframes mwe-gt-fade-in-@{direction} {
@phuedx
phuedx / bands_without_mbids.php
Created August 8, 2014 14:50
If you're in any doubt, then write an API.
<?php
function is_instance_of( $item ) {
return "CLAIM[31:{$item}]";
}
function is_instance_of_band() {
return is_instance_of( '215380' );
}
@phuedx
phuedx / firehose.py
Last active August 29, 2015 14:05
Listen to a wiki's recentchanges feed and publishes them as standardised JSON strings via a ØMQ PUB socket.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Listens to a wiki's recentchanges feed and publishes them as standardised JSON
events, converted to strings, via a ØMQ PUB socket.
Usage:
./firehose.py <api_url> <endpoint>
Options:
@phuedx
phuedx / identity.hh
Last active August 29, 2015 14:06
The Identity monad.
<?hh
type F1<Ta, Tb> = (function(Ta): Tb);
class Identity<Ta> {
public function __construct(private Ta $value) {}
public function bind<Tb>(F1<Ta, Identity<Tb>> $f): Identity<Tb> {
return $f($this->value);
}
@phuedx
phuedx / effective_tld_names.dat
Created November 5, 2014 15:07
Find the highest level part of the host that isn't a public suffix as listed at https://publicsuffix.org
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// ===BEGIN ICANN DOMAINS===
// ac : http://en.wikipedia.org/wiki/.ac
ac
com.ac
edu.ac
@phuedx
phuedx / MyAwesomeFeature.experiment
Last active August 29, 2015 14:10
Can we repurpose the Gherkin syntax to define simple experiments?
Experiment: version
Scenario:
Given the user is logged in
Then they should have a 70% chance of being "A"
And they should have a 30% chance of being "B"
@phuedx
phuedx / api.php
Created February 4, 2015 14:51
php DocThor.php --sourceDir=php-zmq zmq > api.php
<?php
/**
* zmq-API v@PACKAGE_VERSION@ Docs build by DocThor [2015-02-04]
* @package zmq
*/
/**
* @package zmq
*/
class ZMQ {
@phuedx
phuedx / wikigrok.md
Last active August 29, 2015 14:16
Notes from pairing with @MaxSem on getting WikiGrok working on mediawiki-vagrant.

Before enabling the wikidata role and provisioning set refreshonly = false in the wikidata-populate-site-tables in /path/to/mediawiki-vagrant/puppet/modules/role/manifests/wikidata.pp to ensure that SiteMatrix is up to date.

vagrant enable-role wikidata && vagrant provision

Ensure that Wikidata has appeared in the SiteMatrix (http://en.wiki.local.wmftest.net:8080/wiki/Special:SiteMatrix).

vagrant provision doesn't notice schema updates so: vagrant ssh -- foreachwiki update.php --quick

Create a property, e.g. "instance of". Make sure that it has Data type: item.

@phuedx
phuedx / wikigrok-aggregation-test.py
Last active August 29, 2015 14:17
Dumb WikiGrok claim aggregation script
import csv
import hashlib
raw_claims = open('claims.tsv', 'r')
claims = csv.DictReader(raw_claims, delimiter='\t')
aggregated_claims = {}
for claim in claims:
hash = hashlib.md5()
hash.update(claim['event_pageId'].encode('utf-8'))