Skip to content

Instantly share code, notes, and snippets.

View ubermichael's full-sized avatar

Michael Joyce ubermichael

View GitHub Profile
@ubermichael
ubermichael / gist:6323890
Created August 23, 2013 20:53
Open all external links in a new window/tab. Scan all the links in an HTML document, and add target="_blank" to any that go to a different domain.
$(function(){
var hostname = window.location.hostname.replace('www.', '');
$('a').each(function(){
var link_host = $(this).attr('hostname').replace('www.', '');
if(link_host !== hostname) {
$(this).attr('target', '_blank');
}
});
});

Keybase proof

I hereby claim:

  • I am ubermichael on github.
  • I am ubermichael (https://keybase.io/ubermichael) on keybase.
  • I have a public key ASAjm4-rj1faxQCbVfkmiP5lkSRekgClKpG5wOO1mihjbwo

To claim this, I am signing this object:

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)
Based heavily on https://gist.github.com/gmcharlt/f7e3bcb3680a5bf748aacd7e21c13175
```perl
#!/usr/bin/env perl
use 5.014;
use utf8;
use strict;
use warnings;
@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 {
@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";
set_error_handler(function($number, $msg, $file, $line, $vars){
print "$msg:$file:$line\n";
});
@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
git submodule deinit -f path/to/submodule
rm -rf .git/modules/path/to/submodule
git rm -f path/to/submodule
@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 = '';
}