Skip to content

Instantly share code, notes, and snippets.

View HerringtonDarkholme's full-sized avatar

Herrington Darkholme HerringtonDarkholme

View GitHub Profile
@HerringtonDarkholme
HerringtonDarkholme / secrete.js
Last active July 10, 2024 07:31
Cyan's secrete
function findCombinations(numbers, targetSum) {
const result = [];
function find(currentSum, index, currentCombination) {
if (currentSum === targetSum) {
result.push([...currentCombination]);
return;
}
if (currentSum > targetSum || index === numbers.length) return;
// Include the number at the current index.
@HerringtonDarkholme
HerringtonDarkholme / effect.md
Last active May 24, 2024 21:42
React Effect Syntax Extension

React Effect Syntax Extension

This syntax extension is a mere fantasy of future React Script syntax. It is not a RFC, proposal or suggestion to React team or community. It is just a fun idea to imagine how React could be in the future.

Read this like a fan-fiction, for fun. :)

Background

There are two recent new features in React community that are introducing new extensions to JavaScript, both syntax and semantics:

@HerringtonDarkholme
HerringtonDarkholme / nihongo.cpp
Last active July 23, 2024 06: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