Skip to content

Instantly share code, notes, and snippets.

View aldendaniels's full-sized avatar

Alden Daniels aldendaniels

View GitHub Profile
enum Make {
Kia = 'Kia',
Ford = 'Ford',
Honda = 'Honda'
}
interface BaseCar {
make: Make;
color: string;
}
@aldendaniels
aldendaniels / why-codr.md
Last active June 7, 2017 00:41
The use case for Codr

To learn more about Codr, see http://codr.io.

What Codr Isn't

Codr is not an IDE: it’s not a development environment at all. Codr will not provide remote file-system access, terminal access, or other features necessary to use Codr as a coding environment.

Codr is also not designed to support pair programming. To pair program, you need access to a full development environment, including the ability to actually run the program in question.

For the pair programming use-case, I'd highly recommend Screen Hero or a shared tmux/screen/byobu session if coding in the terminal is your thing.

@aldendaniels
aldendaniels / alternative-to-higher-order-components.md
Last active October 6, 2018 09:50
Alternative to Higher-order Components

React now supports the use of ES6 classes as an alternative to React.createClass().

React's concept of Mixins, however, doesn't have a corollary when using ES6 classes. This left the community without an established pattern for code that both handles cross-cutting concerns and requires access to Component Life Cycle Methods.

In this gist, @sebmarkbage proposed an alternative pattern to React mixins: decorate components with a wrapping "higher order" component that handles whatever lifecycle methods it needs to and then invokes the wrapped component in its render() method, passing through props.

While a viable solution, this has a few drawbacks:

  1. There's no way for the child component to override functionality defined on the higher order component.
@aldendaniels
aldendaniels / index.js
Last active August 29, 2015 14:16
requirebin sketch
// See http://stackoverflow.com/questions/27446960/immutable-js-relationships?nah=1#28730230
var Immutable = require('immutable');
var React = require('react/addons');
var emitter = require('event-emitter');
var store = (function() {
// John has two children named Alice and Bob.
// John's child Bob has a cat named Orion.
var state = new Immutable.fromJS({
people: [
@aldendaniels
aldendaniels / simple-class.js
Created December 15, 2014 18:04
Simple Class
/* Simple JavaScript Inheritance
* By John Resig http://ejohn.org/
* MIT Licensed.
* Modified for code readability and added bindMethods() feature.
*/
// Inspired by base2 and Prototype
var initializing = false;
var fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
// The base Class implementation (does nothing)
@aldendaniels
aldendaniels / document-snippet.js
Last active January 2, 2016 21:59
Ace document.applyDelta function that splits 'remove' deltas.
this.applyDelta = function(delta) {
// Split large insert deltas. This is necessary because:
// 1. We need to support splicing delta lines into the document via $lines.splice.apply(...)
// 2. fn.apply() doesn't work for a large number of params. The mallest threshold is on safari 0xFFFF.
if (delta.lines.length > 65000)
{
// Get split deltas.
var deltas = [];
var fnPush = (delta.action == 'insert' ? Array.prototype.push : Array.prototype.unshift); // Fire delete actions in reverse.