Skip to content

Instantly share code, notes, and snippets.


Kent Brewster kentbrew

View GitHub Profile
kentbrew / xhr_promises.js
Created Jun 12, 2017
XHR + Promises + responseType
View xhr_promises.js
var xhr = o => {
return new Promise(function(resolve, reject) {
var req = new XMLHttpRequest();
o.method = o.method || 'GET';
// third parameter must be there and be true to use o.formData, o.url, true);
// default text; can send json
req.responseType = o.responseType || 'text';
// get reply back from API in proper language
kentbrew / content.js
Last active Jun 21, 2017
Firefox Won't Open a New Tab from an Iframe in a Web Extensions Browser Extension
View content.js
var browser = chrome || browser;
var iframe = document.createElement('IFRAME'); = 'fixed'; = '100px'; = '300px'; = '0'; = '0';
iframe.src = browser.extension.getURL('iframe.html');
kentbrew /
Created Jun 5, 2017
Pinterest's META Namespace

Just like Facebook and Twitter, Pinterest has its own namespace. Go like this:

<meta property="pin:url" content="" />
<meta property="pin:description" content="This pin was generated by the Pinterest meta." />
<meta property="pin:media" content="" />

... and your preferred image (which need not actually appear on the page) will show at the top of the grid when someone uses Pinterest's mobile device, browser extension, or Any Image Save button.

kentbrew /
Created Feb 17, 2017
Implementing the President's Border Security and Immigration Enforcement Improvements Policies

January 25, 2017


Kevin McAleenan, Acting Commissioner, U.S. Customs and Border Protection

Dan Ragsdale, Acting Director, U.S. Immigration and Customs Enforcement

Lori Scialabba, Acting Director, U.S. Citizenship and Immigration Services

kentbrew / stub.html
Last active Jun 9, 2020
A stub file for new HTML projects.
View stub.html
<!doctype html>
<meta charset="utf-8">
<link rel="stylesheet" href="presentation.css">
<script src="behavior.js"></script>
kentbrew / WebExtensionCheck.js
Last active Aug 6, 2018
How to tell if visitors to your site are running a WebExtensions-compatible extension
View WebExtensionCheck.js
// If we know the extension's ID and a path to one of its web-accessible resources, we can quietly check for presence.
(function (w, a) {
var checkExt = function (callback) {
var hazExt = false;
var img = new Image();
img.onload = function () {
hazExt = true;
// need to know the right protocol for Firefox and Edge extensions
kentbrew / spinner.svg
Last active Feb 26, 2017
An animated SVG, suitable for use as a progress indicator.
View spinner.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
kentbrew / webExCompat.txt
Last active Nov 18, 2016
How to tell if your Chrome browser extension has WebExtensions support
View webExCompat.txt
From the root directory of your Chrome extension:
grep -r " chrome\." . | sed s/.*chrome\./\"/g | sed s/\(.*/#Browser_compatibility/ | sed s/[.]/\\//g | sed s/./https:\\/\\/developer\.mozilla\.org\\/Add-ons\\/WebExtensions\\/API\\// | sort | uniq
Hopefully you'll get something like this:
kentbrew /
Last active Jul 23, 2021
How to recreate your long-lost Pinterest bookmarklet.

How to recreate your long-lost Pinterest bookmarklet.

Right-click your bookmarks bar and choose Add Page (Chrome) or New Bookmarklet (Firefox).

In Name, put this:

Pin It

In URL, put this:

kentbrew /
Last active Apr 18, 2016
Problem-Solving Interview Question: Implementing the Konami Code

#Implementing the Konami Code

The Konami Code is a cheat code that appears in many early Konami video games. During the title screen before the game demo begins, the player can press the following sequence of buttons on the game controller to enable the cheat:

###↑ ↑ ↓ ↓ ← → ← → B A [Start]

The code has also found a place in popular culture as a reference to the third generation of video game consoles, and is present as an Easter egg on a number of Web sites.

####Please implement the Konami Code in JavaScript.