Skip to content

Instantly share code, notes, and snippets.

@mhawksey
mhawksey / code.gs
Created April 26, 2019 18:37
Example Google Apps Script custom sheet function example. For more info see https://mashe.hawksey.info?p=19219
/**
* Generates a SHA-256 hash of a text input.
*
* @param {String||Array} value to SHA-256 hash.
* @param {String} key to use to generate the hash with.
* @return the SHA-256 hash of the value
* @customfunction
*/
function HASH(value, key) {
if (typeof key !== 'string'){ // test the key is a string
@mhawksey
mhawksey / UrlShortener.gs
Last active April 2, 2021 05:51
Google Apps Script shim to replace UrlShortener calls with a Bit.ly version
// https://addyosmani.com/blog/essential-js-namespacing/
// extend.js
// written by andrew dupont, optimized by addy osmani
function extend(destination, source) {
var toString = Object.prototype.toString,
objTest = toString.call({});
for (var property in source) {
if (source[property] && objTest == toString.call(source[property])) {
destination[property] = destination[property] || {};
extend(destination[property], source[property]);
@mhawksey
mhawksey / snip_02.js
Created March 17, 2018 16:48
Code snippets for Recording .mp3 audio in Google Add-ons/Google Apps Script to Google Drive https://mashe.hawksey.info/?p=17916
blobToDataURL(blob, function(url){
var filename = 'recording_' +
(new Date()) +
'_.mp3';
google.script.run.withSuccessHandler(function(driveUrl){
$('ol.convertedList')
.append('<li><strong> ' + filename +
'</strong> <a href="'+driveUrl+'" target="_blank">Drive Link</a><br/>' +
'<audio controls src="' + url + '"></audio>' +
'</li>');
@mhawksey
mhawksey / snip01.js
Last active November 17, 2019 07:53
Code snippets for Recording .mp3 audio in Google Add-ons/Google Apps Script to Google Drive https://mashe.hawksey.info/?p=17916
blobToDataURL(blob, function(url){
$('ol.convertedList')
.append('<li><strong> recording_' +
(new Date()) +
'_.mp3</strong><br/>' +
'<audio controls src="' + url + '"></audio>' +
'</li>');
})
@mhawksey
mhawksey / appsscriptzoneids.csv
Last active March 8, 2024 02:32
ZoneIds used in Google Apps Script
value text
Pacific/Midway (GMT-11:00) Midway
Pacific/Niue (GMT-11:00) Niue
Pacific/Pago_Pago (GMT-11:00) Pago Pago
Pacific/Honolulu (GMT-10:00) Hawaii Time
Pacific/Johnston (GMT-10:00) Johnston
Pacific/Rarotonga (GMT-10:00) Rarotonga
Pacific/Tahiti (GMT-10:00) Tahiti
Pacific/Marquesas (GMT-09:30) Marquesas
America/Anchorage (GMT-09:00) Alaska Time
@mhawksey
mhawksey / gist:0c5ad7b79e1162b239156ce946cbe2be
Last active June 7, 2022 15:17
Snippet of code used for DevFest London 2017 to count faces in audience and send to Google Analytics and update image in Google Slides (see https://mashe.hawksey.info/?p=17787)
import io
import picamera
import cv2
import numpy
import requests
import base64
def hitGA(faces):
print("Sending to GA")
requests.get("http://www.google-analytics.com/collect?v=1" \
@mhawksey
mhawksey / face-detection-to-google-analytics.py
Last active January 16, 2020 21:40
Snippet of code used for DevFest London 2017 to count faces in audience and send to Google Analytics (see https://mashe.hawksey.info/?p=17787)
import io
import picamera
import cv2
import numpy
def hitGA(faces):
print("Sending to GA")
requests.get("http://www.google-analytics.com/collect?v=1" \
+ "&tid=YOUR_UA_TRACKING_ID_HERE" \
+ "&cid=1111" \
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
<a class="twitter-timeline" data-dnt="true" href="https://twitter.com/search?q=%23altc%20OR%20from%3AA_L_T" data-widget-id="398755222102605825">Tweets about #altc OR from:A_L_T</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
</body>
</html>
var icons = {};
icons['ic_refresh_white_24dp.png'] = { id: 'sync_now',
class: 'i18n spinning',
src: 'data:image/png;base64,...'
};
<div id="action-bar">
<?!= Include.img(icons['ic_refresh_white_24dp.png']); ?>
<?!= Include.img(icons['ic_settings_white_24dp.png']); ?>
</div>