Skip to content

Instantly share code, notes, and snippets.


Kent Brewster kentbrew

View GitHub Profile
kentbrew / favicon-interceptor.js
Created Jan 3, 2011
How to short-circuit those annoying favicon requests in node.js
View favicon-interceptor.js
// early experiments with node had mysterious double requests
// turned out these were for the stoopid favicon
// here's how to short-circuit those requests
// and stop seeing 404 errors in your client console
var http = require('http');
http.createServer(function (q, r) {
// control for favicon
kentbrew /
Last active Jun 18, 2021
How I Got Node.js Talking on EC2's Port 80

The Problem

Standard practices say no non-root process gets to talk to the Internet on a port less than 1024. How, then, could I get Node talking on port 80 on EC2? (I wanted it to go as fast as possible and use the smallest possible share of my teeny tiny little micro-instance's resources, so proxying through nginx or Apache seemed suboptimal.)

The temptingly easy but ultimately wrong solution:

Alter the port the script talks to from 8000 to 80:

kentbrew /
Last active Jun 18, 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 May 25, 2021
Finding Twitter User IDs

Finding Twitter User IDs

User accounts on Twitter are commonly identified by screen name, which may be changed by operators when they take over an account, or have been sitting on an old account for a long time and want to transition it into malicious use.

User IDs, however, are permanent. There are several services out there that will try to find them for you but it seems like a bad idea to me, since you're alerting them to the fact that there's something interesting about this account. There's also plenty of bad advice that uses many long-since-abandoned Twitter API endpoints.

As of this writing (2018-02-18) you can view source and search for /profile_banners/, which will show something like this:

.enhanced-mini-profile .mini-profile .profile-summary {
kentbrew /
Last active Apr 22, 2021
How to change the Chrome default language on OSX

How to Change your Chrome Default Language

Open up a Terminal window. (If you have never seen Terminal before, go to Spotlight Search and type "Terminal.")

In the Terminal box, try this:

defaults read AppleLanguages

If you see this:

View game.js
/* use strict */
const me = {
// we could potentially set this in game.create from game["_gridWidth"]
// instead of hard-coding the number 24
board: {
height: 24,
width: 24
// starting score should be 0
kentbrew / setMultiHeaders.js
Created Jan 10, 2011
Setting multiple cookies (or whatever) per header with Node. Bonus: p3p line prevents IE from spazzing out.
View setMultiHeaders.js
response.writeHead(200, {
'p3p': ['policyref=""', 'CP="OOO EEE OOH AH AHH"'],
'Set-Cookie': ['ting="tang; expires=0; path=/;"', 'wallawalla="bingbang; expires=123456789; path=/;"'],
'Content-Type': 'text/html'
kentbrew / tinymce_wordpress.txt
Created Oct 1, 2012
How to turn off TinyMCE in Wordpress
View tinymce_wordpress.txt
In wordpress/wp-includes/class-wp-editor.php, look for the tinymce setting:
public static function parse_settings($editor_id, $settings) {
$set = wp_parse_args( $settings, array(
'tinymce' => true, // load TinyMCE, can be used to pass settings directly to TinyMCE using an array()
) );
Set it to false and you should be good to go.
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 /
Last active May 2, 2020
Using DOMParser to clean HTML input

Old School:

  var clean = function (input) {
    var testMe = input, dupeTest = '';
    while (testMe !== dupeTest) {
      testMe = new DOMParser().parseFromString(testMe, "text/html").documentElement.textContent;
      dupeTest = testMe;
    testMe = testMe.replace(/</g, '&lt;');
    return testMe;