Skip to content

Instantly share code, notes, and snippets.

View leegee's full-sized avatar

Lee Goddard leegee

View GitHub Profile
jasmine.addMatchers( jasmine.XXX.customMatchers );
// This must load before any tests are run.
jasmine.XXX.customMatchers = {
toEqualNice: function(util, customEqualityTesters) {
return {
compare: function(actual, expected) {
if (expected === undefined) {
expected = '';
}
@leegee
leegee / gherkin.sublime-syntax
Last active April 6, 2016 07:22
Start of a Sublime syntax file Gherkin
%YAML1.2
---
# See http://www.sublimetext.com/docs/3/syntax.html
file_extensions:
- feature
scope: source.feature
contexts:
main:
- match: '"'
scope: punctuation.definition.string.begin.feature
@leegee
leegee / base-with-log4js.js
Created March 30, 2016 08:35
Init a log4js logger with category auto-set to 'module' name, via base prototype.
module.exports = Base;
function Base(category) {
try {
category = category || new Error().stack.match(/Base\.(\w+)/)[1];
}
finally {
if (!category) {
throw new Error('Base requires its sub-class to supply a logging-category argument! ');
}
}
/* eslint-env node, es6 */
'use strict';
/* @param {object|string} _logger - an instance of Log4js/object with a `log` method. If a string, should be a category (see Log4js.getLogger(category)).
@example
logger = require('logger').getLogger( gutil );
*/
Base.prototype.ERROR = [];
Base.errorNames = [
'PageContext', 'NotYetSupported', 'NaN', 'ColDefPropertyNotFound',
'ColDefValueNotFound', 'InvalidArgument', 'MissingArgument',
'UnknownError', 'InvalidCssSelector'
];
Base.errorNames.forEach(function(errName) {
Base.prototype.ERROR[errName] = function (message) {
Error.captureStackTrace(this, this.constructor);
@leegee
leegee / base.js
Created June 23, 2016 07:27
log4js base
// base.js
function Base(options) {
var category;
// https://github.com/v8/v8/wiki/Stack-Trace-API
try {
category = ((new Error).stack.split('\n'))[2].match(/^\s+at\sBase\.(\w+)/)[1];
}
catch (e) {
try {
@leegee
leegee / cache.js
Created November 8, 2016 09:21
Node DNS caching with Promises
var dns = require('dns'), cache = {};
dns._lookup = dns.lookup;
dns.lookup = function(domain) {
return new Promise( (resolve, reject) => {
var key = domain;
if (key in cache) {
var ip = cache[key],
ipv = ip.indexOf('.') !== -1 ? 4 : 6;
@leegee
leegee / tinywizard.js
Last active October 3, 2017 10:41
Tiny Wizard
var Wizard = function (access_token) {
this.access_token = access_token;
this.page = 0;
this.el = {
main: document.getElementById('main'),
pageNumber: document.getElementById('pageNumber')
};
this.el.pageNumber.setAttribute('style', 'display:block"');
}
@leegee
leegee / eg.js
Created November 2, 2017 14:12
Handlebars template to include other templates from DOM
el.main.innerHTML = Handlebars.compile(
el.innerHTML.toString()
)(
{ myContext: this }
);
// {{#includeDomTemplate "publish-tables-and-skus"}}{{/includeDomTemplate}}
Handlebars.registerHelper('includeDomTemplate', function(templateId) {
var html = Handlebars.compile(
document.getElementById(templateId).innerHTML.toString()
var Wizard = function (state) {
this.state = {};
// pageName: null,
// lastPageName: null
// window.history.popstate();?
Object.keys(state).forEach((key) => {
this.state[key] = state[key];
});
this.pageEl = null;
this.el = {