Skip to content

Instantly share code, notes, and snippets.

View HerringtonDarkholme's full-sized avatar

Herrington Darkholme HerringtonDarkholme

View GitHub Profile
@HerringtonDarkholme
HerringtonDarkholme / facai.vue
Created September 26, 2016 16:30
high order component template in Vue2.0
<template>
<p>
<haha>
<v-template inline-template>
<span>{{$ctx.name}}说: 闷声发大财 +{{$ctx.i}}s<br/></span>
</v-template>
</haha>
</p>
</template>
@HerringtonDarkholme
HerringtonDarkholme / nested-for.ts
Created September 25, 2016 08:35
Nested For implementation in Angular2
import {
Component, NgModule, TemplateRef,
Directive, Input, ViewContainerRef,
Compiler, OnChanges, ComponentFactory
} from '@angular/core'
import { CommonModule } from '@angular/common'
@Component({
template: `
@HerringtonDarkholme
HerringtonDarkholme / mytyping.py
Created August 14, 2016 07:24
literal style type annotation experiment in Python3
from typing import Union, TypeVar, _type_check, TypingMeta
import builtins
class MyTypingMeta(type):
def __or__(self, tpe):
return Union[self, tpe]
class MyTypeVar(TypeVar, metaclass=TypingMeta, _root=True):
def __pos__(self):
self.__covariant__ = True
@HerringtonDarkholme
HerringtonDarkholme / test.js
Created May 24, 2016 16:28
babel5 breaks when promise is included
// webpack.config.js
module.exports = {
entry: {
'test': './test',
},
output: {
filename: 'output.js',
},
module: {
loaders: [
@HerringtonDarkholme
HerringtonDarkholme / index.ts
Last active March 22, 2019 17:17
typesafe DI in TypeScript
/// <reference path='./typings/tsd.d.ts' />
import 'reflect-metadata'
type _ = {}
type ClassN<N, T> = { new (...a: N[]): T }
type FN8<A, B, C, D, E, F, G, H, R> = (a?: A, b?: B, c?: C, d?: D, e?: E, f?: F, g?: G, h?: H) => R
type CLS8<A, B, C, D, E, F, G, H, R> = { new (a?: A, b?: B, c?: C, d?: D, e?: E, f?: F, g?: G, h?: H): R}
<!--
postMessage(navigator.appName);
/*
-->
<!doctype html>
<title>navigator.appName</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
<script>
@HerringtonDarkholme
HerringtonDarkholme / typescript_neomake.vim
Last active February 3, 2016 09:57
Read tsconfig dynamically
let s:enabled_options = [
\ 'target', 'emitDecoratorMetadata', 'experimentalDecorators', 'module',
\ 'noImplicitAny', 'rootDir', 'noEmit', 'allowSyntheticDefaultImports',
\ 'noImplicitReturn', 'allowUnreachableCode', 'allowUnusedLabels'
]
function! neomake#makers#ft#typescript#tsc()
let l:tsconfig = findfile('tsconfig.json', '.;')
if len(l:tsconfig)
let true = 1
@HerringtonDarkholme
HerringtonDarkholme / typescript.ctags
Created October 10, 2015 08:37
An updated ctags file for typescript
--langdef=typescript
--langmap=typescript:.ts
--regex-typescript=/^[ \t]*(export)?[ \t]*class[ \t]+([a-zA-Z0-9_]+)/\2/c,classes/
--regex-typescript=/^[ \t]*(export)?[ \t]*abstract class[ \t]+([a-zA-Z0-9_]+)/\2/a,abstract classes/
--regex-typescript=/^[ \t]*(export)?[ \t]*module[ \t]+([a-zA-Z0-9_]+)/\2/n,modules/
--regex-typescript=/^[ \t]*(export)?[ \t]*type[ \t]+([a-zA-Z0-9_]+)/\2/t,types/
--regex-typescript=/^[ \t]*(export)?[ \t]*namespace[ \t]+([a-zA-Z0-9_]+)/\2/n,modules/
--regex-typescript=/^[ \t]*(export)?[ \t]*function[ \t]+([a-zA-Z0-9_]+)/\2/f,functions/
--regex-typescript=/^[ \t]*export[ \t]+var[ \t]+([a-zA-Z0-9_]+)/\1/v,variables/
--regex-typescript=/^[ \t]*var[ \t]+([a-zA-Z0-9_]+)[ \t]*=[ \t]*function[ \t]*\(\)/\1/l,varlambdas/
@HerringtonDarkholme
HerringtonDarkholme / inject.ts
Last active September 20, 2015 16:42
TypeScript Decorator Collection
function inject(...injectionKeys : Array<string>) {
return function decoratorFactory(target : Object|Function, decoratedPropertyName? : string) : void {
let targetType : Function;
let injectionPoint : InjectionPoint;
// Decorator applied to Class (for Constructor injection).
if (typeof target === 'function' && decoratedPropertyName === undefined) {
targetType = target;
injectionPoint = new ConstructorInjectionPoint(injectionKeys);
}
/// <reference path='./es6-collections.d.ts' />
declare var require: any
require('es6-collections')
class Caller<T> {
private callers: T[] = []
constructor(init?: T) {
if (init !== undefined) this.callers.push(init)
}
withValue(t: T): Function {