Skip to content

Instantly share code, notes, and snippets.

/** this script will not run correctly until imageFolderId is correctly set
*/
var imageFolderId = "REPLACEWITHYOURGOOGLEDRIVEFOLDERID";
var imageFolder = DriveApp.getFolderById(imageFolderId);
@northwestcoder
northwestcoder / mergegoogledocs.gs
Created July 20, 2020 18:24
Google App Script merge documents
/**
This script generates a google doc from multiple 'child' docs.
It is meant to be triggered from an AppSheet.com app vis a vis a Google Sheet, e.g.:
AppSheet adds record/event to Google Sheet >> Trigger listening to Google Sheet >> This script invoked
*/
// the Google Sheet that is to be queried
@northwestcoder
northwestcoder / creategoogledoc.gs
Last active August 1, 2020 13:40
creategoogledoc
// this is hard wired to the folder ID of a google drive folder which stores file uploads
// from appsheet dot com. We retrieve the Google ID from the upload and then insert
// that ID back into a separate column.
function onChange(e) {
// hardwired the file upload folder, pls make better
var folder = DriveApp.getFolderById("APPSHEET FOLDER ID WHERE YOUR UPLOADS ARE GOING");
var sSht = e.source;
function onChange(e) {
var sSht = e.source;
var sht = sSht.getActiveSheet();
var shtName = sht.getName();
var activeRng = sht.getActiveRange();
var activeRow = activeRng.getRow();
var image = sht.getRange(activeRow,4).getValue();
var folder = DriveApp.getFolderById("APPSHEET FOLDER ID WHERE IMAGES WERE UPLOADED");
var blob = folder.getFilesByName(image.split("/")[1]).next().getBlob();
@northwestcoder
northwestcoder / CreateDocFromFragments.gs
Created August 2, 2020 15:22
CreateDocFromFragments
/**
This script generates a google doc from multiple 'parent/child' records.
It is meant to be triggered from an AppSheet.com app vis a vis a Google Sheet, e.g.:
1. AppSheet adds record/event to Google Sheet >>
2. Trigger listening to Google Sheet >>
3. This script invoked
4. your shiny google doc is generated from a parent/child appsheet app
*/
@northwestcoder
northwestcoder / timeago.swift
Created August 23, 2020 20:57
"Time Ago" a la social media style
func timeAgoSinceDate(_ date:Date, numericDates:Bool) -> String {
let calendar = Calendar.current
let now = Date()
let earliest = (now as NSDate).earlierDate(date)
let latest = (earliest == now) ? date : now
let components:DateComponents = (calendar as NSCalendar).components([NSCalendar.Unit.minute , NSCalendar.Unit.hour , NSCalendar.Unit.day , NSCalendar.Unit.weekOfYear , NSCalendar.Unit.month , NSCalendar.Unit.year , NSCalendar.Unit.second], from: earliest, to: latest, options: NSCalendar.Options())
if (components.year! >= 2) {
return "\(components.year!) years ago"
} else if (components.year! >= 1){
@northwestcoder
northwestcoder / apps_script_get_checksum.gs
Last active September 23, 2020 15:00
Apps Script: Find duplicate images using generated MD5 Digest/Checksum
/*
OVERVIEW:
Apps Script which, when triggered on a Google Sheet row,
finds the image content referenced and
creates a checksum/digest string for that content and
inserts that string back into the Google Sheet
BACKGROUND:
@northwestcoder
northwestcoder / gsuiteadmin.gs
Created October 1, 2020 18:04
G Suite Admin Functions
/*
Collection of apps script functions that trigger G Suite administrative calls
good backgrounder:
https://stackoverflow.com/questions/60960260/google-scripts-api-call-to-directory-members-failed-with-error-resource-not-fou
Appsheet companion app for this solution:
https://www.appsheet.com/samples/An-app-to-manage-G-Suite-users-and-group-Meant-to-be-used-in-conjunction-with-a-provided-Google-App-Script?appGuidString=7ab88075-a91c-4898-8a4f-1ca6ce2fca93
@northwestcoder
northwestcoder / satori2opensearch.py
Last active November 8, 2022 16:33
AWS Lambda to Push Satori Audit Data into AWS OpenSearch
import awswrangler as wr
import requests
import time
import datetime
import io
import pandas
import boto3
import base64
from botocore.exceptions import ClientError
import json
@northwestcoder
northwestcoder / snowflake_inventory_satori.py
Last active October 12, 2022 15:05
Satori Snowflake table scan for inventory population
from ast import Try
import datetime
import os
import re
import snowflake.connector
# import sqlparsing
import time
import sys