Skip to content

Instantly share code, notes, and snippets.

View HerringtonDarkholme's full-sized avatar

Herrington Darkholme HerringtonDarkholme

View GitHub Profile

Using open source software can be a double-edged sword: We enjoy the latest features and innovations, but we hate frequent and sometimes tedious upgrades.

Bevy is a fast and flexible game engine written in Rust. It aims to provide a modern and modular architecture, notably Entity Component System(ECS), that allows developers to craft rich and interactive experiences. However, the shiny new engine is also an evolving project that periodically introduces breaking changes in its API. Bevy's migration guide is comprehensive, but daunting. It is sometimes overwhelmingly long because it covers many topics and scenarios.

In this article, we will show you how to make migration easier by using some command line tools such as git, cargo and ast-grep. These tools can help you track the changes, search for specific patterns in your code, and automate API migration. Hope

@HerringtonDarkholme
HerringtonDarkholme / repro.ts
Last active March 11, 2023 17:17
repro weird ts 5.1 error
type ComponentPublicInstance<C, Options> = {
$options: Options & 'intersection anything'
} & ExtractComputedReturns<C>
type WhatEver<T> = T extends 1 ? true : false
type MixinToOptionTypes<T> = T extends ComponentOptionsBase<
infer C, 1, 1
>
? OptionTypesType<C>
# I am comment
# Basic Data type
123 # int
12.3 # float
6.0221409e+23 # scentific notation
true # bool
"string"
# String Operation
@HerringtonDarkholme
HerringtonDarkholme / commutative.ts
Created December 3, 2020 06:47
Example for comutative intersection type
// https://www.typescriptlang.org/play?ts=4.1.2#code/C4TwDgpgBAsg9gEwgGwDwwHxQLxQN4BQUxUwEAzsAFxQCMATAMwEC+UAZLAaJFAII58AOwgB3ABQBKGvCRo8AQxoNGLDC27hoAIUF4RE6bEQpUAVyEBrIXFFD1m3gGFBAztsfQAIoN2c+BARIAMbICgBO0ABuEVDBNC4EMeFQCoIGcQQKAHRp7Jw5ZJRBEKER0bEIND5JsQBG6WJQCAR1uRycbUXAQA
type Model<M> = {
test: 123
} & M
type A = {new(): Model<{a: 123}>}
type B = {new(): Model<unknown>}
type C = A & B
type D = B & A
@HerringtonDarkholme
HerringtonDarkholme / index.html
Last active March 18, 2020 16:54
PreventDefault in Web Worker
<a class="worker" href="javascript:alert('not prevented')">preventDefault works!</a>
<a class="non-worker" href="javascript:alert('not prevented')">preventDefault doesn't work...</a>
<script>
function createWorker(fn) {
const blob = new Blob([`(${fn.toString()})()`], {type: 'application/javascript'})
const url = URL.createObjectURL(blob)
return new Worker(url)
}
const WAITING = 0
@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
*/
@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 / 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 / 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 / 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),