Skip to content

Instantly share code, notes, and snippets.

David Manning dlmanning

Block or report user

Report or block dlmanning

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
@dlmanning
dlmanning / monty.js
Last active Jun 19, 2017
Simulation of the Monty Hall problem
View monty.js
/*
There are a certain number of doors (usually 3). Behind one is a prize. Behind the others are goats.
The contestant picks a door, and then the host removes one of the non-selected choices that did contain
the prize. The contestant is given the option to either keep their original choice, or switch to one of
the remaining doors. What should they do?
Let's simulate their potential decisions to find out!
*/
const doors = [1, 2, 3]
@dlmanning
dlmanning / injected.js
Created Apr 20, 2017
Script comcast injected in my http response to show me a modem ad
View injected.js
// Copyright (C) 2015 Comcast Cable Communications, LLC
// Contact Us: http://customer.xfinity.com/contact-us/
// Intended use of this message is to display critical and time sensitive notifications to customers.
/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
View async.js
'use strict'
const async = makeGenerator => function () {
const generator = makeGenerator.apply(this, arguments);
const handle = result =>
result.done
? Promise.resolve(result.value)
: Promise.resolve(result.value)
.then(res => handle(generator.next(res)))
@dlmanning
dlmanning / transducer.js
Last active Jan 13, 2016
tiny little transducer util made with universal-reduce
View transducer.js
import reduce from 'universal-reduce'
const transduce = (put, initial) => (collection, ...xfs) =>
reduce(collection, (accum, value, key) =>
put(
accum,
key,
reduce(xfs, (result, xf) => xf(result), value)
),
initial
@dlmanning
dlmanning / branchDispatch.js
Last active Dec 18, 2015
dispatch keyed values to keyed functions
View branchDispatch.js
const branchDispatch = (obj, table, defaultFn) =>
Object.entries(obj)
.map(([key, value]) =>
table[key] != null
? [key, table[key](value)]
: typeof defaultFn === 'function'
? [key, defaultFn(value)]
: [key, undefined]
)
.reduce((results, [key, value]) => {
@dlmanning
dlmanning / checkbox.js
Last active Dec 17, 2015
A sample checkbox whose outerlayer is an instyled component
View checkbox.js
import React, { Component } from 'react'
import instyled, { flatKeyed } from 'instyled'
import cascade from 'cascade'
const CheckboxContainer = instyled(flatKeyed(cascade({
display: 'flex',
width: 'fit-content',
padding: 10,
borderRadius: 7,
background: 'gray',
@dlmanning
dlmanning / toolbar.js
Last active Dec 16, 2015
How I make react components without react
View toolbar.js
import Icon from 'react-fa'
import hoverable from 'lib/hocs/hoverable'
import instyled, { flatKeyed } from 'instyled'
import cascade from 'cascade'
export const EditButton = hoverable(
instyled(
flatKeyed(
cascade({
position: 'absolute',
@dlmanning
dlmanning / makeConnector.js
Last active Nov 20, 2015
Connect higher-order component from internal closure.
View makeConnector.js
export function makeConnector (store) {
return function connect(mapStateToProps, mapDispatchToProps, mergeProps, options = {}) {
// same stuff
return function wrapWithConnect(WrappedComponent) {
return class Connect extends Component {
// same stuff
constructor(props) {
super(props)
this.store = props.store || store
// same stuff
@dlmanning
dlmanning / hoverable-hoc.js
Created Nov 7, 2015
Simple higher-order React component to make a compoent react to hover events.
View hoverable-hoc.js
function hoverable (WrappedComponent, propName = 'hover') {
return class HoverableComponent extends Component {
constructor (props) {
super(props)
this.state = { hovered: false }
}
turnHoverOn () {
this.setState({ hovered: true })
@dlmanning
dlmanning / does-not-work.jsx
Last active Aug 29, 2015
Why doesn't the spread operator work in JSX?
View does-not-work.jsx
import { default as React, Component } from 'react';
function makeElements () {
return [
<h1>Hello</h1>,
<h1>World,</h1>,
<h1>How</h1>,
<h1>are</h1>,
<h1>you?</h1>
]
You can’t perform that action at this time.