Skip to content

Instantly share code, notes, and snippets.

View HerringtonDarkholme's full-sized avatar

Herrington Darkholme HerringtonDarkholme

View GitHub Profile
@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 / 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 / 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 / vue.vim
Last active October 3, 2016 16:42
vue syntax highlighting
" Vim syntax file
" Language: Vue.js
" Maintainer: Eduardo San Martin Morote
if exists("b:current_syntax")
finish
endif
if !exists("s:syntaxes")
" Search available syntax files.
@HerringtonDarkholme
HerringtonDarkholme / ctrlp.vim
Last active July 6, 2019 17:48
give syntax highlight for ctrlp vim-devicon
"I borrowed this crazy code from vim-tomorrow-theme colorschemes
" Returns an approximate grey index for the given grey level
fun! s:grey_number(x)
if &t_Co == 88
if a:x < 23
return 0
elseif a:x < 69
return 1
elseif a:x < 103
@HerringtonDarkholme
HerringtonDarkholme / 1.ts
Last active November 21, 2016 10:06
Translate vue template into hand write template code
h('div', {class: 'el-autocomplete', directive: ['clickoutside']}, [
h('el-input', { props: {
value: this.value,
disabled: this.disabled,
placeholder: this.placeholder,
name: this.name,
size: this.size,
}, on: {
change: this.handleChange.bind(this),
focus: this.handleFocus.bind(this),
@HerringtonDarkholme
HerringtonDarkholme / wtf.ts
Last active November 22, 2016 16:23
WTF have I written?
export type HTML = {
div: IfTag<HTML, 'div'>
p: IfTag<HTML, 'p'>
ul: UL<HTML>
ol: OL<HTML>
img: () => HTML
}
export type Comp<Parent, End extends string> = {
props(prop: {[k: string]: any}): Comp<Parent, End>
@HerringtonDarkholme
HerringtonDarkholme / example.json
Created March 20, 2017 10:34
example vscode response
{"jsonrpc":"2.0","id":2,"result":{"isIncomplete":false,"items":[{"label":"aria-activedescendant","kind":12,"textEdit":{"range":{"start":{"line":3,"character":13},"end":{"line":3,"character":14}},"newText":"aria-activedescendant=\"$1\""},"insertTextFormat":2},{"label":"aria-atomic","kind":12,"textEdit":{"range":{"start":{"line":3,"character":13},"end":{"line":3,"character":14}},"newText":"aria-atomic=\"$1\""},"insertTextFormat":2},{"label":"aria-autocomplete","kind":12,"textEdit":{"range":{"start":{"line":3,"character":13},"end":{"line":3,"character":14}},"newText":"aria-autocomplete=\"$1\""},"insertTextFormat":2},{"label":"aria-busy","kind":12,"textEdit":{"range":{"start":{"line":3,"character":13},"end":{"line":3,"character":14}},"newText":"aria-busy=\"$1\""},"insertTextFormat":2},{"label":"aria-checked","kind":12,"textEdit":{"range":{"start":{"line":3,"character":13},"end":{"line":3,"character":14}},"newText":"aria-checked=\"$1\""},"insertTextFormat":2},{"label":"aria-colcount","kind":12,"textEdit":{"range":
@HerringtonDarkholme
HerringtonDarkholme / VSCode error
Created April 6, 2018 07:52
TypeScript Error reproduciton
Error processing request. Cannot set property 'typeParameters' of undefined
TypeError: Cannot set property 'typeParameters' of undefined
at assignContextualParameterTypes (/project/node_modules/typescript/lib/tsserver.js:36049:38)
at checkFunctionExpressionOrObjectLiteralMethod (/project/node_modules/typescript/lib/tsserver.js:36336:29)
at checkObjectLiteralMethod (/project/node_modules/typescript/lib/tsserver.js:37103:38)
at checkObjectLiteral (/project/node_modules/typescript/lib/tsserver.js:33798:32)
at checkExpressionWorker (/project/node_modules/typescript/lib/tsserver.js:37192:28)
at checkExpression (/project/node_modules/typescript/lib/tsserver.js:37144:42)
at checkExpressionForMutableLocation (/project/node_modules/typescript/lib/tsserver.js:37088:24)
at checkPropertyAssignment (/project/node_modules/typescript/lib/tsserver.js:37096:20)
@HerringtonDarkholme
HerringtonDarkholme / get-types.ts
Last active September 17, 2019 19:01
A demonstration of variadic generic in TS3.0
/**
* This gist demonstrates how powerful TypeScript's new tuple type is.
* Say, we want to write a function that receive multiple arguments, and return a tuple of arguments' types.
* For example, `getTypes(1, true, 'str')` return a tuple `['number', 'boolean', 'string']`.
* We can do that in **type safe** way in TypeScript now! And actually we can do the computation at compile time!
* This is so like dependent type in TypeScript!
* Reference: https://github.com/Microsoft/TypeScript/pull/24897
*/