Skip to content

Instantly share code, notes, and snippets.

View leegee's full-sized avatar

Lee Goddard leegee

View GitHub Profile
@leegee
leegee / paramsFromURI.js
Created March 15, 2014 16:58
JS URI Params
/** @return A hash keyed by URI param name, values always being arrays */
function paramsFromURI(){
var p = {};
var a = document.location.search.substring(1).split(/[;&]+/);
for (var i=0; i<a.length; i++){
var kv = a[i].split(/=/);
p[kv[0]] = p[kv[0]] || [];
p[kv[0]].push( decodeURIComponent( kv[1] ) );
}
return p;
@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 */
@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 / 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 / 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 / phantom-node-screenshot
Created November 11, 2013 06:23
Take a screenshot with Phantom.js under Node.js
/*
Take a screenshot with Phantom.js under Node.js
APIs
* Phantom https://github.com/ariya/phantomjs/wiki/API-Reference
* Webpage https://github.com/ariya/phantomjs/wiki/API-Reference-WebPage
*/
@leegee
leegee / app.js
Created November 11, 2013 15:16
Express and node-mysql connection pool test with nodeunit
var mysql = require('mysql');
var express = require('express');
var app = express();
var controllers = module.exports.controllers = {};
var models = module.exports.models = {};
if (!process.env.dbpass){
app.use(express.logger('dev'));
}
@leegee
leegee / app.js
Created November 12, 2013 15:50
An example of sending JSON from MySQL as chunked content
var mysql = require('mysql');
var express = require('express');
var app = express();
var controllers = module.exports.controllers = {};
var models = module.exports.models = {};
if (!process.env.dbpass){
app.use(express.logger('dev'));
}
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,
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 = '';
}