Skip to content

Instantly share code, notes, and snippets.

View jsdbroughton's full-sized avatar
🐒
coiled spring

Jonathon Broughton jsdbroughton

🐒
coiled spring
View GitHub Profile
@jsdbroughton
jsdbroughton / GoogleSheetPDF.js
Last active April 28, 2022 18:42
Function to convert a given Google Spreadsheet [Sheet] into a PDF.
/**
* Function to convert a given Google Spreadsheet [Sheet] into a PDF.
*
* @param {string} key This is the Id of the Sheet to be converted bothe the DocsList.getId() and the SpreadsheetApp.getId() versions work
* @param {string} name [Optional] Intended Filename. If omitted, uses the Sheet filename.
* @param {object} options Settings object for the crafting of the PDF. Defaults to A4, no gridline print etc. <pre>
* {
* format:Enum,
* size:Enum,
* headers: Bool,
@jsdbroughton
jsdbroughton / TitleCase.js
Last active December 15, 2015 10:09
Custom function for Google Sheets to Title case an array, range or single value. *Needs work* test function fails to correctly capitalise 'McCartney'
/*
* Function accepts a single ceel, array, 1D or 2D range Values.
*/
function titleCase(val) {
return processVal_(val);
}
function processVal_(val) {
var a;
if (val.constructor === Array) {
@jsdbroughton
jsdbroughton / bookmarklet.js
Last active December 16, 2015 00:19
This bookmarklet opens a new window/tab to the web hosting view of a publicly shared Google Drive folder. 1. Shared a Drive folder to Public 2. Open the folder either by navigating to it in Drive or via the Open command. 3. Click bookmarklet For a website to be accessible from the resultant url the folder must contain a single index.html file.
javascript:(function(){open('https://googledrive.com/host/'+location.href.split('/edit')[0].split('/').pop()+'/');})()
@jsdbroughton
jsdbroughton / genericHandler.js
Created May 31, 2013 11:42
jQuery var function to pass into a $(query).each() loop. In the stripped instance here, HTML5 data-* tags can control multiple events and types within one each call. "desk" here is a constructor with prototyped functions, but really the typeof test could be replaced with an eval on the value in the data-* attribute.
iconFunctions = function() {
$(this).click(function (e) {
var f = (e.target.attributes['data-function'] || {}).textContent;
if (typeof desk[f] === 'function') {
desk[f](e);
}
});
};
@jsdbroughton
jsdbroughton / absenceList.js
Created May 31, 2013 11:56
GAS for serving an XML gadget for GMail / Google Calendar that displays a list of people who are absent and codifies them accordingly. XML Gadget is served via content service, but this also runs on a timed trigger to update a calendar with one event per day that holds the same data. This is useful for subscribing to within calendar client apps.
function doGet(e) {
var output = ContentService.createTextOutput();
var xml;
var cache = CacheService.getPublicCache();
var cached = cache.get('xml');
if (cached != null) {
xml = JSON.parse(cached);
@jsdbroughton
jsdbroughton / test.html
Created June 11, 2013 18:45
Welcome document
<h1 id="welcome">Welcome to StackEdit! </h1>
<p>Hello, I am your first Markdown document within <strong>StackEdit</strong>. Don't delete me, I can be helpful. I can be recovered anyway in the <code>Utils</code> tab of the <i class="icon-cog"></i> <code>Settings</code> dialog.</p>
<hr>
<h2 id="documents">Documents</h2>
<p><strong>StackEdit</strong> stores your documents in the browser local storage, which means all your documents are automatically saved locally and are accessible offline.</p>
@jsdbroughton
jsdbroughton / 0.signatureBuilder.js
Last active December 19, 2015 15:29
1. Visit the Google Sites hosted knowledge library. The script checks Session.getActiveUser() to grab just the name and checks ScriptProperties for you. If no entry exists it serves a HTML form with few options. 2. Save the settings and you are presented with the resultant signature block. If its ok, send to GMail. 3. That's it. Next time you vi…
function doGet(request) {
request = request || {parameter: {fn: null}};
var content, user = Session.getActiveUser(), data, json, importData, mode;
mode = request.parameter.fn;
content = mode;
try {
switch (mode) {
case 'Start Over':
ScriptProperties.deleteProperty(user.getEmail());
case 'Build Signature':
@jsdbroughton
jsdbroughton / signatures.js
Last active August 25, 2017 19:11
Setting and Retrieving email signatures using Google Apps Script for a Google Apps for Business/Education Domain
function getSignatureById(id, domain) {
id = id || __userid__;
domain = domain || __yourdomain.com__;
var requestData = {
'method': 'GET',
'contentType': 'application/atom+xml'
};
function exampleEdit() {
var email = "15x.moon@email.com";
var sharedCode = "blahdiblah123";
var imageFile = convertSVG(editSVG(email, sharedCode, null), 'This is a PNG with the sharedCode');
// do whatever with the imageFile - I want to add it to an email to send the recipient address above
}
//+ Jonas Raoni Soares Silva
//@ http://jsfromhell.com/array/shuffle [rev. #1]
shuffle = function(v){
for(var j, x, i = v.length; i; j = parseInt(Math.random() * i), x = v[--i], v[i] = v[j], v[j] = x);
return v;
};