Skip to content

Instantly share code, notes, and snippets.

View JayGoldberg's full-sized avatar

Jay Goldberg JayGoldberg

View GitHub Profile
@JayGoldberg
JayGoldberg / url-param-stripper.html
Created October 19, 2023 18:02
Strips all the parameters from URLs from one input field and populates the stripped URLs in the other
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>URL Parameter Stripper</title>
</head>
<body>
<h1>URL Parameter Stripper</h1>
@JayGoldberg
JayGoldberg / etl_geojson.py
Last active September 17, 2023 19:37 — forked from lakshmanok/etl_geojson.py
How to load GeoJSON files to BigQuery (supports filename arg)
#!/usr/bin/env python3
# See: https://medium.com/@lakshmanok/how-to-load-geojson-files-into-bigquery-gis-9dc009802fb4
import json
import sys
def convert_geojson(input_file_path):
with open(input_file_path, 'r') as ifp:
with open('to_load.json', 'w') as ofp:
features = json.load(ifp)['features']
@JayGoldberg
JayGoldberg / convertGeoJsonToBq.js
Last active December 19, 2023 18:48
BigQuery requires new-line delimited JSON files where the geometry column is single string.
// https://medium.com/google-cloud/how-to-load-geojson-files-into-bigquery-gis-9dc009802fb4
// Javascript (NodeJS) vs Python
function convertGeoJsonBq() {
const fs = require('fs');
fs.readFile(process.argv[1], 'utf8', (err, data) => {
if (err) throw err;
const geojson = JSON.parse(data);
const features = geojson.features;
@JayGoldberg
JayGoldberg / resolveRedirect.gs
Created January 28, 2023 00:37
Google Sheets function to recursively resolve URLs and get status codes =getStatusCode() and =getRedirects()
const options = {
'muteHttpExceptions': true,
'followRedirects': false
};
function getStatusCode(url) {
const url_trimmed = url.trim();
let cache = CacheService.getScriptCache();
let result = cache.get(url_trimmed);
@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);