Skip to content

Instantly share code, notes, and snippets.

View grantmacken's full-sized avatar
🏠
Working from home

Grant MacKenzie grantmacken

🏠
Working from home
View GitHub Profile
@grantmacken
grantmacken / muURL.xqm
Last active March 8, 2023 00:13
xQuery helper functions for dealing with URLs
xquery version "3.0";
(:~
This module contains helper functions for dealing with URLs.
When receiving webmention the post parameter 'source' is a URL pointing to the
origin of the mention.
Before we get and store a sanitized version of an HTML document the url links to
we want to able to
@grantmacken
grantmacken / nightmare.t
Created January 24, 2016 01:10
tap tests nightmate and tape inoked with prove
#!/usr/bin/env node
var test = require('tape');
var Nightmare = require('nightmare');
var properties = require('properties-parser').read('./config');
var website = 'http://' + properties.NAME
test('example tap test using nightmare and tape', function (t) {
t.plan(1);
new Nightmare()
.goto(website)
@grantmacken
grantmacken / phridge.t
Created January 24, 2016 01:02
tap tests phridge with tape invoked with prove
#!/usr/bin/env node
var test = require('tape');
// var driver = require('node-phantom-simple');
var properties = require('properties-parser').read('./config');
var website = 'http://' + properties.NAME
var phridge = require("phridge");
test('example tap test using phridge and tape', function (t) {
t.plan(1);
phridge.spawn().then(function(phantom) {
@grantmacken
grantmacken / test.t
Created January 22, 2016 21:25
tapping a website with tape and phantom invoked with prove
#!/usr/bin/env node
var test = require('tape');
var phantom = require('phantom');
var properties = require('properties-parser').read('./config');
var website = 'http://' + properties.NAME
test('example tap test using phantom and tape', function (t) {
t.plan(2);
phantom.create(function (ph) {
ph.createPage(function (page) {
@grantmacken
grantmacken / styles.mk
Last active October 6, 2015 23:20
Make function get mime-type using #existdb mime-types file
# makes a shell call to node and uses cheerio to extract mimetype from
# passed in file name
# depends on cheerio node_module in reachable node path
getMimeType = $(shell node -pe "\
fs = require('fs');\
re = /$1/;\
n = require('cheerio').load(fs.readFileSync('$(EXIST_HOME)/mime-types.xml'),\
{ normalizeWhitespace: true, xmlMode: true});\
n('extensions').filter(function(i, el){\
return re.test(n(this).text());\
@grantmacken
grantmacken / controller.xql
Created February 9, 2015 17:51
controller.xql
xquery version "3.0";
declare variable $exist:path external;
declare variable $exist:resource external;
declare variable $exist:controller external;
declare variable $exist:prefix external;
declare variable $exist:root external;
import module namespace xmldb="http://exist-db.org/xquery/xmldb";
@grantmacken
grantmacken / issue.txt
Last active March 13, 2021 21:36
extract front-matter from a markdown file into vars
---
ISSUE_DATE=2015-01-14
ISSUE_LABEL="enhancement"
ISSUE_TITLE="branch selection from issue"
ISSUE_STATE="open"
ISSUE_NUMBER=2
---
A one line *summary* of what we hope to resolve.
- [x] todo task 1
@grantmacken
grantmacken / reposCreateNewRepo.sh
Created December 19, 2014 01:29
a bash function I will use to create a repo in current folder ussing github api
#!/bin/bash +x
function reposCreateNewRepo(){
local apiUrlBase='https://api.github.com'
GITHUB_ACCESS_TOKEN=$( cat ${GITHUB_ACCESS_TOKEN_LOCATION} )
PROJECT_NAME=$( echo ${PWD##*/} )
PROJECT_DESCRIPTION="website project ${PROJECT_NAME}"
local chkGitStatus=$( git status 2>/dev/null )
echo "CHECK! if ${PROJECT_NAME} under git control"
if [[ -n ${chkGitStatus} ]] ; then
@grantmacken
grantmacken / test-runner.xq
Last active August 29, 2015 14:02
LIVE browser preview testing of tests found in the tests collection as we are working on a xquery library module
xquery version "3.0";
(:~
We want LIVE browser preview testing of tests found in the tests collection
when we are working on an xquery library module
gistID: 61082e441e43653b8b75
https://gist.github.com/grantmacken/61082e441e43653b8b75
I use this with a Komodo toolbox macro which on save
uploads working file to existdb localhost server
@grantmacken
grantmacken / tests.xqm
Created May 2, 2014 00:28
using map in tests to check if node has tag-name
declare
%test:args('<a class="h-entry" href="http://microformats.org/2012/06/25/microformats-org-at-7">microformats.org at 7</a>')
%test:assertExists
%test:assertTrue
%test:assertXPath("count($result) = 1")
%test:assertXPath("local-name($result[1]) eq 'entry'")
%test:assertXPath(" 'name' = ( map(function($n) { local-name($n) }, $result[1]/*) ) ")
%test:assertXPath(" 'url' = ( map(function($n) { local-name($n) }, $result[1]/*) ) ")
function st:just-a-hyperlink($node as element()) as element() {
mf2:dispatch($node)