Skip to content

Instantly share code, notes, and snippets.

@jasonphillips
jasonphillips / machine.js
Created February 24, 2020 00:22
Generated by XState Viz: https://xstate.js.org/viz
// Available variables:
// - Machine
// - interpret
// - assign
// - send
// - sendParent
// - spawn
// - raise
// - actions
@jasonphillips
jasonphillips / graphql_tools.py
Last active April 7, 2020 12:38
python graphql-tools imitation
import graphql
# build_executable schema
#
# accepts schema_definition (string) and resolvers (object) in style of graphql-tools
# returns a schema ready for execution
def build_executable_schema(schema_definition, resolvers):
ast = graphql.parse(schema_definition)
schema = graphql.build_ast_schema(ast)
@jasonphillips
jasonphillips / omit.js
Created November 9, 2017 17:24
omit "One"-liner
const omit = (obj, omitProps) => Object.keys(obj)
.filter(key => omitProps.indexOf(key)===-1)
.reduce((returnObj, key) => ({ ...returnObj, [key]: obj[key] }), {})
@jasonphillips
jasonphillips / .babelrc
Last active October 30, 2017 19:01
babel error with Set() and spread syntax, when using "loose":true
{
"presets": [["env", {
"loose": true
}
]]
}
@jasonphillips
jasonphillips / pick.js
Last active May 11, 2017 16:08
Pick "One"-Liner
const pick = (obj, props) => Array.prototype.reduce.call(
props,
(built, prop) => (
Object.prototype.hasOwnProperty.call(obj, prop)
? Object.assign({}, built, {[prop]: obj[prop]})
: built
), {}
)
@jasonphillips
jasonphillips / JackRabbit.js
Last active April 18, 2017 15:37
RabbitMQ Router (Express-like) for Topic Exchanges
const amqp = require('amqplib');
class JackRabbit {
constructor(url, opts) {
this.channel = this.makeConnection(url, opts);
this.errorCB = (error) => console.log(error);
this.exchanges = {};
this.queued = {};
this.channel.catch((error) => this.errorCB(error));
@jasonphillips
jasonphillips / cardboard.glsl
Last active April 6, 2020 06:52
Lens distortion for Dolphin emulator (for VR viewers) as custom shader
/*
[configuration]
[OptionRangeInteger]
GUIName = Distortion amount
OptionName = DISTORTION_FACTOR
MinValue = 1
MaxValue = 10
StepAmount = 1
DefaultValue = 4
@jasonphillips
jasonphillips / responsiveTable.js
Last active January 5, 2018 10:21
React table elements with automatic pivoting to list-style view for mobile
import React from 'react';
/* context helpers from:
* https://gist.github.com/ryanflorence/1e1290571337ebcea1c5a748e8f5b37d
*/
import provideContext from './provideContext';
import withContext from './withContext';
const contextShape = React.PropTypes.shape({
@jasonphillips
jasonphillips / config.js
Last active June 24, 2018 13:10
Jupyter NodeJS: HTML Output (and React Demonstration)
module.exports = {
extensions: {
// clojurescript: require('./ext/clojurescript'),
clojure: require('./build/ext/clojure'),
clojurescript: require('./build/ext/clojurescript'),
coffee: require('./build/ext/coffee'),
babel: require('./build/ext/babel'),
html: require('./build/ext/html')
}
}
@jasonphillips
jasonphillips / Post.js
Last active December 14, 2015 03:15
Declarative, Isomorphic Falcor data in React.js
// Main Post component, which initiates data fetching
import React from "react";
import { resolve, context } from "react-resolver";
import PostBody from "./PostBody.js";
import PostMeta from "./PostMeta.js";
/**
* Falcor routes constructed below: