Skip to content

Instantly share code, notes, and snippets.

Avatar

Kent Brewster kentbrew

View GitHub Profile
@kentbrew
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
req.open(o.method, o.url, true);
// default text; can send json
req.responseType = o.responseType || 'text';
// get reply back from API in proper language
@kentbrew
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');
iframe.style.position = 'fixed';
iframe.style.height = '100px';
iframe.style.width = '300px';
iframe.style.top = '0';
iframe.style.right = '0';
iframe.src = browser.extension.getURL('iframe.html');
document.body.appendChild(iframe);
@kentbrew
kentbrew / pinterest_meta.md
Created Jun 5, 2017
Pinterest's META Namespace
View pinterest_meta.md

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

<meta property="pin:url" content="https://yourpage.com/pinit/test/pinterest_meta.html" />
<meta property="pin:description" content="This pin was generated by the Pinterest meta." />
<meta property="pin:media" content="http://cdn.yourpage.com/your_image_here.jpg" />

... 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
kentbrew / IPBSIEIP.md
Created Feb 17, 2017
Implementing the President's Border Security and Immigration Enforcement Improvements Policies
View IPBSIEIP.md

January 25, 2017

MEMORANDUM FOR:

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
kentbrew / stub.html
Last active Jun 9, 2020
A stub file for new HTML projects.
View stub.html
<!doctype html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<link rel="stylesheet" href="presentation.css">
</head>
<body>
<script src="behavior.js"></script>
</body>
@kentbrew
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
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
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:
https://developer.mozilla.org/Add-ons/WebExtensions/API/i18n/getMessage#Browser_compatibility
https://developer.mozilla.org/Add-ons/WebExtensions/API/runtime/sendMessage#Browser_compatibility
https://developer.mozilla.org/Add-ons/WebExtensions/API/storage/local/get#Browser_compatibility
https://developer.mozilla.org/Add-ons/WebExtensions/API/storage/local/set#Browser_compatibility
@kentbrew
kentbrew / pinmarklet.md
Last active Jul 23, 2021
How to recreate your long-lost Pinterest bookmarklet.
View pinmarklet.md

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
kentbrew / konami.md
Last active Apr 18, 2016
Problem-Solving Interview Question: Implementing the Konami Code
View konami.md

#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.