Skip to content

Instantly share code, notes, and snippets.

Richard Scarrott richardscarrott

Block or report user

Report or block richardscarrott

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
vktr / rule.js
Created Feb 10, 2018
Add Stripe Customer Id to Auth0 via custom rule
View rule.js
function (user, context, callback) {
user.app_metadata = user.app_metadata || {};
if ('stripe_customer_id' in user.app_metadata) {
context.idToken[''] = user.app_metadata.stripe_customer_id;
return callback(null, user, context);
var stripe = require('stripe')('sk_....');
var customer = {
acdlite /
Last active Oct 23, 2019
Demo: Coordinating async React with non-React views

Demo: Coordinating async React with non-React views

tl;dr I built a demo illustrating what it might look like to add async rendering to Facebook's commenting interface, while ensuring it appears on the screen simultaneous to the server-rendered story.

A key benefit of async rendering is that large updates don't block the main thread; instead, the work is spread out and performed during idle periods using cooperative scheduling.

But once you make something async, you introduce the possibility that things may appear on the screen at separate times. Especially when you're dealing with multiple UI frameworks, as is often the case at Facebook.

How do we solve this with React?

ChrisPenner / heyting-validation.js
Created Aug 23, 2017
Heyting Algebra Validation
View heyting-validation.js
const all = (...preds) => (obj) => => f(obj)).reduce((a, b) => a && b, true)
const any = (...preds) => (obj) => => f(obj)).reduce((a, b) => a || b, false)
const oneOf = (...preds) => (obj) => => f(obj)).reduce((a, b) => a ? !b : b, false)
const has = (prop) => (obj) => obj[prop] !== undefined
const not = (pred) => (obj) => !pred(obj)
const equals = (prop, val) => (obj) => obj[prop] === val
const implies = (f, g) => (obj) => !f(obj) || g(obj);
const validate = all(implies(has('selectedIndex'), equals('isOpen', true)))
dehamzah / generate.js
Last active Nov 30, 2019
Generate secret key in NodeJS
View generate.js
require('crypto').randomBytes(48, function(err, buffer) { var token = buffer.toString('hex'); console.log(token); });
bastman /
Created Mar 31, 2016
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see:

$ docker volume rm $(docker volume ls -qf dangling=true)
$ docker volume ls -qf dangling=true | xargs -r docker volume rm
View alldataloader.js
type BatchLoadFn<K, V> = (keys: Array<K>) => Promise<Array<V | Error>>;
type LoadAllFn<K, V> = () => Promise<Array<[K, V]>>;
type Options<K, V> = {
batch?: boolean,
cache?: boolean,
cacheMap?: CacheMap<K, Promise<V>>,
cacheKeyFn?: (key: any) => any
View weightedRandom.js
function weightedRandom(ar) {
var ar = ar.sort(x => x.w);
var sum = ar.reduce((p, c) => p + c.w, 0);
// normalise
var soFar = 0; => {
o.w = o.w / sum;
o.w += soFar;
soFar += o.w;
jondlm /
Last active Jan 3, 2018
React shallow render lifecycle breakdown

React introduced shallow rendering in 0.13. This is an excellent feature that I wish was included earlier in React. It aims to solve the problem of unit testing components without going through a real, or jsdom mocked, DOM. I couldn't find any info online about what lifecycle events it actually fires. So I did some testing of my own. To reproduce, put component.js and test.js into a folder and run node test.js.

TLDR; shallow rendering only invokes the following lifecycle hooks (in order):

  1. getDefaultProps
  2. getInitialState
  3. componentWillMount stops here until re-render
  4. componentWillReceiveProps
  5. shouldComponentUpdate
  6. componentWillUpdate
isaacsanders /
Created Jan 21, 2012
Joel Spolsky on Equity for Startups

This is a post by Joel Spolsky. The original post is linked at the bottom.

This is such a common question here and elsewhere that I will attempt to write the world's most canonical answer to this question. Hopefully in the future when someone on answers.onstartups asks how to split up the ownership of their new company, you can simply point to this answer.

The most important principle: Fairness, and the perception of fairness, is much more valuable than owning a large stake. Almost everything that can go wrong in a startup will go wrong, and one of the biggest things that can go wrong is huge, angry, shouting matches between the founders as to who worked harder, who owns more, whose idea was it anyway, etc. That is why I would always rather split a new company 50-50 with a friend than insist on owning 60% because "it was my idea," or because "I was more experienced" or anything else. Why? Because if I split the company 60-40, the company is going to fail when we argue ourselves to death. And if you ju

lightsofapollo / gist:1577413
Created Jan 8, 2012
Jasmine reporter to find slow running tests
View gist:1577413
SlowDescribeReporter.prototype = {
threshold: 400,
reportRunnerStarting: function(runner){
var i, len, suites = runner.suites_, self = this;
this.topLevels = {};
for(i = 0, len = suites.length; i < len; i++){
You can’t perform that action at this time.