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 / Convert-ACLToCustomObject.ps1
Created February 7, 2024 02:45
Convert-ACLToCustomObject
View Convert-ACLToCustomObject.ps1
function Convert-ACLToCustomObject {
param ([Parameter(Mandatory = $true)]$ACL)
# Define a custom type
class CustomADObject {
[object]$ADObject
[string]$Guid
CustomADObject([object]$ADObject, [string]$Guid) {
$this.ADObject = $ADObject
@emmaly
emmaly / code.gs
Created December 15, 2023 02:29
Google Sheet Apps Script: change data validation ranges
View code.gs
/** @OnlyCurrentDoc */
/**
* Fixes the dropdown pickers on the Elections sheet if they need it.
*/
function fixPickers() {
const spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
const sheet = (spreadsheet.getSheets().filter((sheet) => sheet.getSheetId() === 123123) || []).shift();
const pickListsSheet = (spreadsheet.getSheets().filter((sheet) => sheet.getSheetId() === 234234) || []).shift();
const pickers = spreadsheet.getRangeByName("ProductPickers");
@emmaly
emmaly / code.gs
Created December 4, 2023 23:41
Apps Script Helper Functions for Google Sheets
View code.gs
/** @OnlyCurrentDoc */
/**
* @param {any} value - value to test
* @returns {boolean} - `true` if a number, `false` otherwise
*/
function isNumber(value) {
return typeof value == 'number' && isFinite(value);
}
@emmaly
emmaly / code.gs
Created December 4, 2023 23:39
Apps Script: Cached Key Helpers & Named Range Lookup
View code.gs
/**
* Retrieves a value from the cache if it's still valid.
* @param {string} key - The key for the cached data.
* @param {number} expirationInMinutes - The time after which data should be considered stale.
* @returns {any} - The cached data, or null if it's stale or not present.
*/
function getCachedValue(key, expirationInMinutes) {
Logger.log("getCachedValue(%s, %s)", key, expirationInMinutes.toFixed(0));
var cache = PropertiesService.getScriptProperties();
@emmaly
emmaly / gist:8267078
Created January 5, 2014 11:21
Bash script to automatically switch PulseAudio sink to Bluetooth headset on connect with A2DP profile and 50% volume.
View gist:8267078
#!/bin/bash
sink_name="bluez_sink.00_42_1B_AD_FA_CE"
if [ -z "$1" ]; then
dbus-monitor --system "path=/org/bluez/777/hci0/dev_00_42_1B_AD_FA_CE, interface=org.bluez.AudioSink, member=Connected" | while read line; do
echo $line
$0 1
done
else
@emmaly
emmaly / doRangesIntersect.gs
Last active December 1, 2023 13:48
Google Sheet: doRangesIntersect() = do all of these ranges have shared overlap points? getRangeIntersection() = return the intersection of *all* of any number of supplied ranges
View doRangesIntersect.gs
/**
* Source: https://gist.github.com/emmaly/2522d2e12157c4c3ebefe32d409ca996
*
* @param {SpreadsheetApp.Range} ranges
* @returns {boolean}
* - `true` indicates all ranges share the same overlapping area with all others.
* - `false` indicates no shared overlap area, even if they all overlap individually.
*/
function doRangesIntersect(...ranges) {
return getRangeIntersection(...ranges) !== null;
@emmaly
emmaly / gfb.html
Created November 5, 2023 05:22
Glowy Floaty Balls
View gfb.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Glowy Floaty Balls</title>
<style>
body {
background-color: #222;
@emmaly
emmaly / KV to JSON.buildship
Created September 22, 2023 19:51
BuildShip Node: KV to JSON
View KV to JSON.buildship
{
"meta": {
"id": "f803c041-7f48-48d0-852c-22adff386327",
"icon": {
"url": null,
"type": "URL"
},
"description": "Converts Key/Value list to JSON",
"name": "KV to JSON"
},
@emmaly
emmaly / Jinja2 Type Testing.txt
Last active September 14, 2023 06:23
Jinja2 Type Testing (useful for constrained environments)
View Jinja2 Type Testing.txt
None:
- none
True:
- boolean
False:
- boolean
65535:
- number
- integer
123:
@emmaly
emmaly / email-regex.md
Last active August 25, 2023 00:17
Email Regular Expression
View email-regex.md

Email RegEx

Go

var emailAddressRE = regexp.MustCompile(`^(?i)(?:(?:\"[^\"]+\")|[a-z0-9!#$%&'*+\-\/=?^_` + "`" + `{|}~]+(?:\.[a-z0-9!#$%&'*+\-\/=?^_` + "`" + `{|}~]+)*)@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$`)
if !emailAddressRE.MatchString("emmaly@example.com") {
  panic("oops")
}