Skip to content

Instantly share code, notes, and snippets.

View JayGoldberg's full-sized avatar

Jay Goldberg JayGoldberg

  • Google
  • San Francisco, CA, USA
View GitHub Profile
@JayGoldberg
JayGoldberg / circuitFinder.html
Last active December 24, 2024 00:58
Circuit finder using ESP devices (ESP8266 or ESP32)
<!DOCTYPE html>
<html>
<head>
<title>ESPHome Circuit finder</title>
<style>
.status-container {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
grid-gap: 10px;
}
@JayGoldberg
JayGoldberg / ytAnalytics.py
Created October 23, 2024 18:19
Accessing youtubeanalytics.googleapis.com API using python
import os
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
API_SERVICE_NAME = 'youtubeAnalytics'
API_VERSION = 'v2'
CLIENT_SECRETS_FILE='ytsecret.json'
@JayGoldberg
JayGoldberg / genAI_noise.sh
Last active October 23, 2024 01:59
adds organic noise to AI generated images
# adds organic noise to AI generated images
# requires ImageMagick `convert` command
function makenoise {
# Get the input extension and use the same one for output
imageName="$1"
basename=$(basename "$imageName")
extension="${imageName##*.}"
# Split the image into channels
convert "$imageName" -separate "channel_%d.png"
@JayGoldberg
JayGoldberg / enumerateDrive.gs
Created May 24, 2024 15:48
Recursive enumeration of all files in a Google Drive folder to text file on Drive
function getAllFiles(folderId) {
const accumulated = [];
const folder = DriveApp.getFolderById(folderId);
// Function to copy a file to GCS, handling file or folder path as argument
function traverseOrReturnItem(item, currentPath) {
const itemName = item.getName(); // Handles file or folder names
const thisPath = `${currentPath}${currentPath ? "/" : ""}${itemName}`; // Construct GCS object key
// if (typeof item === 'object' && item.getMimeType() ? false : true && DriveApp.getFolderById(item.getId()) ? true : false) { // If it's a folder, process contents recursively
@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);
}