Skip to content

Instantly share code, notes, and snippets.

@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);
}
}
@JonathanGawrych
JonathanGawrych / CHITEST in memory.txt
Created February 17, 2020 00:58
Do the chitest formula in memory. Assumes the data is in DATA!$A:$K, and that the chi sheet, the top/left row/column references the columns to use (B, C, D, etc)
=CHITEST(
QUERY(QUERY(Data!$A:$K,"SELECT count(B) WHERE "&$A2&" IS NOT NULL GROUP BY "&$A2&" PIVOT "&B$1, 1), "SELECT * OFFSET 1", 0),
MMULT(
QUERY(Data!$A:$K,"SELECT COUNT(B) WHERE "&$A2&" IS NOT NULL GROUP BY "&$A2&" label Count(B) ''", 1),
ARRAYFORMULA(DIVIDE(TRANSPOSE(
QUERY(Data!$A:$K,"SELECT COUNT(B) WHERE "&B$1&" IS NOT NULL GROUP BY "&B$1&" LABEL COUNT(B) ''", 1)),
QUERY(Data!$A:$K,"SELECT COUNT(B) LABEL COUNT(B) ''", 1)))
)
)
)
Rule Description
Generic.Arrays.ArrayIndent Ensures that array are indented one tab stop.
Generic.Arrays.DisallowLongArraySyntax Bans the use of the PHP long array syntax.
Generic.Arrays.DisallowShortArraySyntax Bans the use of the PHP short array syntax.
Generic.Classes.DuplicateClassName Reports errors if the same class or interface name is used in multiple files.
Generic.Classes.OpeningBraceSameLine Checks that the opening brace of a class/interface/trait is on the same line as the class declaration.
Generic.CodeAnalysis.AssignmentInCondition Detects variable assignments being made within conditions.
Generic.CodeAnalysis.EmptyPHPStatement Checks against empty PHP statements.
Generic.CodeAnalysis.EmptyStatement This sniff class detected empty statement.
@JonathanGawrych
JonathanGawrych / git force remerge.sh
Last active March 13, 2019 20:11
Force a remerge using git's plumbings commands
# If remerging a revert, do this to get back your changes
git revert revertSha
git reset HEAD~
git add -A
# And skip to the echo below
# Find the merge-base of an already merged branch
# https://stackoverflow.com/a/4991675/1248889
diff -u <(git rev-list --first-parent topic) <(git rev-list --first-parent develop) | sed -ne 's/^ //p' | head -1

Keybase proof

I hereby claim:

  • I am JonathanGawrych on github.
  • I am jonathangawrych (https://keybase.io/jonathangawrych) on keybase.
  • I have a public key whose fingerprint is A680 6B2B A7AC FEB9 5CD2 1F37 5E23 FEF2 F8AC 3368

To claim this, I am signing this object:

// 1 << bit == 1 << (bit % 32)
// 1 << 33 == 2
// need a structure to represent bit >= 32
var bit = 32;
[(bit >> 5 == 3) << bit,
(bit >> 5 == 2) << bit,
(bit >> 5 == 1) << bit,
(bit >> 5 == 0) << bit]
@JonathanGawrych
JonathanGawrych / LESS CSS slanted border
Created January 17, 2017 22:57
Implementing a slanted border between a top-right and bottom-left block
@bottom-left-bg-color: #ff0000;
@top-right-bg-color: #0000ff;
@border-color: #cccccc;
@border-width: 5px;
@slant-angle: 15deg;
@slant-height: 10px;
@slant-anti-aliasing: 20%
@slant-width: tan(@slant-angle) * @slant-height;
@slant-hypotenuse: @slant-height / cos(@slant-angle);
@JonathanGawrych
JonathanGawrych / SIMD popcnt
Last active January 17, 2017 22:22
Calculated a the Hamming Weight (number of set bits) in a Single-Instruction Multi-Data type in JavaScript
// see http://stackoverflow.com/questions/109023/
let simd3 = SIMD.Uint32x4.splat(0x33333333);
let simd5 = SIMD.Uint32x4.splat(0x55555555);
let simd01 = SIMD.Uint32x4.splat(0x01010101);
let simd0F = SIMD.Uint32x4.splat(0x0F0F0F0F);
function popcnt(simd) {
simd = SIMD.Uint32x4.sub(simd, SIMD.Uint32x4.and(SIMD.Uint32x4.shiftRightByScalar(simd, 1), simd5));
simd = SIMD.Uint32x4.add(SIMD.Uint32x4.and(simd, simd3), SIMD.Uint32x4.and(SIMD.Uint32x4.shiftRightByScalar(simd, 2), simd3));