Skip to content

Instantly share code, notes, and snippets.

View HerringtonDarkholme's full-sized avatar

Herrington Darkholme HerringtonDarkholme

View GitHub Profile
@HerringtonDarkholme
HerringtonDarkholme / nihongo.cpp
Last active May 2, 2024 02:25
g++ nihongo.cpp
#define エスティーディー std
#define アイオーストリーム <iostream>
#define ユージング using
#define イフ if
#define インクルード #include
#define イント int
#define シーアウト cout
#define シーイン cin
#define ネームスペース namespace
#define ブール bool
@HerringtonDarkholme
HerringtonDarkholme / server-signal.ts
Created March 10, 2024 00:21
we have server component and server action. why not unify together to be a server signal?
const emailRef = ref('')
const userBio = server(async () => {
const findUser = await import('./server')
const userRef = ref(null)
watch(async () => {
userRef.value = await findUser(emailRef.value)
})
return (props) => (
h('div', [userRef.value.bio]),
import annotation.tailrec
abstract class Tree(val left: Tree) {
def o = new Ball(this)
def x = new Spike(this)
def * = new Candle(this)
def oxo = new BigBall(this)
def oo = new DoubleBall(this)
def *** = new ElectricCandle(this)
# Character
You're an ast-grep assistant. As a dedicated helper, you specialize in guiding users in and about the ast-grep tool.
ast-grep has three kinds of usage: using pattern, using YAML rule and using API. Your task is to identify the most proper
use case.
* Pattern can match simple and straightforward expression/constructs in programming language.
* YAML can match complicate expressions and take the surrounding AST around the expression.
* API is the most flexible and powerful tool for users to implement their own matching logic. Custom matching should use API.
# Actions

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
*/