Skip to content

Instantly share code, notes, and snippets.

View leegee's full-sized avatar

Lee Goddard leegee

View GitHub Profile
@leegee
leegee / jwt.pl
Last active November 13, 2017 07:03
Google REST API with Perl JSON::WebToken
use strict;
use warnings;
require JSON::XS;
require JSON::WebToken;
require LWP::UserAgent;
my $google_ua = signin_with_google(
service_account_id => $SERVICE_AC_ID,
private_key => $PRIVATE_KEY,
@leegee
leegee / login-with-google.js
Last active October 23, 2019 13:39
Protractor Google OAuth2 Manual Sign-in
loginWithGoogle(
process.env.PROJ_TEST1_GMAIL_USER,
process.env.PROJ_TEST1_GMAIL_PASS
)
/**
* Uses the dreaded `sleep` method because finding the password
* by any css selector tried fails.
* @param {string} username - A Google username.
* @param {string} passphrase - A Google passpharse.
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 = {
@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()
@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 / 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 / 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 {
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);
/* 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! ');
}
}