Skip to content

Instantly share code, notes, and snippets.

View bgrins's full-sized avatar

Brian Grinstead bgrins

View GitHub Profile
var EOL = {}, EOF = {}, QUOTE = 34, NEWLINE = 10, RETURN = 13;
function objectConverter(columns) {
return new Function("d", "return {" + columns.map(function(name, i) {
return JSON.stringify(name) + ": d[" + i + '] || ""';
}).join(",") + "}");
}
function customConverter(columns, f) {
var object = objectConverter(columns);
return function(row, i) {
return f(object(row), i, columns);
var prefs = Services.prefs;
var prefNames = prefs.getChildList("", {});
var prefSizes = {};
for (var i = 0; i < prefNames.length; i++) {
var prefName = prefNames[i];
if (prefs.getPrefType(prefName) !== prefs.PREF_STRING) continue;
prefSizes[prefName] = new Blob([prefs.getStringPref(prefName)]).size;
@bgrins
bgrins / Browser Console Helpers
Last active April 26, 2024 21:54
Helpers that can be used when debugging Firefox in the Browser Console / Browser Debugger
Helpers that can be used when debugging Firefox in the Browser Console / Browser Debugger
@bgrins
bgrins / reviewers.txt
Last active April 26, 2024 19:59
hg log devtools -r 'date(-180)' --template '{desc|firstline}\n' | awk '{split($0,a,"r=");print tolower(a[2])}' | grep -v "^$" | sort | uniq -c
1 miker
1 ato for marionette, rs=mossop for rest)
5 backout
1 backout a=backout on a closed tree
1 backout on a closed tree
1 baku
1 baku,
1 baku,bgrins
86 bgrins
1 bgrins, jsantell
<script type='text/javascript' src='astar.js'></script>
<script type='text/javascript'>
var graph = new Graph([
[1,1,1,1],
[0,1,1,0],
[0,0,1,1]
]);
var start = graph.grid[0][0];
var end = graph.grid[1][2];
var result = astar.search(graph, start, end);
@bgrins
bgrins / export-chrome-bookmarks.js
Last active February 26, 2024 04:00
Reminder of how to export bookmarks from Chrome as text.
/*
Export bookmarks from Chrome as text.
Go to Bookmarks Manager->Organize->Export to HTML file.
Then open that file, open console and run this command:
*/
[].map.call(document.querySelectorAll("dt a"), function(a) {
return a.textContent + " - " + a.href
}).join("\n");
@bgrins
bgrins / detectDataURL.js
Last active December 18, 2023 18:57
Detect if a string is a data URL. Doesn't try to parse it or determine validity, just a quick check if a string appears to be a data URL. See http://jsfiddle.net/bgrins/aZWTB/ for a demo.
// Detecting data URLs
// data URI - MDN https://developer.mozilla.org/en-US/docs/data_URIs
// The "data" URL scheme: http://tools.ietf.org/html/rfc2397
// Valid URL Characters: http://tools.ietf.org/html/rfc2396#section2
function isDataURL(s) {
return !!s.match(isDataURL.regex);
}
isDataURL.regex = /^\s*data:([a-z]+\/[a-z]+(;[a-z\-]+\=[a-z\-]+)?)?(;base64)?,[a-z0-9\!\$\&\'\,\(\)\*\+\,\;\=\-\.\_\~\:\@\/\?\%\s]*\s*$/i;
-- https://github.com/HTTPArchive/almanac.httparchive.org/blob/a54cc07fc61461e1366112ba81cf6e8fed7236fa/sql/2022/css/multicol.sql#L9
-- https://github.com/HTTPArchive/almanac.httparchive.org/blob/a54cc07fc61461e1366112ba81cf6e8fed7236fa/sql/2021/css/grid_named_lines.sql#L9
CREATE TEMPORARY FUNCTION countMozImageRect(css STRING)
RETURNS NUMERIC
LANGUAGE js
OPTIONS (library = "gs://httparchive/lib/css-utils.js")
AS '''
try {
const ast = JSON.parse(css);
return countDeclarations(ast.stylesheet.rules, {values: /^-moz-image-rect/});
@bgrins
bgrins / 33-66CI.json
Last active September 6, 2023 20:52
Multiply runs
{ "version": "development", "options": { "test-interval": 30, "display": "minimal", "tiles": "big", "controller": "ramp", "kalman-process-error": 1, "kalman-measurement-error": 4, "time-measurement": "performance", "warmup-length": 2000, "warmup-frame-count": 30, "first-frame-minimum-length": 0, "system-frame-rate": 60, "frame-rate": 60, "configuration": "medium" }, "data": [ { "MotionMark": { "Multiply": { "marks": { "Start sampling": { "time": 0, "index": 205 }, "Complexity: 2": { "time": -4473, "index": 10 }, "Complexity: 3": { "time": -4106, "index": 32 }, "Complexity: 10": { "time": -3772, "index": 52 }, "Complexity: 32": { "time": -3438, "index": 72 }, "Complexity: 100": { "time": -3105, "index": 92 }, "Complexity: 178": { "time": -2704, "index": 113 }, "Complexity: 316": { "time": -1753, "index": 153 }, "Complexity: 562": { "time": -929, "index": 183 } }, "samples": { "controller": { "fieldMap": { "time": 0, "complexity": 1, "frameLength": 2, "smoothedFrameLength": 3 }, "data": [ [ -4639, 1, 16.66
@bgrins
bgrins / Log-.md
Last active August 1, 2023 16:32
Prevent errors on console methods when no console present and expose a global 'log' function.

Javascript log Function

Every time I start a new project, I want to pull in a log function that allows the same functionality as the console.log, including the full functionality of the Console API.

There are a lot of ways to do this, but many are lacking. A common problem with wrapper functions is that the line number that shows up next to the log is the line number of the log function itself, not where log was invoked. There are also times where the arguments get logged in a way that isn't quite the same as the native function.

This is an attempt to once and for all document the function that I pull in to new projects. There are two different options:

  • The full version: Inspired by the plugin in HTML5 Boilerplate. Use this if you are writing an application and want to create a window.log function. Additionally,