Skip to content

Instantly share code, notes, and snippets.

View thomasboyt's full-sized avatar

Thomas Boyt thomasboyt

View GitHub Profile
import * as React from 'react';
import {ColorScheme} from '../../universal/resources';
interface Context {
colorScheme: ColorScheme;
}
/**
* Injects this.context.colorScheme as a prop
Polymer({
is: "google-legacy-loader",
behaviors: [Polymer.IronJsonpLibraryBehavior],
properties: {
libraryUrl: {
type: String,
value: "https://www.google.com/jsapi?callback=%%callback%%"
},
notifyEvent: {
type: String,
@thomasboyt
thomasboyt / harmonograph.pde
Created October 6, 2012 13:05
Harmonograph in Processing
float d[] = new float[4];
float f[] = new float[4];
float p[] = new float[4];
float E = exp(1);
PVector current_pt;
PVector center;
void setup() {

redux "request" idea

(this is adapted from the redux-happy-async project I made earlier this year, but I think simplified in an easier-to-understand way)

Why?

Managing async action state in Redux is a very, very common topic of discussion. The classical way to do it is to create three action types (for start, error, and success), and then create boilerplate to set loading/error states for each action inside a reducer. This boilerplate adds up fast if you're creating an app with lots of async actions!

This library abstracts away this boilerplate with a ✨ magic ✨ requests reducer that will handle storing and retrieving this state across your application.

interface PromiseExtender extends Promise<any> {
}
function bar(): PromiseExtender {
return new Promise((resolve, reject) => {});
}
async function foo() {
await bar(); // raises error: "Operand for 'await' does not have a valid callable 'then' member."
}
@thomasboyt
thomasboyt / react.md
Last active September 15, 2016 09:23
ReactJS's interesting build step

React does a really interesting thing with its build process that I haven't seen elsewhere.

React uses what appears to be CommonJS syntax in its files. For example, in ReactDOM.js:

var ReactDescriptor = require('ReactDescriptor');
var ReactDescriptorValidator = require('ReactDescriptorValidator');
var ReactLegacyDescriptor = require('ReactLegacyDescriptor');
var ReactDOMComponent = require('ReactDOMComponent');
@thomasboyt
thomasboyt / reverse.js
Created August 18, 2016 01:32
why is js's implementation of reverse() so awful
> var a = [1,2,3]
undefined
> a.reverse()
[ 3, 2, 1 ]
> a
[ 3, 2, 1 ]
// [insert price is right losing horn here]

Deployment Goals

  1. Deploy static site frontend to somewhere that properly cache busts everything
  2. Deploy Node.js WebSockets backend with to somewhere that will, long-term, give me the option to easily add a Redis instance
  3. Connect frontend in (1) to (2)
  4. Spend no less than like $10/month on this whole thing (excepting like a domain and DNS)

Candidates

My DigitalOcean VPS

So, in my TypeScript library, I import a module and return a type from it in an exported function:

// myLib/src/index.ts
import * as SAT from 'sat';

export function getCollisionResponse(a: SAT.Polygon, b: SAT.Polygon): SAT.Response {
  const res = new SAT.Response();
  SAT.testPolygonPolygon(a, b, res);
 return res;
const SixtyFps = React.createClass({
componentDidMount() {
this.rafCb = this.renderLoop;
window.requestAnimationFrame(this._rafCb);
},
componentWillUnmount() {
this.rafCb = () => {};
},