Skip to content

Instantly share code, notes, and snippets.

@JonathanGawrych
JonathanGawrych / domain-match-regex.js
Created February 8, 2024 22:39
Ensure that a well-formed url matches a domain and it's subdomains, but don't allow userInfo
// Modified from https://github.com/google/closure-library/blob/7818ff7dc0b53555a7fb3c3427e6761e88bde3a2/closure/goog/uri/utils.js#L189-L208
new RegExp(
'^' + // Anchor against the entire string.
'https?:\\/\\/' + // scheme
'(?![^\\\\\\/?#]*@)' + // userInfo disallowed
'(?:(?:[^\\\\\\/?#\\.]+?)\\.)*' + // subdomain
'mydomain.com' + // domain
'(?::[0-9]+)?' + // port
'(?=[\\\\\\/?#]|$)' // authority-terminating character.
);
@JonathanGawrych
JonathanGawrych / hide-fa.user.js
Created December 19, 2023 07:20
Userscript to add toggle buttons to FA posts.
// ==UserScript==
// @name Hide FA
// @namespace http://tampermonkey.net/
// @version 2023-12-19
// @description try to take over the world!
// @author You
// @match https://www.furaffinity.net/search/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=furaffinity.net
// @grant GM_setValue
// @grant GM_getValue
@JonathanGawrych
JonathanGawrych / subcategory-validation.gs
Created September 15, 2023 23:44
An apps script to detect when a Category is updated in a google spreadsheet, to update the subcategory data validation.
// When editing a cell that has data validation of the named range "CategoryList"
// The cell to the right of it will have it's data validation set to the name range of category + "List"
function onEdit(e) {
// Logger.log('start');
// Go see what was edited. Grab the top left cell in case they pasted both category and subcategory
const edited = e.range.offset(0, 0, 1, 1);
const spreadsheet = edited.getSheet().getParent();
// See if it has a validation
const validation = edited.getDataValidation();
@JonathanGawrych
JonathanGawrych / jira-sum-highlighted.user.js
Last active July 6, 2023 21:59
Creates a floating badge of the sum on the tickets when you highlight multiple
// ==UserScript==
// @name Jira Sum Highlighted
// @author Jonathan Gawrych
// @match https://goreact.atlassian.net/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=atlassian.net
// @grant none
// @run-at document-idle
// ==/UserScript==
(function doit() {
@JonathanGawrych
JonathanGawrych / git-undo-merge.md
Created April 7, 2023 16:43
How to undo a git merge

Figured out how to undo merge commits. If you have a branch like so:

develop -A--B--C--D--E
             \     \
topic         1--2--M--3

And you wanted to remove the merge, checkout topic and run git rebase --onto 2 M, where M is the merge commit and 2 is the topic's commit before the merge commit: WARNING: THIS DELETES EVIL MERGE CHANGES (changes that do not appear in either parent)

@JonathanGawrych
JonathanGawrych / findpath.js
Last active March 18, 2024 01:46
Given an key of a deep object and you're trying to find a path to it, BFS and print the path
const findPathByKey = (ob, key) => {
const found = new Set();
const queue = [{obj: ob, path: []}];
let pathLength = 0;
while (queue.length > 0) {
const {obj, path} = queue.shift();
if (pathLength < path.length) {
pathLength = path.length;
console.log(`increasing depth to ${pathLength}, current queue size: ${queue.length}, current found size: ${found.size}`);
}
@JonathanGawrych
JonathanGawrych / kill-gitlab-vs.user.js
Last active October 11, 2022 17:13
Virtual scroll in gitlab is bad. Just disable this feature (at GoReact)
// ==UserScript==
// @name Disable Gitlab Virtual Scroll At GoReact
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Virtual scroll in gitlab is bad. Just disable this feature
// @author Joanthan Gawrych
// @match https://gitlab.goreact.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=goreact.com
// @grant none
// ==/UserScript==
@JonathanGawrych
JonathanGawrych / findPathToObj.php
Last active June 8, 2022 17:58
A php function to scan an object to attempt to find a path to a value.
<?php
function findPathToObj($from, $to, $maxLevel = 5): ?string
{
$queue = [[
'var' => $from,
'path' => 'root',
'level' => 0
]];
$seen = [];
@JonathanGawrych
JonathanGawrych / HealthEquityAutoFill.userscript.js
Last active March 18, 2024 04:06
Userscript to automatically fill out the HSA Partial Transfer form for Health Equity to Fidelity
// ==UserScript==
// @name Fill Out HSA Transfer
// @match https://member.my.healthequity.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
let toTransfer = null;
@JonathanGawrych
JonathanGawrych / countup.js
Created May 7, 2020 00:42
Countup with variable carry
function* count(max) {
if (max.length === 0) {
yield [];
return;
}
for (let i = 1; i <= max[0]; i++) {
for (const subTree of count(max.slice(1))) {
yield [i].concat(subTree);
}
}