Skip to content

Instantly share code, notes, and snippets.

View vikiboss's full-sized avatar
🐈
loading...

Viki vikiboss

🐈
loading...
View GitHub Profile
@vikiboss
vikiboss / preview.js
Created October 16, 2026 01:29
preview.js
// preview.js
// @from https://www.thenodebook.com/blog/fast-nodejs-doing-less#where-it-ended-up
import * as cheerio from 'cheerio';
const OK_TTL = 60 * 60 * 1000; // 1 hour
const FAILURE_TTL = 60 * 1000; // 1 minute
const TIMEOUT = 4000;
const MAX_HEAD_BYTES = 512 * 1024;
class LRU {
@vikiboss
vikiboss / koa.ts
Last active September 16, 2026 04:44
Koa 洋葱模型中间件核心
type Next = () => Promise<void> | void;
type Middleware = (ctx: any, next: Next) => Promise<void> | void;
class Koa {
#middlewares: Middleware[] = [];
use(middleware: Middleware) {
this.#middlewares.push(middleware);
return this;
}
@vikiboss
vikiboss / express.ts
Created September 16, 2026 04:43
express 中间件核心
type Middleware = (next: (err?: unknown) => void) => void | Promise<void>
function express() {
const middlewares: Middleware[] = []
return {
use(fn: Middleware) {
middlewares.push(fn)
return this
},
@vikiboss
vikiboss / repo.sh
Last active April 2, 2026 06:33
repo.sh
# 公开仓库的 PAT 即可,无任何敏感权限,仅用于提高 GitHub API 速率限制
# 将本文件内容放到 ~/.bashrc 或者 ~/.zshrc 即可通过 `repo vikiboss/60s` 快速查询仓库大小等信息
# Public-repo-only PAT for higher API rate limits.
export GITHUB_RATE_LIMIT_PAT="github_pat_xxx"
# size(KB)转可读字符串
_repo_size() {
local kb=$1
if (( kb < 1024 )); then
# 设置 Dock 自动隐藏动画时间为 0.3 秒
defaults write com.apple.dock autohide-time-modifier -float 0.3
# 设置 Dock 自动隐藏延迟为 0 秒(立即隐藏)
defaults write com.apple.dock autohide-delay -float 0
# 重启 Dock 使设置生效
killall Dock
@vikiboss
vikiboss / when.tsx
Last active November 3, 2025 08:19
function When<T>(props: {
condition: T
children?: React.ReactNode | ((data: NonNullable<T>) => React.ReactNode)
fallback?: React.ReactNode
}) {
const { condition, children, fallback } = props
if (condition) {
if (typeof children === 'function') {
return children?.(condition) ?? null
@vikiboss
vikiboss / deep-clone.ts
Last active February 19, 2025 06:57
Deep Clone for TS
function isObject(obj: unknown): obj is Record<string, unknown> {
return typeof obj === 'object' && obj !== null
}
export function deepClone<T>(obj: T, cache: Map<unknown, unknown> = new Map()): T {
if (obj === null || typeof obj !== 'object') {
return obj
}
if (cache.has(obj)) {
@vikiboss
vikiboss / qq-music-free-deepseek-r1.ts
Last active February 19, 2025 06:54
QQ Music Free DeepSeek R1
// const prompt = '请扮演 QQ 群内拥有海量知识储备的全能问答机器人。'
const prompt = '哎呀,好无聊'
;(async () => {
async function putAiChat(message: string = '') {
const res = await fetch(`https://shu6.y.qq.com/cgi-bin/musicu.fcg`, {
method: 'POST',
body: JSON.stringify({
comm: { qq: 10000 },
@vikiboss
vikiboss / mini-reactive.ts
Created December 11, 2024 11:40
Mini Reactive
interface ProxyState {
initialState: object
getNotifyVersion: (nextVersion?: number) => number
createSnapshot: <State extends object>(proxyState: State, version: number) => State
addListener: (listener: (change: Change, nextVersion: number) => void) => () => void
}
const state2proxyCache = new WeakMap<object, object>()
const proxy2proxyStateCache = new WeakMap<object, ProxyState>()
const proxy2snapshotCache = new WeakMap<object, [version: number, snapshot: object]>()
@vikiboss
vikiboss / 【AI 画图】sd-1.0.0.ts
Last active October 22, 2024 15:02
Plugins for KiviBot v1
import { definePlugin, http } from 'kivibot'
export default definePlugin({
name: 'sd',
version: '1.0.0',
setup(ctx) {
ctx.handle('message', async (e) => {
if (e.raw_message.startsWith('#sd ')) {
const hasRight = ctx.isOwner(e) || ctx.isAdmin(e)