Skip to content

Instantly share code, notes, and snippets.

View girlcheese's full-sized avatar
🏠
Working from home

Sam Carrington girlcheese

🏠
Working from home
View GitHub Profile
@girlcheese
girlcheese / index.html
Created July 16, 2020 22:09
Duck's Arduino Interface
<script>
// build the interface
const rowIds = [];
const $body = document.getElementsByTagName("body")[0];
$body.addEventListener("click", e => {
// event handler on body - need to check if the orginal target of the
// bubbled event has a value, i.e. is a checkbox
const val = e.target.value;
@girlcheese
girlcheese / lambda-boilerplate.js
Created April 4, 2017 19:17
Basic AWS Lambda code for proxying via an AWS API Gateway
"use strict";
process.env['PATH'] = process.env['PATH'] + ':' + process.env['LAMBDA_TASK_ROOT'];
var handler = function(event, context, callback){
const query = event.queryStringParameters || {};
const eventParams = event.body ? JSON.parse(event.body) : {};
var data = {
results: [1,2,3],
@girlcheese
girlcheese / certbot.sh
Created November 28, 2016 14:05
Certbot interaction to set up domains
export $DIR ...
export $DOMAINS ...
mkdir -p $DIR && ./root/certbot/certbot-auto certonly --server https://acme-v01.api.letsencrypt.org/directory -a webroot --webroot-path=$DIR --agree-dev-preview $DOMAINS
// -------------------------------------------------------------------------------------------------
// init widgets
/**
* DOM-based routing module for page initialisation.
* @module initWidgets
* @author samc@fullsixuk.com
*
*/
function initWidgets(scope, trycatch) {
@girlcheese
girlcheese / gist:29acea17ba606b01153c
Last active June 12, 2020 03:31
slotRenderEnded listener event (DFP)
googletag.pubads().addEventListener("slotRenderEnded", function(event) {
//console.log("googletag slotRenderEnded", event.slot.b.f);
var containerId = "";
// WARN: Fragile access of private object within DFP Slot Object returned with the event
// It's the only way to get access to the id of the DOM element attached to the slot
// FIXME: Ideally we need to contact Google and request a public API method to return the id
if (typeof event.slot !== "undefined") {
if (typeof event.slot.b !== "undefined") {
@girlcheese
girlcheese / array.js
Created August 21, 2014 13:43
Getting the TrackingId on a page.
ga(function() {
var trackers = ga.getAll(), ret = [];
for (var i=0; i<trackers.length; ++i) {
var tracker = trackers[i];
ret.push(tracker.get('trackingId'));
}
console.log(ret);
});
@girlcheese
girlcheese / app.js
Last active December 19, 2015 04:49
Utility function : Element Factory (Using require pattern) ... A bit perverse as its using require to populate a global utility object. But hey.
/*global define, window */
define(['jquery'], function ($) {
'use strict';
var GU = window.GU || {};
GU.UTIL = GU.UTIL || {};
/* Element factory.
* @param {string} el The name of a DOM element
@girlcheese
girlcheese / debug-helper.js
Last active December 10, 2015 22:18
Boilerplate for a JSHist-friendly x-browser console log wrapper
// Avoid `console` errors in browsers that lack a console.
(function() {
var method;
var noop = function () {};
var methods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
'timeStamp', 'trace', 'warn'
];
@girlcheese
girlcheese / gplus.html
Created November 26, 2012 17:20
Asynchronous code injection #2
<g:plusone annotation="inline"></g:plusone>
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'http://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
@girlcheese
girlcheese / buysellads.html
Created November 26, 2012 17:18
Asynchronous code injection
<script type="text/javascript">
(function(){
var bsa = document.createElement('script');
bsa.type = 'text/javascript';
bsa.async = true;
bsa.src = '//s3.buysellads.com/ac/bsa.js';
(document.getElementsByTagName('head')[0]||document.getElementsByTagName('body')[0]).appendChild(bsa);
})();
</script>