Skip to content

Instantly share code, notes, and snippets.

View robertpenner's full-sized avatar

Robert Penner robertpenner

View GitHub Profile
@michelsalib
michelsalib / timestampable.ts
Created April 22, 2015 15:52
Typescript @timestampable annotation
@timestampable
class Dog {
public name: string = 'Paul';
}
function timestampable(func) {
return <any>(function() {
var genericConstructor = () => {};
genericConstructor.prototype = func.prototype;
var instance = new genericConstructor();
#Workflow:: CompStak
credentials:
username:
password:
account:
line:
title: CompStack V1.0
template_id: DaAvql4Ayi
@PatrickJS
PatrickJS / rxPipeRegistry.ts
Last active November 12, 2015 16:51
rx support for Angular 2 Async Pipe
/// <reference path="../../typings/tsd.d.ts" />
///
import {PipeFactory} from 'angular2/src/change_detection/pipes/pipe';
import {async} from 'angular2/src/change_detection/change_detection';
import {NullPipeFactory, Pipe, PipeRegistry, defaultPipes} from 'angular2/change_detection';
import {bind} from 'angular2/di';
import {ObservablePipe} from 'angular2/pipes';
import * as Rx from 'rx';
export function isObservable(obs) {
import {Component} from 'angular2/core';
import {bootstrap} from 'angular2/platform/browser';
import 'rxjs/Rx';
import {HTTP_PROVIDERS, Http} from 'angular2/http';
@Component({
selector: 'app',
template: `
<ul *ngFor="#person of people | async">
{{person.name}}
</ul>
@bendc
bendc / toRGB.js
Created May 11, 2015 20:16
Hexadecimal to RGB converter
const toRGB = (() => {
const expand = hex =>
hex.length < 7 ? hex.split("").reduce((a, b) => a + b + b) : hex;
const convert = hex =>
hex.match(/[\d\w]{2}/g).map(val => parseInt(val, 16));
return hex => {
const [r, g, b] = convert(expand(hex));
return `rgb(${r}, ${g}, ${b})`;
};
})();
@AndrewRayCode
AndrewRayCode / easing.js
Created March 13, 2016 05:01
ES6 module-ified easing functions, based on https://gist.github.com/gre/1650294
// based on https://gist.github.com/gre/1650294
// no easing, no acceleration
export function linear( t ) {
return t;
}
// accelerating from zero velocity
export function easeInQuad( t ) {
return t * t;
[] + []; // JavaScript will give you "" (which makes little sense), TypeScript will error
//
// other things that are nonsensical in JavaScript
// - don't give a runtime error (making debugging hard)
// - but TypeScript will give a compile time error (making debugging unnecessary)
//
{} + []; // JS : 0, TS Error
[] + {}; // JS : "[object Object]", TS Error
{} + {}; // JS : NaN, TS Error
@nesbtesh
nesbtesh / createReducer.js
Created August 24, 2016 13:32
Create Reducer Redux
export function createReducer(initialState, reducerMap) {
return (state = initialState, action) => {
const reducer = reducerMap[action.type];
return reducer
? reducer(state, action.payload)
: state;
};
}
@anaisbetts
anaisbetts / sparse-map.ts
Created February 15, 2017 22:58
TypeScript Is Amazing
//
// WRONG
///
class InMemorySparseMap<K, V> implements SparseMap<K, V> {
private latest: Map<K, Updatable<V>>;
private factory: ((key: K) => Observable<V>) | undefined;
subscribe(key: K): Updatable<V> {
let ret = this.latest.get(key);
@satomacoto
satomacoto / labeledarrow.html
Created August 18, 2012 06:56
labeled arrow w/ D3.js
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="http://d3js.org/d3.v2.js"></script>
<style>
line.arrow {
stroke: #666;