Skip to content

Instantly share code, notes, and snippets.

View rgrove's full-sized avatar
🥧

Ryan Grove rgrove

🥧
View GitHub Profile
@rgrove
rgrove / parseJson.js
Created February 10, 2019 01:37
ECMA-404 compliant JSON parser in pure JS
/**
This is an ECMA-404 compliant JSON parser written in pure JS, with nice error
reporting. It's not super useful since it's ridiculously slow compared to
`JSON.parse()`, but I had fun writing it.
ISC License
Copyright (c) 2019 Ryan Grove <[email protected]>
Permission to use, copy, modify, and/or distribute this software for any purpose
@rgrove
rgrove / body-parser-prototype-poisoning-fix.js
Last active February 8, 2019 18:33
How to protect against prototype poisoning when using the Express body-parser library
/*
The Express body-parser library, which you may be using to parse incoming JSON
request bodies, doesn't currently protect against prototype poisoning via the
`__proto__` key.
The dangers of prototype poisoning are described in detail here:
https://hueniverse.com/a-tale-of-prototype-poisoning-2610fa170061
Until body-parser provides its own fix, you can protect yourself by adding a
reviver function that throws an error if it sees any key named "__proto__". This
@rgrove
rgrove / test.js
Created October 25, 2018 00:23
Node 10 memory leak with domains & Express
'use strict';
const domain = require('domain');
const app = require('express')();
app.use((req, res, next) => {
let requestDomain = domain.create();
requestDomain.add(req);
requestDomain.on('error', next);
@rgrove
rgrove / nytimes.txt
Created August 23, 2018 22:41
Custom uBlock Origin filter to block the huge obtrusive ads in The New York Times's new design
# This is a uBlock Origin filter list that blocks the huge obtrusive ads in
# The New York Times's new design.
#
# You can paste these rules into uBlock Origin's "My Filters" tab or import them
# as described here:
#
# https://github.com/gorhill/uBlock/wiki/Filter-lists-from-around-the-web
www.nytimes.com###app div:if(> div:only-child > div:only-child > div.ad)
@rgrove
rgrove / snippets.cson
Created January 31, 2017 01:07
Atom snippets for writing Mocha tests
# Your snippets
#
# Atom snippets allow you to enter a simple prefix in the editor and hit tab to
# expand the prefix into a larger code block with templated values.
#
# You can create a new snippet in this file by typing "snip" and then hitting
# tab.
#
# An example CoffeeScript snippet to expand log to console.log:
#
@rgrove
rgrove / README.md
Created February 8, 2016 19:01
Cake's approach to React Router server rendering w/code splitting and Redux

Can't share the complete code because the app's closed source and still in stealth mode, but here's how I'm using React Router and Redux in a large app with server rendering and code splitting on routes.

Server

  1. Wildcard Express route configures a Redux store for each request and makes an addReducers() callback available to the getComponents() method of each React Router route. Each route is responsible for adding any Redux reducers it needs when it's loaded. (This isn't really necessary on the
@rgrove
rgrove / broken.js
Last active August 29, 2015 14:21
Chrome 43+ JS character encoding + parsing bug
This file has been truncated, but you can view the full file.
YUI.add("sm-cart-helpers",function(e){SM.currentModule="sm-cart-helpers";var exports={},module=SM.modules[SM.currentModule]={exports:exports,name:SM.currentModule};!function(){"use strict";var r,o=SM.import("lodash"),t=e.UA.ie&&e.UA.ie<=9,n=e.UA.safari&&parseInt(e.UA.safari,10)<537,a=SM.import("sm-resource-album-image"),s=SM.import("sm-accepts-smugmug-cookies"),u=SM.import("sm-uri");module.exports={showAddToCart:function(i,m,c){return t||n?SM.load("sm-icartoverlay").then(function(){r||(r=new e.SM.ICartOverlay),r.set("image",i),r.set("album",m),r.show()}):a.loadByKey(m.get("AlbumKey"),i.get("ImageKey"),{expand:["ImageSizeDetails"]}).then(function(e){s.then(function(){SM.load("sm-addtocart-controller").then(function(r){r.mount(o.assign({image:e},c))})},function(){var r=SM.env.pageOwner,o=new u(location.href),t="";o.file&&"buy"===o.file.toLowerCase()?o.queryParams.returnTo?t=o.query:(t="returnTo="+encodeURIComponent(e.get("WebUri")),o.query&&(t+="&"+o.query)):t="returnTo="+encodeURIComponent(o.source),window.loc
@rgrove
rgrove / gist:044cc7e9a5b44f583c05
Created April 20, 2015 17:45
New CSS properties added to the relaxed config in Sanitize 4.0.0
  • alignment-adjust
  • alignment-baseline
  • all
  • anchor-point
  • azimuth
  • baseline-shift
  • binding
  • bleed
  • bookmark-label
  • bookmark-level
"use strict";
var _ = SM.import('lodash');
var DOM = SM.import('sm-dom');
var Uri = SM.import('sm-uri');
// WebKit (as of version 538.35.8) fires a useless popstate event after every
// page load, even when the page wasn't popped off the HTML5 history stack. We
// only want to handle popstate events that result from a page actually being
// popped off the HTML5 history stack, so we need a way to differentiate between
@rgrove
rgrove / event-emitter.js
Created July 23, 2014 23:00
Simple ES5 custom event implementation with basic bubbling support, for server or client.
"use strict";
/**
Barebones custom events implementation. Extend or mix in this class to add event
support to your own classes.
Example:
function MyClass() {
// Example of attaching a listener (this isn't required).