Skip to content

Instantly share code, notes, and snippets.

View biancadanforth's full-sized avatar

Bianca Danforth biancadanforth

View GitHub Profile
@biancadanforth
biancadanforth / benchmarking.js
Created January 14, 2020 04:45
Benchmarking RegExp vs URL class for domain matching
/**
* Motivation: For a list of domains, is RegExp domain matching or URL class domain matching
* more performant in Firefox's JS engine? I used the website ``jsben.ch`` to measure.
* Spoiler: The URL class approach is 11% faster. Can this approach work with the
* ``matchSubdomains`` option?
*/
// Setup block
const domains = ["nytimes.com", "www.npr.org"];
const url = "https://www.nytimes.com/2020/01/13/us/politics/russian-hackers-burisma-ukraine.html?action=click&module=Top%20Stories&pgtype=Homepage";
@biancadanforth
biancadanforth / are_two_JSON_objects_the_same.py
Last active November 6, 2019 02:43
Check if two JSON objects are the same by first ordering them
import json, os
# Put filenames here; this script assumes these files are in the same dir as the script
FILENAME_1 = "2.json"
FILENAME_2 = "3.json"
def ordered(obj):
if isinstance(obj, dict):
return sorted((k, ordered(v)) for k, v in obj.items())
@biancadanforth
biancadanforth / Bug_1542035_QA_Test_Plan.md
Last active August 27, 2019 06:52
Bug 1542035 QA Test Plan

((Below is the QA Test Plan. I will upload the test extensions before merge day.))

Bug 1542035 QA Test Plan

Setup

  1. Open Firefox Beta 70 in a new profile
  2. Download the following test extensions attached to this bug:
  • Test Extension 1: 1542035-test-extension-1-1.0.zip
    • Extension with Background script and browserAction toolbar button. Clicking the browserAction toolbar button opens a popup with a menu.
  • Test Extension 2: 1542035-test-extension-2-1.0.zip
@biancadanforth
biancadanforth / day03.js
Last active July 23, 2019 15:44
Day 03 Advent of Code implemented in JS and Python with TDD (https://adventofcode.com/2015/day/3)
const fs = require("fs");
function main() {
const path = __dirname + "/input";
let input = fs.readFileSync(path, { encoding: "utf8" });
console.log("Day 3, part 1: ", part1(input)); // 2572
console.log("Day 3, part 2: ", part2(input)); // 2631
}
@biancadanforth
biancadanforth / isVisible.js
Last active July 16, 2019 02:48
Performant and comprehensive rewrite (Rev 1 is BEFORE, Rev 2+ is AFTER) of `isVisible` in Price Tracker (https://github.com/mozilla/price-tracker/)
// Avoid reading `display: none` due to Bug 1381071
isVisible(fnode) {
const element = fnode.element;
if (element.getBoxQuads().length === 0) {
// The element has no box (display: none subtree?), checking
// getBoundingClientRect instead for a width and height of 0 only tells
// us it is a zero-sized box.
return false;
}
const eleStyle = getComputedStyle(element);
@biancadanforth
biancadanforth / test_extension_storage_actor.js
Last active June 12, 2019 17:42
temporary backup for bug 1542035 adding rest of test coverage for issue #4
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
/* globals browser */
"use strict";
const {
AddonTestUtils,
} = ChromeUtils.import("resource://testing-common/AddonTestUtils.jsm");
@biancadanforth
biancadanforth / READ_AND_WRITE_devtools-server-actors-storage.js
Last active June 9, 2019 19:52
Breaking up bug_1542035 patch into a READ and READ_AND_WRITE patch https://github.com/biancadanforth/bug_1542035
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const {Cc, Ci, Cu, CC} = require("chrome");
const protocol = require("devtools/shared/protocol");
const {LongStringActor} = require("devtools/server/actors/string");
const {DebuggerServer} = require("devtools/server/main");
@biancadanforth
biancadanforth / HostVsStoresRouter.js
Last active June 8, 2019 06:49
HostVsStoresRouter class Bug 1542035
// in storage actor's `populateStoresForHost` method...
this.hostVsStores = new HostVsStoresRouter(host);
// Add an intermediary "area" layer between host and storeMap in this.hostVsStores
class HostVsStoresRouter {
constructor(host) {
this.DEFAULT_AREA = "local";
// a triple nested map: host => areaMap, where areaMap is area => storeMap and storeMap is key => value
this.router = (new Map()),set(host, new Map());
},
@biancadanforth
biancadanforth / 0README.md
Last active May 31, 2019 17:25
Test Cases for Staff Engineer, Data Products On-Site Pair Programming Exercise (https://github.com/biancadanforth/staff-engineer-data-products)

Pair Programming Exercise

Problem Statement

In this exercise, we will port a JavaScript implementation of the Floyd-Warshall algorithm to Python.

This algorithm computes the shortest path between any node and any other node in a directed graph with integral edge lengths.

We are given:

bdanforth ~/src/mozilla-unified $ ./mach test devtools/server/tests/unit/test_extension_storage_actor.js
0:01.30 INFO Found node at /Users/bdanforth/.mozbuild/node/bin/node
0:01.30 INFO Found moz-http2 at /Users/bdanforth/src/mozilla-unified/testing/xpcshell/moz-http2/moz-http2.js
0:01.41 INFO Running tests sequentially.
0:01.41 SUITE_START: xpcshell - running 1 tests
0:01.43 INFO profile dir is /var/folders/r4/54vpbnzx4_l3jk8cmjgs5v040000gn/T/firefox/xpcshellprofile
0:01.43 TEST_START: devtools/server/tests/unit/test_extension_storage_actor.js
0:01.43 INFO devtools/server/tests/unit/test_extension_storage_actor.js | full command: ['/Users/bdanforth/src/mozilla-unified/objdir-frontend-debug-artifact/dist/Nightly.app/Contents/MacOS/xpcshell', '-g', '/Users/bdanforth/src/mozilla-unified/objdir-frontend-debug-artifact/dist/Nightly.app/Contents/Resources', '-a', '/Users/bdanforth/src/mozilla-unified/objdir-frontend-debug-artifact/dist/Nightly.app/Contents/Resources/browser', '-r', '/Users/bdanforth/src/moz