Skip to content

Instantly share code, notes, and snippets.

View aculich's full-sized avatar
😀
Having fun exploring repos for Computational Text Analysis with D-Lab CTAWG

Aaron Culich aculich

😀
Having fun exploring repos for Computational Text Analysis with D-Lab CTAWG
View GitHub Profile
@aculich
aculich / clean-toc.gs
Created March 29, 2022 01:21 — forked from marcorei/clean-toc.gs
Google Apps Script which cleans the Table of Content from unwanted headings.
/**
* Creates a menu entry in the Google Docs UI when the document is opened.
*
* @param {object} e The event parameter for a simple onOpen trigger. To
* determine which authorization mode (ScriptApp.AuthMode) the trigger is
* running in, inspect e.authMode.
*/
function onOpen(e) {
DocumentApp.getUi().createAddonMenu()
.addItem('Clean Table of Contents', 'cleanToC')

Google Apps Script Spreadsheet Utilities and Custom Functions#

These utilities are grouped into related files, for simpler copy & paste to your scripts.

ConvertA1.gs

A couple of helper functions to convert to & from A1 notation.

cellA1ToIndex( string cellA1, number index )

@aculich
aculich / submit.md
Created October 2, 2021 18:40 — forked from tanaikech/submit.md
Sorting Cells on Google Spreadsheet with Background colors using Google Apps Script

Sorting Cells on Google Spreadsheet with Background colors using Google Apps Script

This is a sample script for sorting the cells on Google Spreadsheet with the background colors using Google Apps Script.

Unfortunately, in the current stage, it seems that sort(sortSpecObj) of Class Range cannot directly sort by the background colors of cells. But when Sheets API is used, this goal can be achieved. Here, "SortRangeRequest" of the method of "spreadsheets.batchUpdate" in Sheets API is used.

Flow

@aculich
aculich / GithubClient.gs
Created September 24, 2021 09:11 — forked from pamelafox/GithubClient.gs
Google Apps Script for committing a file to Github Repo
/* A bare-bones GithubClient, just used for commits */
function GithubClient(owner, repo, username, passwordOrToken) {
this.owner = owner;
this.repo = repo;
this.username = username;
this.passwordOrToken = passwordOrToken;
}
/*
@aculich
aculich / whatFilesHaveIShared.gs
Last active September 21, 2021 19:37 — forked from danjargold/whatFilesHaveIShared.gs
Google script to list (on a Google Sheet) all files shared in your google drive, including all viewers, editors, and sharing permissions. Credit goes to @woodwardtw (https://gist.github.com/woodwardtw/22a199ecca73ff15a0eb) as this is an improvement on his code which only assesses a single folder and one level of sub-folders down.
function listFolders(folder) {
var sheet = SpreadsheetApp.getActiveSheet();
sheet.appendRow(["Name", "Sharing Access", "Sharing Permission", "Get Editors", "Get Viewers", "Date", "Size", "URL", "Download", "Description", "Type"]); //writes the headers
//var folder = DriveApp.getFolderById("INSERT_YOUR_FILE_ID");//that long chunk of random numbers/letters in the URL when you navigate to the folder
//getLooseFiles(folder, sheet);
//getSubFolders(folder, sheet);
//instead of getting folder by ID rather get all folders and cycle through each. Note this will miss loose files in parent directory.
var folder = DriveApp.getFolders()
@aculich
aculich / block_personal_appts
Created September 14, 2021 02:19 — forked from ttrahan/block_personal_appts
Google Apps Script to automatically create, edit and delete events on work calendar for personal calendar events. Instructions on how to set up can be found at https://medium.com/@willroman/auto-block-time-on-your-work-google-calendar-for-your-personal-events-2a752ae91dab
function sync() {
var id="XXXXXXXXXX"; // CHANGE - id of the secondary calendar to pull events from
var today=new Date();
var enddate=new Date();
enddate.setDate(today.getDate()+7); // how many days in advance to monitor and block off time
var secondaryCal=CalendarApp.getCalendarById(id);
var secondaryEvents=secondaryCal.getEvents(today,enddate);

Remove white background color of an image in ImageMagick

$ convert  your.jpg  -transparent white  your.png

Flatten a transparent image with a white background:

@aculich
aculich / sort-tabs.txt
Created July 27, 2021 02:15 — forked from bpmore/sort-tabs.txt
Sort Tabs in Google Spreadsheets
1. Copy/Paste the information below to the clipboard
2. Open the spreadsheet whose sheets need to be alphabetised
3. Choose Tools > Script editor > Blank (this opens a new tab in the browser)
4. Press Control+A followed by Control+V copy and paste the script in
5. Press Control+S to save the script
6. Choose Run > sortSheets
7. Go back to the spreadsheet tab to view the new sorted tab order
--Copy everything below this line--
function sortSheets () {
@aculich
aculich / walk_gdrive.py
Created July 9, 2021 15:23 — forked from xflr6/walk_gdrive.py
Recursively traverse the directory tree of a Google Drive folder as variation of os.walk()
# walk_gdrive.py - os.walk variation with Google Drive API
import os
from apiclient.discovery import build # pip install google-api-python-client
FOLDER = 'application/vnd.google-apps.folder'
def get_credentials(scopes, secrets='~/client_secrets.json', storage='~/storage.json'):
from oauth2client import file, client, tools
@aculich
aculich / server.py
Created June 16, 2021 12:50 — forked from mdonkers/server.py
Simple Python 3 HTTP server for logging all GET and POST requests
#!/usr/bin/env python3
"""
Very simple HTTP server in python for logging requests
Usage::
./server.py [<port>]
"""
from http.server import BaseHTTPRequestHandler, HTTPServer
import logging
class S(BaseHTTPRequestHandler):