Skip to content

Instantly share code, notes, and snippets.

View ubermichael's full-sized avatar

Michael Joyce ubermichael

View GitHub Profile
@ubermichael
ubermichael / build.xml
Last active May 13, 2022 16:34
Example of an ant build.xml file for uploading files to eXistDb with credentials stored in a properties file
<?xml version="1.0" encoding="UTF-8"?>
<project default="xar" name="wilde" xmlns:xdb="http://exist-db.org/ant">
<description>Wilde Trials International News Archive</description>
<property name="host" value="localhost"/>
<property file="${host}.properties"/>
<path id="classpath.core">
<fileset dir="${local.dir}/lib">
<include name="*.jar"/>
@ubermichael
ubermichael / Clone all repositories
Created September 23, 2021 23:36
Clone all repositories
```shell
for u in $(hub api orgs/$ORGNAME/repos | jq '.[].ssh_url' | sed -e 's/"//g'); do echo $u; git clone "$u"; done
```
@ubermichael
ubermichael / extract.php
Created March 11, 2021 17:51
Extract text between page breaks in TEI with PHP
$nodes = $xp->query('/tei:TEI/tei:text//node()[self::text() or self::tei:pb]');
for($n = 0; $n < $nodes->length; $n++) {
$node = $nodes->item($n);
if($node instanceof DOMNode && $node->nodeType === XML_ELEMENT_NODE) {
$pageCount++;
$content = preg_replace("/[[:space:]]{2,}/u", ' ', $text) . "\n";
$fn = sprintf("%s/%s_%04d", $dir, $id, $pageCount);
file_put_contents($fn, $content);
$text = '';
}
git submodule deinit -f path/to/submodule
rm -rf .git/modules/path/to/submodule
git rm -f path/to/submodule
@ubermichael
ubermichael / gist:17e2a642c46396b07fe820fa78f99610
Created March 26, 2018 17:18
Find crap listening on port 3000.
# OS X
sudo lsof -i tcp:3000
# Older OS X - PID is second to last number.
netstat -vanp tcp | grep 3000
set_error_handler(function($number, $msg, $file, $line, $vars){
print "$msg:$file:$line\n";
});
@ubermichael
ubermichael / test.php
Created November 8, 2017 04:40
This should be surprising, but isn't.
<?php
foreach(array(true, false, null, 'a') as $a) {
var_dump($a);
switch($a) {
case true:
print "true";
break;
case null:
print "null";
@ubermichael
ubermichael / normalize.xq
Created December 9, 2016 19:38
Normalize unicode by calling java native functions in eXist 2.2 where normalize-unicode() doesn't work.
xquery version "3.0";
(:
Sadly, the eXist 2.2 normalize-unicode() function is broken. So we call out
to the java one.
:)
declare namespace normalizer = "java:java.text.Normalizer";
declare namespace form = "java:java.text.Normalizer$Form";
declare function local:normalize($string as item()) as xs:string {
Based heavily on https://gist.github.com/gmcharlt/f7e3bcb3680a5bf748aacd7e21c13175
```perl
#!/usr/bin/env perl
use 5.014;
use utf8;
use strict;
use warnings;
declare namespace xhtml="http://www.w3.org/1999/xhtml";
let $wc :=
for $p in collection('/db/apps/wilde-data/data')//xhtml:p
return count(tokenize($p, '\s'))
return sum($wc)