Skip to content

Instantly share code, notes, and snippets.

View telic's full-sized avatar

Maxwell Terpstra telic

  • Victoria, BC, Canada
View GitHub Profile
@telic
telic / type.xq
Last active January 23, 2017 21:36
XQuery type name introspection
declare function local:type($item as item()?) as xs:string {
typeswitch ($item)
(: NOTE: eXist doesn't support XML Schema 1.1 types yet
case xs:dateTimeStamp return 'xs:dateTimeStamp'
:)
case xs:dateTime return 'xs:dateTime'
case xs:date return 'xs:date'
case xs:time return 'xs:time'
case xs:yearMonthDuration return 'xs:yearMonthDuration'
case xs:dayTimeDuration return 'xs:dayTimeDuration'
@telic
telic / display-map.xq
Last active February 8, 2017 03:42
Display `map(*)` contents in eXide
declare function local:display-map($m as map(*)?) as element()? {
if (exists($m)) then
<map>{
for $k in map:keys($m) return
<key name="{$k}">{
for $v in $m($k) return
typeswitch ($v)
case document-node() return <document uri="{document-uri($v)}"/>
case attribute() return <attribute name="{name($v)}">{xs:string($v)}</attribute>
case map(*) return local:display-map($v)
@telic
telic / throttle.js
Created April 24, 2017 01:30
Simple es6 throttle with leading and trailing-edge calls
function throttle(fn, threshold=250) {
let hold = false;
let trail;
let timeout = function() {
if (trail !== undefined) {
fn.apply(trail[0], trail[1]);
trail = undefined;
setTimeout(timeout, threshold)
} else {
hold = false;
@telic
telic / greedymenu.js
Created April 24, 2017 02:04
A collapsing-menu enhancement script
/* eslint-env es6 */
/**
* Greedymenu - hides menu items that don't fit in a popup menu
*
* Automatically applies to to elements with MENU_CLASS or MENU_S_CLASS
* on document load. Also exports an initialization function (window.greedymenu)
* that can be used to transform nav lists explicitly.
*
* Inspired by http://codepen.io/lukejacksonn/pen/PwmwWV/
*
@telic
telic / Preferences.sublime-settings
Last active March 21, 2019 22:12
sublime-text preferences
{
"always_show_minimap_viewport": true,
"auto_find_in_selection": true,
"copy_with_empty_selection": false,
"default_line_ending": "unix",
"drag_text": false,
"ensure_newline_at_eof_on_save": true,
"find_selected_text": false,
"folder_exclude_patterns":
[