Skip to content

Instantly share code, notes, and snippets.

### Query to find all postcodes that reference Glasgow City as their District
### and return postcode uri, label and geocoding
### 2014-03-03
### Peter Winstanley
PREFIX admingeo: <http://data.ordnancesurvey.co.uk/ontology/admingeo/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX gaz: <http://data.ordnancesurvey.co.uk/ontology/50kGazetteer/>
PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>
PREFIX geometry: <http://data.ordnancesurvey.co.uk/ontology/geometry/>
PREFIX georss: <http://www.georss.org/georss/>
@pwin
pwin / best_practices_cluster.py
Created June 29, 2015 18:14
hierarchical clustering of docs
from __future__ import print_function
import numpy as np
import pandas as pd
import nltk
import re
import os
import codecs
from sklearn import feature_extraction
import mpld3
import requests
import matplotlib.pyplot as plt
from wordcloud import WordCloud, STOPWORDS
import sys
uris = [
'http://www.w3.org/2013/share-psi/wiki/Best_Practices/Cross_Agency_Strategy',
'http://www.w3.org/2013/share-psi/wiki/Best_Practices/High_Level_Support',
@pwin
pwin / FindLinkedFiles.bas
Created September 18, 2015 09:38
Routines for crawling a folder, finding MS Office documents, and finding external references (links) in Excel, Powerpoint or Word documents
Option Explicit
Const strLogPath As String = "C:\PathForLogFiles\"
Const crawlStart As String = "J:\StartingDirectoryPath"
'
Const MaskPP = "*.pp*"
Const MaskXL = "*.xl*"
Const MaskDoc = "*.doc*"
@pwin
pwin / splitFolder.sh
Created September 24, 2015 13:42
Linux Bash command line routine for splitting large folders into folders of up to n files [useful for Github which doesn't allow more than 1000 files per folder]
let fileCount=1000
let dirNum=1
for f in *
do
[ -d $f ] && continue
[ $fileCount -eq 1000 ] && {
dir=$(printf "%03d" $dirNum)
mkdir $dir
let dirNum=$dirNum+1
@pwin
pwin / get-filename.xquery
Last active December 14, 2015 17:19
return filename part of filepath
declare function core:get-filename($uri as xs:string) {
fn:tokenize($uri, "/")[last()]
};
@pwin
pwin / text-to-lines.xquery
Last active December 14, 2015 17:19
tokenise lines on newline
declare function core:text-to-lines($text) {
let $lines := tokenize($text, '\n')
return $lines
};
@pwin
pwin / gist:5142371
Created March 12, 2013 12:03
in an XForm submission - adding a variable value to a querystring to overcome caching etc
<xf:submission id="s2" method="get" replace="instance" targetref="instance('list')">
<xf:resource value="concat('/exist/rest/db/apps/stats21/views/report-view.xquery?t=',substring(string(digest( string( random( true ) ), 'MD5', 'hex' )), 1, 8))"/>
</xf:submission>
@pwin
pwin / select-box unique.html
Created March 12, 2013 12:06
In an XForms select1 itemset, ensure that the nodeset only contains unique values
<xf:select1 ref="instance('policeforce')/selectedforce" selection="closed" >
<xf:itemset nodeset="instance('report-transformed')/body//tr[not(td[3] = preceding-sibling::tr/td[3])]">
<xf:label ref="td[3]" />
<xf:value ref="td[3]" />
</xf:itemset>
</xf:select1>
@pwin
pwin / IATI-Activities work in progress.xquery
Last active December 17, 2015 00:59
Work in progress on IATI Activities XForm
xquery version "3.0";
declare option exist:serialize "method=xhtml media-type=text/xml indent=yes process-xsl-pi=no";
let $attribute := request:set-attribute("betterform.filter.ignoreResponseBody", "true")
(: look at https://github.com/orbeon/eXist-1.4.x/blob/master/webapp/xforms/tasks/todo-list.xml :)
let $form := <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"