Skip to content

Instantly share code, notes, and snippets.

View JayGoldberg's full-sized avatar

Jay Goldberg JayGoldberg

View GitHub Profile
@JayGoldberg
JayGoldberg / bqCreateExternalTableFromDrive.gs
Created January 11, 2023 00:01
Create an external table
// create external table from CSV or Google Sheet, autodetect schema
function bqCreateCsvTable(csvDriveFileId) {
const CONFIG = setConfig();
let csvFile = DriveApp.getFileById(csvDriveFileId);
let tableId = csvFile.getName();
let bqConfig = {
"tableReference": {
"projectId": CONFIG.projectId,
@JayGoldberg
JayGoldberg / restWebService.gs
Last active December 24, 2022 14:38
App Script REST style API in doGet() and doPost()
function doGet(e) {
// Look up the function for the specified endpoint
var handler = getEndpointHandlers[e.parameter.action];
if (handler) {
// Call the appropriate function for the endpoint
return handler(e);
} else {
// Return an error if the endpoint is not recognized
return ContentService.createTextOutput("Error: Invalid GET endpoint.").setMimeType(ContentService.MimeType.TEXT);
}
@JayGoldberg
JayGoldberg / driveFolderTagging.gs
Created December 23, 2022 14:47
Writes all the folder names of a file into the file description, so that the file can be found by searching the folder names.
// https://www.labnol.org/code/19721-add-tags-google-drive-files
/*
setDescriptionToFolderNames
Workaround to fake Tags in Google Drive.
Writes all the folder names of a file into the file description, so that the file can be found by searching the folder names.
*/
function setDescriptionToFolderNames() {
var file;
var filename;
@JayGoldberg
JayGoldberg / mouseDraw.js
Last active December 21, 2022 03:17 — forked from brettbartylla/mouseDraw.js
This javascript allows a mouse to draw on an HTML5 Canvas
// Get the canvas and its context
var canvas = document.querySelector('#paint');
var ctx = canvas.getContext('2d');
// Get the parent element of the canvas and its computed style
var sketch = document.querySelector('.sketch');
var sketch_style = getComputedStyle(sketch);
// Set the canvas dimensions to match the parent element
canvas.width = parseInt(sketch_style.getPropertyValue('width'));
@JayGoldberg
JayGoldberg / drawing.js
Created December 21, 2022 03:15 — forked from zachdunn/drawing.js
Canvas mouse drawing for a canvas #sketch plus button #clear.
(function(window){
// Define the Pen object, which handles drawing on the canvas
var Pen = function(context){
// Whether the user is currently drawing
var drawing;
// Reset the pen's drawing style
this.reset = function(){
context.beginPath();
context.lineCap = 'round';
@JayGoldberg
JayGoldberg / spreadsheetIndexfromColumn.js
Created December 20, 2022 04:53
Convert alphabetical spreadsheet column ID to a numeric index (Google Sheets, etc)
// given a column 'A'...'AB' etc, return a numeric index
function columnToIndex(column) {
// Initialize the index to 0
var index = 0;
// Iterate through the characters in the column string
for (var i = 0; i < column.length; i++) {
// Get the character at the current index
var char = column.charAt(i);
@JayGoldberg
JayGoldberg / geo.gs
Created November 29, 2022 03:27
Apps Script Google Maps geocoding using native Maps and API-key based geocode
// JSON geocode returned
function doNativeGeoCode(address) {
var response = Maps.newGeocoder().setBounds(32.85964933715685, -117.32946858722974, 32.70248574032382, -117.0346293702513).geocode(address);
return response;
}
// JSON geocode returned
function doApiGeoCode(address) {
var options = {
muteHttpExceptions: true,
@JayGoldberg
JayGoldberg / geocode.gs
Created September 16, 2022 21:00
Apps Script use Google Maps Javascript API with custom-defined script property API key
// addresses "Exception: Service invoked too many times for one day: geocode" because the built-in Maps App does not support API keys
// you must create an API key in Maps API in the Google Cloud Console for insertion into Script Properties `mapsApiKey`
function doGeoCode(address) {
var serviceUrl = `https://maps.googleapis.com/maps/api/geocode/json?address=${address}&key=${ScriptProperties.getProperty('mapsApiKey')}`;
var response=UrlFetchApp.fetch(serviceUrl, options);
if(response.getResponseCode() == 200) {
var responseJSON = JSON.parse(response.getContentText());
if (responseJSON !== null) { return responseJSON; }
}
#!/bin/sh
# v1.0
wd="/tmp/IPCAM"
mkdir -p $wd
rm -f $wd/*
tar -cf $wd/config.tar -C ./ mnt/mtd
@JayGoldberg
JayGoldberg / ftp_sync.sh
Last active July 25, 2021 12:55 — forked from guerrerocarlos/copy_to_ftp.sh
Script for syncing OUCAM camera videos automatically to FTP
#!/bin/sh
# FTP_COPY version 0.3 by MP77V www.4pda.ru
# ----------------------------
FTP_DEST_DIR="/FTP_directory"
FTP_DEST_HOST="FTP_host"
FTP_DEST_PORT="21"
FTP_DEST_LOGIN="FTP_user"
FTP_DEST_PASS="FTP_password"
# ----------------------------