Skip to content

Instantly share code, notes, and snippets.

@Klortho
Klortho / ajax-1.txt
Last active May 4, 2017 19:49
Chaining conditional jQuery promises
ajax-1
@Klortho
Klortho / 00-how-to-set-up-oxygen.md
Last active July 13, 2016 19:35
How to set up oXygen to work with any one NLM/JATS DTD

These instructions assume you already have oXygen installed.

1. Get the DTDs

In your browser, go to one of the following URLs

@Klortho
Klortho / utils.sh
Created June 19, 2016 07:16
shell script utilities, complete with unit test
#!/bin/bash
# What directory are we in?
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# TeamCity messages
teamcity () {
echo "##teamcity[message text='$*']"
}
@Klortho
Klortho / assert-close-enough.js
Last active June 23, 2016 04:59
Add `closeEnough` assertion to chai. See https://github.com/chaijs/chai/issues/89
// DO NOT USE!
// This was a quick-and-dirty attempt to handle the problem.
// Use this package, instead: https://www.npmjs.com/package/nearlyequal
/*
const assert = require('chai').assert;
@Klortho
Klortho / circular.js
Created May 25, 2016 20:00
Circular object reference in JavaScript without mutation
const Node = function(node) {
this.other = (typeof node === 'undefined') ? new Node(this) : node;
};
console.log(new Node()); //=> { other: { other: [Circular] } }
@Klortho
Klortho / args.js
Created May 11, 2016 22:14
Variable number of args in js, passing from function to function, manipulating, etc.
#!/usr/bin/env node
// Shows how to manipulate variable number of arguments, passing them
// around, etc.
// To just pass a variable number of arguments along, do this. This can be
// useful in a constructor, to pass the args to an init function, for example.
function passArgs() {
done.apply(this, arguments);
}
@Klortho
Klortho / log.js
Created May 11, 2016 21:54
log is a function that logs messages, with a simple indent feature.
// log is a function that logs messages, and has a simple indent (.enter()) and
// unindent (.exit()) feature.
//
// Usage:
// var log = require('./log.js')();
// log.exitAfter = 100;
// log.enabled = false;
var count = 0,
indent = 0;
@Klortho
Klortho / object-uid.js
Created May 10, 2016 05:01
Set a unique id property _uid on all objects.
// Generates a unique, read-only id for any object. This modifies Object.prototype,
// so should only be used for testing, within a limited scope.
// The _uid is generated for an object the first time it's accessed.
(function() {
var id = 0;
Object.defineProperty(Object.prototype, '_uid', {
// The prototype getter sets up a property on the instance. Because
// the new instance-prop masks this one, we know this will only ever
// be called at most once for any given object.
@Klortho
Klortho / ChainMapTree.py
Created May 7, 2016 05:19
Merge a list of Python dict's (or any mapping), recursively
#!/usr/bin/env python
import itertools
from itertools import chain
import operator
import sys
import pprint
from collections import abc
pp = pprint.PrettyPrinter(indent=4)
@Klortho
Klortho / 0-settings.py
Last active April 21, 2016 16:30
SettingsDeferrer - one way to implement lazy settings with overrides, in Django
#!/usr/bin/env python
from os import path, getenv
import settings_deferrer as s
# Put normal settings here, if you want, or put them all into the `fill_defaults()`
# function below. If the latter, though, you'll have to use the `s.MY_SETTING` syntax.
MY_SETTING = 'zormulon'
# ...