Skip to content

Instantly share code, notes, and snippets.

View leegee's full-sized avatar

Lee Goddard leegee

View GitHub Profile
/* 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 );
*/
@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! ');
}
}
@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
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 = '';
}
beforeEach( module('thinMonitor') );
beforeEach( inject( function ($injector, $rootScope) {
rootScope = $rootScope;
scope = $rootScope.$new();
scope.grid = MOCKS.grid;
controller = $injector.get('$controller')('templateDialogController', {
$rootScope : $rootScope,
$scope : scope,
dialogInstance : MOCKS.dialogInstance,
@leegee
leegee / hue-from-rgb.js
Created December 14, 2015 15:00
Hue from RGB
// https://en.wikipedia.org/wiki/Hue#Computing_hue_from_RGB
else if ((r >= g) && (g >= b)) {
rvXy[x][y] = 60 * ( (g-b) / (r-b) );
}
else if ((g > r) && (r >= b)) {
rvXy[x][y] = 60 * (2 - ( (r-b) / (g-b) ));
}
else if ((g >= b) && (g > r)) {
rvXy[x][y] = 60 * (2 + ( (b-r) / (g-r) ));
}
@leegee
leegee / Scrol2Next.js
Created February 10, 2015 11:51
Vertically scrolling slide show, cf Valentino
/** Vertically scrolling slide show, cf Valentino
<script src='js/scroll2next.js'></script>
<script>
jQuery(document).ready( function () {
document.body.scrollTop = document.documentElement.scrollTop = 0;
new Scroll2Next({
container: '#container',
selector: 'img'
});
});
@leegee
leegee / config_es_yaml.sh
Last active August 29, 2015 14:05
ElasticSearch configured for named people with addresses, with combined name field with "auto-suggestion" that uses synonyms
# set -o verbose
# set -x
export ES_HOST=localhost:9200
export INDEX_NAME="people"
export SUGGEST_INDEX_NAME="suggestions"
export DELETE="curl -XDELETE $ES_HOST"
export POST="curl -XPOST $ES_HOST"
export PUT="curl -XPUT $ES_HOST"
export GET="curl -XGET $ES_HOST"
@leegee
leegee / Ls.js
Last active April 6, 2016 07:25
AJAX directory listing
// AMD stub?
var define = define || function (deps,module){ return module }
define([], function () {
/**
Apache autoindex to hash
@param {string} uri - uri of `mod_autoindex` directory or similar HTML page
@param {RegExp} re - hyperlinks for files to select from directory listing
@param {function} [next] - optional callback
@param {function} [error] - optional callback
@leegee
leegee / gist:cb59872f7bbf35ddfba8
Created May 30, 2014 14:34
Client-side Require.js and Mocha.js Runner
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Mocha Test Suite Runner</title>
<link rel="stylesheet" media="all" href="vendor/mocha/mocha.css">
<script src='../vendor/require.js'></script>
<script>
/** Needed to run the tests */