Skip to content

Instantly share code, notes, and snippets.

View moorage's full-sized avatar

Matthew Moore moorage

View GitHub Profile
@moorage
moorage / IMPORT_URL_WITH_SELECTOR.gs
Last active September 9, 2024 17:49
Google Apps Script to fetch a url, use a query selector to get to a value
/**
* Fetches and caches the fully redirected URL for one day (24 hours).
*
* This function follows all redirects for a given URL and stores the final
* redirected URL in the cache for 24 hours. If the URL has already been
* processed within the last 24 hours, the cached result is returned to
* improve performance and limit network requests.
*
* @param {string} url - The original URL to fetch and follow redirects from.
* @return {string} The fully redirected URL after following all redirects.
@moorage
moorage / window-and-document-shim.ts
Created January 20, 2024 08:21
shim to get clerk in background worker for chrome extension
import { i18n } from 'webextension-polyfill';
if (typeof window === 'undefined') {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(globalThis as any).window = {
fetch: fetch,
navigator: navigator,
location: {
hash: '',
host: i18n.getMessage(extensionIdString),
@moorage
moorage / gmail_batch_fetch.ts
Created August 28, 2023 21:14
How to fetch gmail in batch with javascript / typescript
const gmailBatchEndpoint = 'https://www.googleapis.com/batch/gmail/v1'
const batchLimit = 2
async function fetchFullMessages(
auth: OAuth2Client,
messageIds: string[] = []
) {
const messageQueries = messageIds.map(function (id) {
return { uri: '/gmail/v1/users/me/messages/' + id }

Keybase proof

I hereby claim:

  • I am moorage on github.
  • I am moorage (https://keybase.io/moorage) on keybase.
  • I have a public key ASD544wuQvewbMQvK55Z1srBKpROrC_shqLTkUYSFyoKxQo

To claim this, I am signing this object:

@moorage
moorage / realsense-serial-numbers.py
Created July 22, 2019 22:34
Realsense serial numbers from python interface
import pyrealsense2 as rs
c = rs.context()
devices = c.query_devices()
print(devices)
print(devices[0])
print(devices[1])
@moorage
moorage / greppy_metaverse_dataset_renamer.py
Last active October 4, 2018 23:41
For a Greppy Metaverse dataset: rearrange non-contiguous scenes in a dataset, generate camera normals, move to separate folders.
import os, fnmatch, argparse
import numpy as np
import OpenEXR, Imath, json
import shutil, glob
# TODO update to handle stereo camera
#
# python3 greppy_metaverse_dataset_renamer.py --p /path/to/dataset
SUBFOLDER_MAP = {
@moorage
moorage / world_to_camera_normal.py
Created September 28, 2018 05:18
Convert blender world normals EXR to camera normal
import numpy as np
import OpenEXR, Imath
from scipy.misc import imsave
INPUT_EXR_NORMALS_FILE = '1-world.exr'
OUTPUT_RGB_NORMAL_FILE = '1-world-to-camera.png'
INVERTED_CAMERA_QUARTERNION = np.array([0.8127532005310059, -0.456145316362381, 0.17738527059555054, 0.31606677174568176], dtype=np.float32)
X_CHANNEL_NAME = 'RenderLayer.Normal.X'
Y_CHANNEL_NAME = 'RenderLayer.Normal.Y'
@moorage
moorage / save-aligned-pyrealsense2-images.py
Last active September 20, 2018 00:46
pyrealsense2 implementation for saving numpy arrays for aligned depth
# On macOS, you'll need to build the wrapper and export PYTHONPATH=$PYTHONPATH:/____PATH_TO____/librealsense/build/wrappers/python/Debug
import pyrealsense2 as rs
import numpy as np
# Give time for auto-exposure to kick in
CAPTURES_BEFORE_SAVING = 10
# Create a context object. This object owns the handles to all connected realsense devices
rs_pipeline = rs.pipeline()
@moorage
moorage / extract-bsdf-values.py
Last active March 1, 2024 08:32
Extract BSDF values from Blender in Python
import bpy
import colorsys
import json
# https://blender.stackexchange.com/a/80047/58635
def _convert_rgb_to_hsv(red, green, blue):
return colorsys.rgb_to_hsv(*_linear_to_srgb(red, green, blue))
# https://blender.stackexchange.com/a/80047/58635
def _linear_to_srgb(r, g, b):
@moorage
moorage / blender_center_of_object_collection.py
Created July 9, 2018 04:00
Python function that returns the (x,y,z) typle of the center of multiple objects, within blender
cntr = _center_of_object_collection([ D.objects['obj_example1'], D.objects['obj_example2'], ... ])
def _center_of_object_collection(obs):
min_x = max_x = min_y = max_y = min_z = max_z = None
for ob in obs:
local_vertices = ob.bound_box[:]
worldify = lambda p: ob.matrix_world * Vector(p[:])
world_vertices = [worldify(p).to_tuple() for p in local_vertices]
for (x,y,z) in world_vertices:
if min_x is None or x < min_x: