Skip to content

Instantly share code, notes, and snippets.

Avatar

Charles Pick phpnode

View GitHub Profile
View machine.js
function createApprovalMachine(context) {
return Machine({
id: 'approval',
initial: 'initializing',
context,
states: {
initializing: {
on: {
'': [
View match.js
const invalidMatchSignal = new Error();
function makeProxyThrower(input) {
return new Proxy(input, {
get(target, prop, receiver) {
if (prop in target) {
const result = Reflect.get(target, prop, receiver);
if (typeof result === "object" && result !== null) {
return makeProxyThrower(result);
@phpnode
phpnode / demo.js
Created Jan 19, 2018
Extension methods for JS using proxies!
View demo.js
// @flow
const proxyCache = new WeakMap();
const extensionMethods = new WeakMap();
function extended<T>(instance: T): $Supertype<T> {
if (isPrimitive(instance)) {
return instance;
}
const existingProxy = proxyCache.get(instance);
View constraints.js
// paste me into https://codemix.github.io/flow-runtime/#/try
// (no gist support yet :( )
import t, {reify} from 'flow-runtime';
type ValidURL = string;
(reify: ValidURL).addConstraint(url => {
if (/^(.|\/)/.test(url)) {
return "Don't use relative URLs for some reason";
View somefile.js
type Linkable = {
name: string,
profileURL: string
};
function bigOldObject () {
return {
id: 1,
name: 'foo',
email: 'foo@bar.com',
View react.js
// This is how the world looks at the moment
import {render} from 'react-dom';
render(
<Router>
<Route path="/" component={HomeScreen} />
</Router>,
document.getElementById('root')
);
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Untitled benchmark</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Array#forEach</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
<script src="./suite.js"></script>
</head>
<body>
<h1>Open the console to view the results</h1>
View input.js
function demo (input: Array<number>): Array<number> {
return function blah () {
return function foo () {
return input.map(item => item + 1).map(item => item + 2);
};
};
}
@phpnode
phpnode / leaky-args.js
Created Dec 15, 2014
node --allow-natives-syntax leaky-args.js
View leaky-args.js
'use strict';
function leakyArgs (item) {
var args = Array.prototype.slice.call(arguments, 1);
var total = item;
for (var i = 0, length = args.length; i < length; i++) {
total += args[i] + (300 * 234 * 234234 * 235 * 23433);
}
return total;
}
You can’t perform that action at this time.