Skip to content

Instantly share code, notes, and snippets.

@mhawksey
mhawksey / submit.md
Last active Jun 14, 2022 — forked from tanaikech/submit.md
Retrieving and Parsing XML data from Google Workspace Update Blog and Putting it to Google Spreadsheet using Google Apps Script
View submit.md

Retrieving and Parsing XML data from Google Workspace Update Blog and Putting it to Google Spreadsheet using Google Apps Script

This is a sample script for retrieving and parsing the XML data from Google Workspace Update Blog and putting it to Google Spreadsheet using Google Apps Script.

At Google Workspace Update Blog, the XML data is provided. By this, the retrieved XML data is parsed with XmlService, and the data is put to Google Spreadsheet. Recently, I got a request for this. So I created this sample script. When this was useful for your situation, I'm glad.

Update: Modified version of the script which keeps inserting new posts after the header row.

@mhawksey
mhawksey / Code.js
Last active Jun 14, 2022 — forked from erickoledadevrel/Code.js
Formatting date/time values using the user's timezone in Apps Script.
View Code.js
/**
* @file A sample showing how to format date/time values in Apps Script so that they appear in the
* user's timezone. View a working version here:
* https://docs.google.com/spreadsheets/d/1t_ur0wMw80AXaFkpBXmYclLfGm_kDccYcD5LAGoBkrQ/edit
*/
/**
* Add menu item after the spreadsheet opens.
*/
function onOpen() {
View QueryResult.csv
year questions answers views
2009 1 4 23934
2010 51 129 651431
2011 72 141 836327
2012 1879 3186 8213291
2013 2601 3837 9766045
2014 2758 3802 7800393
2015 2779 3703 6018356
2016 2885 3615 5284099
2017 3895 4414 5246554
@mhawksey
mhawksey / inlineimage.gs
Last active Apr 2, 2021
Handling inline images and attachments so they can be included in the merge
View inlineimage.gs
// Handling inline images and attachments so they can be included in the merge
// Based on https://stackoverflow.com/a/65813881/1027723
// Get all attachments and inline image attachments
const msg = draft.getMessage();
const allInlineImages = msg.getAttachments({includeInlineImages: true, includeAttachments: false});
const attachments = msg.getAttachments({includeInlineImages: false});
const htmlBody = msg.getBody();
// Create an inline image object with the image name as key
// (can't rely on image index as array built based on insert order)
View Tweet functions.gs
// @OnlyCurrentDoc
const BearerTokenKey = 'twitterBearerToken';
function onOpen() {
SpreadsheetApp
.getUi()
.createMenu('Twitter')
.addItem('Set Bearer token', 'helpers.requestBearerToken')
.addItem('Sign out', 'helpers.logout')
View yt.gs
/**
* @OnlyCurrentDoc
*/
YouTube.setTokenService(function(){ return getYouTubeService().getAccessToken(); });
// Read data from current sheet and create live events returning details back to sheet
function schedule_events(){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("YT");
new cUseful.Fiddler(sheet)
@mhawksey
mhawksey / shBrushJScript.js
Created Apr 17, 2020
SyntaxHighlighter which includes Google Apps Script services
View shBrushJScript.js
/**
* SyntaxHighlighter
* http://alexgorbatchev.com/SyntaxHighlighter
*
* SyntaxHighlighter is donationware. If you are using it, please donate.
* http://alexgorbatchev.com/SyntaxHighlighter/donate.html
*
* @version
* 3.0.83 (July 02 2010)
*
@mhawksey
mhawksey / template-ALT.html
Last active Nov 26, 2019
Mosaico Template for CiviCRM based on
View template-ALT.html
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="viewport" content="initial-scale=1.0" />
<meta name="format-detection" content="telephone=no" />
<title style="-ko-bind-text: @titleText">[subject]</title>
<style type="text/css">
@mhawksey
mhawksey / code.gs
Created Apr 26, 2019
Example Google Apps Script custom sheet function example. For more info see https://mashe.hawksey.info?p=19219
View code.gs
/**
* 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 Apr 2, 2021
Google Apps Script shim to replace UrlShortener calls with a Bit.ly version
View UrlShortener.gs
// 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]);