Skip to content

Instantly share code, notes, and snippets.

function createDummyFoldersWithNesting() {
// Get the starting point for the dummy folder structure
// Replace with your desired folder ID or use 'root' to start in the root of your My Drive
const rootFolder = DriveApp.getFolderById("YOUR_FOLDER_ID");
// Configuration for the dummy structure
const maxNestingLevel = 3; // How many levels deep the structure will go
const maxFoldersPerLevel = 5; // Maximum number of folders to create in each level
const maxFilesPerFolder = 5; // Maximum number of files to create in each folder
const fileFolderPrefix = 'Dummy' // Text added to the start of all folders/files
/**
* This library includes software components derived from the following projects:
* [ChatGPTApp] (https://github.com/scriptit-fr/ChatGPTApp)
* [Google AI JavaScript SDK] (https://github.com/google/generative-ai-js/)
*
* These components are licensed under the Apache License 2.0.
* A copy of the license can be found in the LICENSE file.
*/
/**
@mhawksey
mhawksey / Code.gs
Created February 7, 2024 21:55
Examples of Memoization in Apps Script with Cache Service
function main(){
console.log("Run in memory tests")
inMemory();
console.log("Run in cache tests")
withCache();
}
// From https://medium.com/@saravanaeswari22/memorization-in-javascript-f312d66402b2
const memoize = (func) => {
@mhawksey
mhawksey / Method1.gs
Created February 17, 2023 09:07
Google Apps Script methods for generating Google My Drive report.
// @OnlyCurrentDoc
const FOLDER_ID = 'YOUR_FOLDER_ID'; // OR 'root' if you want your entire My Drive
/**
* Method One: Using built-in DriveApp / file iterator
*/
function generateFolderFilesDriveApp() {
try {
const folderId = FOLDER_ID;
const parentFolder = (folderId === 'root') ? DriveApp.getRootFolder() : DriveApp.getFolderById(folderId);
@mhawksey
mhawksey / submit.md
Last active August 2, 2022 16:58 — 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

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 June 14, 2022 05:32 — forked from erickoledadevrel/Code.js
Formatting date/time values using the user's timezone in Apps Script.
/**
* @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() {
@mhawksey
mhawksey / QueryResult.csv
Created January 10, 2022 20:10
Snapshot of view count of Stack Overflow Questions tagged with google-apps-script https://data.stackexchange.com/stackoverflow/query/1539894/tag-views-by-year?Tag=google-apps-script
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 April 2, 2021 05:50
Handling inline images and attachments so they can be included in the merge
// 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)
// @OnlyCurrentDoc
const BearerTokenKey = 'twitterBearerToken';
function onOpen() {
SpreadsheetApp
.getUi()
.createMenu('Twitter')
.addItem('Set Bearer token', 'helpers.requestBearerToken')
.addItem('Sign out', 'helpers.logout')
/**
* @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)