Skip to content

Instantly share code, notes, and snippets.

View erickoledadevrel's full-sized avatar

Eric Koleda erickoledadevrel

View GitHub Profile
@erickoledadevrel
erickoledadevrel / drive_console_helper.js
Last active August 29, 2015 14:10
The Google Drive SDK console only allows you to enter MIME types and file extensions one at a time. This script allows you to enter a comma-separated list of values into a text box and then have it split into multiple text boxes automatically.
(function() {
// Include jQuery.
var script = document.createElement('script');
script.src = 'https://code.jquery.com/jquery-2.1.1.min.js';
script.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(script);
var sections = [
'Default MIME Types',
'Default File Extensions',
@erickoledadevrel
erickoledadevrel / AppsMarketplaceSignIn.html
Created April 22, 2016 18:42
Showing how to use the Google Sign-in JavaScript library with Google Apps Marketplace.
<html>
<head>
<title>GAM Sample App</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/URI.js/1.17.1/URI.js"></script>
<script src="https://apis.google.com/js/platform.js?onload=init" async defer></script>
</head>
<body>
<h1>GAM Sample App</h1>
<p id="message">Loading...</p>
@erickoledadevrel
erickoledadevrel / announcements_publisher.js
Created May 29, 2012 16:21
Apps Script Intro Example Code 2012-05-23
function publish() {
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
var sheet = spreadsheet.getSheetByName('Announcements');
var data = sheet.getDataRange().getValues();
var site = SitesApp.getSite('erickoledauniversity');
var page = site.getChildByName('announcements');
for (var i = 0; i < data.length; i++) {
var row = data[i];
var title = row[1];
var description = row[2];
@erickoledadevrel
erickoledadevrel / Code.gs
Created January 14, 2016 17:36
Polling in a sidebar only when the page is visible
function onOpen() {
SpreadsheetApp.getUi().createMenu('Testing')
.addItem('Show Sidebar', 'showSidebar')
.addToUi();
}
function showSidebar() {
var sidebar = HtmlService.createHtmlOutputFromFile('Sidebar')
.setSandboxMode(HtmlService.SandboxMode.IFRAME)
.setTitle('Sidebar');
@erickoledadevrel
erickoledadevrel / downloadFileRange.gs
Created August 9, 2018 16:22
Downloading a portion of a Drive file in Apps Script.
function downloadFileRange(fileId, startByte, endByte) {
// Mention DriveApp in a comment to ensure the Drive scope is requested.
// DriveApp.getRootFolder();
var url = 'https://www.googleapis.com/drive/v3/files/' +
fileId + '?alt=media';
var response = UrlFetchApp.fetch(url, {
headers: {
Authorization: 'Bearer ' + ScriptApp.getOAuthToken(),
Range: 'bytes=' + startByte + '-' + endByte
}
@erickoledadevrel
erickoledadevrel / Code.js
Last active February 20, 2020 13:32
Remove multiple line breaks in a Googe Document using Apps Script
function removeMultipleLineBreaks(element) {
if (!element) {
element = DocumentApp.getActiveDocument().getBody();
}
var parent = element.getParent();
// Remove empty paragraphs
if (element.getType() == DocumentApp.ElementType.PARAGRAPH
&& element.asParagraph().getText().replace(/\s/g, '') == '') {
if (!(parent.getType() == DocumentApp.ElementType.BODY_SECTION
&& parent.getChildIndex(element) == parent.getNumChildren() - 1)) {
@erickoledadevrel
erickoledadevrel / Timezones.gs
Last active July 8, 2020 11:42
Some examples showing how to work with timezones in Apps Script.
// Setup: Spreadsheet in Pacific time, Script in Eastern time, Calendar in Mountain time.
// Sample spreadsheet: https://docs.google.com/spreadsheets/d/1neePK1YPKMKnVwI8dld0HSJjI1kSFPpcY8g7kG8xG4U/edit#gid=0
// A2 = 3/1/2016 9:00 AM, B2 = 3/1/2016 10:00 AM
/**
* The dates and times in the spreadsheet refer to exact moments in time, and the clock
* on the wall may show a different time.
*/
function copyMoment() {
var ss = SpreadsheetApp.getActive();
@erickoledadevrel
erickoledadevrel / Code.gs
Created February 9, 2016 14:18
Time-based trigger for specific time
function createTrigger() {
var time = new Date();
time.setMinutes(time.getMinutes() + 5);
ScriptApp.newTrigger('run')
.timeBased()
.at(time)
.create();
}
function run() {
@erickoledadevrel
erickoledadevrel / Code.gs
Last active April 12, 2021 20:48
Walkstation booking with Apps Script
/**
* @license
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
@erickoledadevrel
erickoledadevrel / Code.gs
Created February 19, 2016 14:38
Create a Google Calendar event with an attachment in Apps Script
function createEventWithAttachment() {
var driveFileId = '...';
var file = DriveApp.getFileById(driveFileId);
var event = {
summary: 'Test Event with Attachments',
description: 'Woot!',
attachments: [{
fileId: driveFileId,
fileUrl: file.getUrl(),
mimeType: file.getMimeType(),