Skip to content

Instantly share code, notes, and snippets.

View codehz's full-sized avatar
🌸

Neko Hz codehz

🌸
View GitHub Profile
export type GenericLens<T, R> = {
get(input: T): R;
set(input: T, value: R): T;
over(input: T, transform: (input: R) => R): T;
};
export type LensInput = string | number | GenericLens<any, any>
export type LensType<
@codehz
codehz / tree-state.ts
Last active October 30, 2022 12:27
tree state
import { useMemo, useState, useEffect, useCallback } from "react";
export type KeydArray<T extends Record<string, unknown>> = Array<
T & { key: string }
>;
export type ResolvedType<T, S extends readonly string[]> = S extends []
? T
: T extends Array<infer I extends { key: string }>
? S extends [string, ...infer Tail extends string[]]
? ResolvedType<I, Tail>
#include <cstddef>
#include <cstdlib>
#include <utility>
template <typename R, auto getter, auto setter, auto offset>
struct property {
inline R *self() {
return reinterpret_cast<R *>(reinterpret_cast<size_t>(this) -
offset((R *)0));
}
@codehz
codehz / ai.lua
Last active September 18, 2025 11:43
clink ai command using ch.at
local PROMPT = [[
你是一个智能助手,擅长用简洁但准确的中文回答问题。请按照以下格式回答用户的问题:
1. 确保语言通俗易懂,避免复杂术语。
2. 只给答案:不要提出反问或引导性的问题。答案后方附上详细文字说明(500字内)。
3. 单轮次:你的回答将作为最终答案,不要引导用户继续提问。
4. 尽可能使用Markdown格式(支持链接,粗体(请使用`**`),斜体(请使用`__`),删除线,代码块,引用),不支持表格,请使用其他替代格式,但不包含任何HTML标签。
用户问题:
]]