Skip to content

Instantly share code, notes, and snippets.

View emmaly's full-sized avatar
👾
Invading Space

Emmaly emmaly

👾
Invading Space
View GitHub Profile
@emmaly
emmaly / getSheetById.gs
Created August 21, 2023 19:08
getSheetById.gs
/**
* @OnlyCurrentDoc
*/
/**
* @param {SpreadsheetApp.Spreadsheet} spreadsheet
* @param {number} sheetId
* @returns SpreadsheetApp.Sheet
*/
function getSheetById(
@emmaly
emmaly / wakeup.rb
Created May 22, 2023 22:38
Sonic Pi: Majestic Wakeup Routine, says GPT-4
use_bpm 60
use_synth :kalimba
define :calm_section do
play_pattern_timed [:c4, :e4, :g4, :c5], [0.5, 0.5, 0.5, 1]
play_pattern_timed [:c4, :e4, :g4, :b4], [0.5, 0.5, 0.5, 1]
play_pattern_timed [:c4, :d4, :g4, :a4], [0.5, 0.5, 0.5, 1]
play_pattern_timed [:c4, :d4, :g4, :g4], [0.5, 0.5, 0.5, 1]
end
@emmaly
emmaly / Set-NumLockOn.ps1
Created April 28, 2023 18:36
Ensure NumLock is ON via PowerShell
Add-Type -TypeDefinition @"
using System;
using System.Runtime.InteropServices;
public static class NumLock {
[DllImport("user32.dll", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
public static extern short GetKeyState(int keyCode);
[DllImport("user32.dll", EntryPoint = "keybd_event", CharSet = CharSet.Auto, ExactSpelling = true, CallingConvention = CallingConvention.Winapi)]
public static extern void keybd_event(byte bVk, byte bScan, int dwFlags, int dwExtraInfo);
@emmaly
emmaly / Write-ThisDown.ps1
Created March 25, 2023 05:13
Write-ThisDown.ps1
function Write-ThisDownHere {
[CmdletBinding()]
param (
[Parameter(ValueFromPipeline = $true)]
$InputObject,
[ValidateSet("Host", "Info", "Log")]
$Medium = "Host",
[ValidateSet("List", "Table", "Wide", "String", "JSON", "Raw")]
@emmaly
emmaly / googleworkspace_resource_custodian.gs
Created March 12, 2023 02:37
Google Workspace Automatic per Building Resource Management Privilege Distribution via Per Building Group Creation & Inclusion in Resource ACL
//
const NOOP = true; // must be === false to make *ANY* actual modification work happen, not just !== true.
//
const GROUP_CREATION_OKAY = false; // must be === true for this to happen
const ACLRULE_ADD_OKAY = false; // must be === true for this to happen
const ACLRULE_REMOVE_OKAY = false; // must be === true for this to happen
const ACLRULE_FIXROLE_OKAY = false; // must be === true for this to happen
//
const GROUP_TEMPLATE = {
name: ({buildingName}) => buildingName + " Resource Custodian Role",
@emmaly
emmaly / resolveRelationships.js
Created March 8, 2023 06:04
JSON:API relationship resolver
function resolveRelationships(relationships, included, parentIds) {
if (typeof relationships !== "object" || !Object.keys(relationships).length) return [];
if (typeof included !== "object" || !Array.isArray(included)) return [];
if (typeof parentIds === "string") parentIds = [parentIds];
if (typeof parentIds !== "object" || !Array.isArray(parentIds)) parentIds = [];
/**
* @param {string} type
* @returns {string}
*/
@emmaly
emmaly / Code.gs
Created March 4, 2023 03:53
Google Sheets Named Range Format Patroller
// An example of how something like this could be used:
//
// Set some ranges as NamedRanges named "ColumnFormat_PhoneNumber" and "ColumnFormat_DateTime"
// and those will end up processed by the functions named "Format_PhoneNumber" and "Format_DateTime"
// which should enforce a value format or number format or possibly even a visual format upon edit
// and then set occasionalSheetFormatPatrol as a scheduled trigger to catch the items that were
// updated by API/scripts or other things that couldn't have been caught by the onEdit function.
// **
function occasionalSheetFormatPatrol() {
@emmaly
emmaly / QueryString.gs
Last active January 28, 2023 03:06
URL + QueryString object converted to string
/**
* @param {string} url
* @param {Object<string,string|string[]>} qs - query string
*/
function urlWithQueryStringObject(url, qs) {
if (!qs) return url;
return [
url,
Object.entries(qs)
.map(([k,v]) => {
@emmaly
emmaly / Install-WinGetCli.ps1
Last active January 26, 2023 09:30
Install WinGet-CLI on Windows Server
function Get-FilesFromGithubLatestRelease {
# original function from https://github.com/microsoft/winget-cli/issues/1861#issuecomment-1193136622
param (
[parameter(Mandatory)][string]$Project, # e.g. paintdotnet/release
[parameter(Mandatory)][string[]]$Patterns, # regex
[switch]$Prerelease
)
$releases = Invoke-RestMethod -Method Get -Uri "https://api.github.com/repos/$Project/releases"
$release = $releases | Where-Object { $_.prerelease -eq $Prerelease } | Select-Object -First 1
@emmaly
emmaly / DATEMAX(range)
Created January 16, 2023 03:12
Google Sheets Named Functions: DATEMAX and DATEMIN
=
ARRAY_CONSTRAIN(
SORT(
FILTER(
range,
MAP(
range,
LAMBDA(
cell,
ISDATE(cell)