[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6EMVTJQQ6RQX8639635T60R":3,"skill-same:01M6EMVTJQQ6RQX8639635T60R":60},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":26,"linkOnly":27,"markdownContent":28,"markdownBody":29,"frontMatter":30,"refName":31,"commitSha":32,"skillDirectory":33,"forksCount":34,"repositoryHtmlUrl":35,"repositoryHomepageUrl":36,"ownerHtmlUrl":37,"ownerBlogUrl":6,"ownerDescription":38,"updatedAt":39,"install":40,"resources":53},"01M6EMVTJQQ6RQX8639635T60R","code-patterns",null,"Common code patterns and best practices reference for quick lookup","ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",67,"MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fbenny9193\u002Fcode-patterns\u002FSKILL.md",[],[19,20,21,22,23,24,25],"code","patterns","code patterns","best practices","lookup","common","reference","2026-11-10 10:12:30",false,"---\nname: code-patterns\ndescription: Common code patterns and best practices reference for quick lookup\n---\n\n# Code Patterns Reference\n\nQuick reference for common patterns. Use these as starting points, not rigid templates.\n\n## Creational Patterns\n\n### Factory\n```typescript\n\u002F\u002F When: Creating objects without specifying exact class\ninterface Product { use(): void }\n\nclass ConcreteProductA implements Product {\n  use() { console.log('Using A') }\n}\n\nclass ProductFactory {\n  static create(type: string): Product {\n    const products = { a: ConcreteProductA };\n    return new products[type]();\n  }\n}\n```\n\n### Builder\n```typescript\n\u002F\u002F When: Complex object construction with many optional params\nclass QueryBuilder {\n  private query = { select: '*', from: '', where: [] };\n\n  select(fields: string) { this.query.select = fields; return this; }\n  from(table: string) { this.query.from = table; return this; }\n  where(condition: string) { this.query.where.push(condition); return this; }\n  build() { return this.query; }\n}\n\n\u002F\u002F Usage\nconst query = new QueryBuilder()\n  .select('name, email')\n  .from('users')\n  .where('active = true')\n  .build();\n```\n\n### Singleton\n```typescript\n\u002F\u002F When: Exactly one instance needed (use sparingly!)\nclass Database {\n  private static instance: Database;\n  private constructor() {}\n\n  static getInstance(): Database {\n    if (!Database.instance) {\n      Database.instance = new Database();\n    }\n    return Database.instance;\n  }\n}\n```\n\n## Structural Patterns\n\n### Adapter\n```typescript\n\u002F\u002F When: Making incompatible interfaces work together\ninterface ModernLogger { log(msg: string): void }\n\nclass LegacyLogger {\n  writeLog(message: string, level: number) { \u002F* ... *\u002F }\n}\n\nclass LoggerAdapter implements ModernLogger {\n  constructor(private legacy: LegacyLogger) {}\n  log(msg: string) { this.legacy.writeLog(msg, 1); }\n}\n```\n\n### Decorator\n```typescript\n\u002F\u002F When: Adding behavior without modifying original\ninterface Coffee { cost(): number; description(): string }\n\nclass SimpleCoffee implements Coffee {\n  cost() { return 5; }\n  description() { return 'Coffee'; }\n}\n\nclass MilkDecorator implements Coffee {\n  constructor(private coffee: Coffee) {}\n  cost() { return this.coffee.cost() + 2; }\n  description() { return this.coffee.description() + ' + Milk'; }\n}\n```\n\n## Behavioral Patterns\n\n### Strategy\n```typescript\n\u002F\u002F When: Algorithm should be selectable at runtime\ninterface PaymentStrategy {\n  pay(amount: number): void;\n}\n\nclass CreditCardPayment implements PaymentStrategy {\n  pay(amount: number) { console.log(`Paid ${amount} via credit card`); }\n}\n\nclass PayPalPayment implements PaymentStrategy {\n  pay(amount: number) { console.log(`Paid ${amount} via PayPal`); }\n}\n\nclass Checkout {\n  constructor(private strategy: PaymentStrategy) {}\n  process(amount: number) { this.strategy.pay(amount); }\n}\n```\n\n### Observer\n```typescript\n\u002F\u002F When: Objects need to be notified of state changes\ntype Listener\u003CT> = (data: T) => void;\n\nclass EventEmitter\u003CT> {\n  private listeners: Listener\u003CT>[] = [];\n\n  subscribe(listener: Listener\u003CT>) {\n    this.listeners.push(listener);\n    return () => this.listeners = this.listeners.filter(l => l !== listener);\n  }\n\n  emit(data: T) {\n    this.listeners.forEach(l => l(data));\n  }\n}\n```\n\n## Error Handling Patterns\n\n### Result Type\n```typescript\n\u002F\u002F When: Errors are expected, not exceptional\ntype Result\u003CT, E = Error> =\n  | { ok: true; value: T }\n  | { ok: false; error: E };\n\nfunction divide(a: number, b: number): Result\u003Cnumber, string> {\n  if (b === 0) return { ok: false, error: 'Division by zero' };\n  return { ok: true, value: a \u002F b };\n}\n\nconst result = divide(10, 2);\nif (result.ok) {\n  console.log(result.value); \u002F\u002F 5\n} else {\n  console.error(result.error);\n}\n```\n\n### Retry with Backoff\n```typescript\n\u002F\u002F When: Transient failures are expected\nasync function retry\u003CT>(\n  fn: () => Promise\u003CT>,\n  attempts = 3,\n  delay = 1000\n): Promise\u003CT> {\n  for (let i = 0; i \u003C attempts; i++) {\n    try {\n      return await fn();\n    } catch (e) {\n      if (i === attempts - 1) throw e;\n      await new Promise(r => setTimeout(r, delay * Math.pow(2, i)));\n    }\n  }\n  throw new Error('Unreachable');\n}\n```\n\n## Async Patterns\n\n### Promise Queue\n```typescript\n\u002F\u002F When: Limiting concurrent async operations\nclass PromiseQueue {\n  private queue: (() => Promise\u003Cany>)[] = [];\n  private running = 0;\n\n  constructor(private concurrency: number) {}\n\n  add\u003CT>(fn: () => Promise\u003CT>): Promise\u003CT> {\n    return new Promise((resolve, reject) => {\n      this.queue.push(async () => {\n        try { resolve(await fn()); }\n        catch (e) { reject(e); }\n      });\n      this.process();\n    });\n  }\n\n  private async process() {\n    if (this.running >= this.concurrency || !this.queue.length) return;\n    this.running++;\n    await this.queue.shift()!();\n    this.running--;\n    this.process();\n  }\n}\n```\n\n### Debounce\n```typescript\n\u002F\u002F When: Limiting rapid-fire function calls\nfunction debounce\u003CT extends (...args: any[]) => any>(\n  fn: T,\n  delay: number\n): (...args: Parameters\u003CT>) => void {\n  let timeout: NodeJS.Timeout;\n  return (...args) => {\n    clearTimeout(timeout);\n    timeout = setTimeout(() => fn(...args), delay);\n  };\n}\n```\n\n## Data Patterns\n\n### Repository\n```typescript\n\u002F\u002F When: Abstracting data access\ninterface Repository\u003CT> {\n  findById(id: string): Promise\u003CT | null>;\n  findAll(): Promise\u003CT[]>;\n  save(entity: T): Promise\u003CT>;\n  delete(id: string): Promise\u003Cvoid>;\n}\n\nclass UserRepository implements Repository\u003CUser> {\n  constructor(private db: Database) {}\n\n  async findById(id: string) {\n    return this.db.query('SELECT * FROM users WHERE id = ?', [id]);\n  }\n  \u002F\u002F ... other methods\n}\n```\n\n### Unit of Work\n```typescript\n\u002F\u002F When: Coordinating writes across multiple repositories\nclass UnitOfWork {\n  private operations: (() => Promise\u003Cvoid>)[] = [];\n\n  register(operation: () => Promise\u003Cvoid>) {\n    this.operations.push(operation);\n  }\n\n  async commit() {\n    await this.db.beginTransaction();\n    try {\n      for (const op of this.operations) await op();\n      await this.db.commit();\n    } catch (e) {\n      await this.db.rollback();\n      throw e;\n    }\n  }\n}\n```\n\n## When to Use Each\n\n| Problem | Pattern |\n|---------|---------|\n| Complex object creation | Builder |\n| Multiple similar objects | Factory |\n| Global state (careful!) | Singleton |\n| Incompatible interfaces | Adapter |\n| Adding features dynamically | Decorator |\n| Swappable algorithms | Strategy |\n| Event-based communication | Observer |\n| Expected failures | Result Type |\n| Transient failures | Retry |\n| Rate limiting | Debounce\u002FThrottle |\n| Data access abstraction | Repository |\n| Transactional consistency | Unit of Work |\n","# Code Patterns Reference\n\nQuick reference for common patterns. Use these as starting points, not rigid templates.\n\n## Creational Patterns\n\n### Factory\n```typescript\n\u002F\u002F When: Creating objects without specifying exact class\ninterface Product { use(): void }\n\nclass ConcreteProductA implements Product {\n  use() { console.log('Using A') }\n}\n\nclass ProductFactory {\n  static create(type: string): Product {\n    const products = { a: ConcreteProductA };\n    return new products[type]();\n  }\n}\n```\n\n### Builder\n```typescript\n\u002F\u002F When: Complex object construction with many optional params\nclass QueryBuilder {\n  private query = { select: '*', from: '', where: [] };\n\n  select(fields: string) { this.query.select = fields; return this; }\n  from(table: string) { this.query.from = table; return this; }\n  where(condition: string) { this.query.where.push(condition); return this; }\n  build() { return this.query; }\n}\n\n\u002F\u002F Usage\nconst query = new QueryBuilder()\n  .select('name, email')\n  .from('users')\n  .where('active = true')\n  .build();\n```\n\n### Singleton\n```typescript\n\u002F\u002F When: Exactly one instance needed (use sparingly!)\nclass Database {\n  private static instance: Database;\n  private constructor() {}\n\n  static getInstance(): Database {\n    if (!Database.instance) {\n      Database.instance = new Database();\n    }\n    return Database.instance;\n  }\n}\n```\n\n## Structural Patterns\n\n### Adapter\n```typescript\n\u002F\u002F When: Making incompatible interfaces work together\ninterface ModernLogger { log(msg: string): void }\n\nclass LegacyLogger {\n  writeLog(message: string, level: number) { \u002F* ... *\u002F }\n}\n\nclass LoggerAdapter implements ModernLogger {\n  constructor(private legacy: LegacyLogger) {}\n  log(msg: string) { this.legacy.writeLog(msg, 1); }\n}\n```\n\n### Decorator\n```typescript\n\u002F\u002F When: Adding behavior without modifying original\ninterface Coffee { cost(): number; description(): string }\n\nclass SimpleCoffee implements Coffee {\n  cost() { return 5; }\n  description() { return 'Coffee'; }\n}\n\nclass MilkDecorator implements Coffee {\n  constructor(private coffee: Coffee) {}\n  cost() { return this.coffee.cost() + 2; }\n  description() { return this.coffee.description() + ' + Milk'; }\n}\n```\n\n## Behavioral Patterns\n\n### Strategy\n```typescript\n\u002F\u002F When: Algorithm should be selectable at runtime\ninterface PaymentStrategy {\n  pay(amount: number): void;\n}\n\nclass CreditCardPayment implements PaymentStrategy {\n  pay(amount: number) { console.log(`Paid ${amount} via credit card`); }\n}\n\nclass PayPalPayment implements PaymentStrategy {\n  pay(amount: number) { console.log(`Paid ${amount} via PayPal`); }\n}\n\nclass Checkout {\n  constructor(private strategy: PaymentStrategy) {}\n  process(amount: number) { this.strategy.pay(amount); }\n}\n```\n\n### Observer\n```typescript\n\u002F\u002F When: Objects need to be notified of state changes\ntype Listener\u003CT> = (data: T) => void;\n\nclass EventEmitter\u003CT> {\n  private listeners: Listener\u003CT>[] = [];\n\n  subscribe(listener: Listener\u003CT>) {\n    this.listeners.push(listener);\n    return () => this.listeners = this.listeners.filter(l => l !== listener);\n  }\n\n  emit(data: T) {\n    this.listeners.forEach(l => l(data));\n  }\n}\n```\n\n## Error Handling Patterns\n\n### Result Type\n```typescript\n\u002F\u002F When: Errors are expected, not exceptional\ntype Result\u003CT, E = Error> =\n  | { ok: true; value: T }\n  | { ok: false; error: E };\n\nfunction divide(a: number, b: number): Result\u003Cnumber, string> {\n  if (b === 0) return { ok: false, error: 'Division by zero' };\n  return { ok: true, value: a \u002F b };\n}\n\nconst result = divide(10, 2);\nif (result.ok) {\n  console.log(result.value); \u002F\u002F 5\n} else {\n  console.error(result.error);\n}\n```\n\n### Retry with Backoff\n```typescript\n\u002F\u002F When: Transient failures are expected\nasync function retry\u003CT>(\n  fn: () => Promise\u003CT>,\n  attempts = 3,\n  delay = 1000\n): Promise\u003CT> {\n  for (let i = 0; i \u003C attempts; i++) {\n    try {\n      return await fn();\n    } catch (e) {\n      if (i === attempts - 1) throw e;\n      await new Promise(r => setTimeout(r, delay * Math.pow(2, i)));\n    }\n  }\n  throw new Error('Unreachable');\n}\n```\n\n## Async Patterns\n\n### Promise Queue\n```typescript\n\u002F\u002F When: Limiting concurrent async operations\nclass PromiseQueue {\n  private queue: (() => Promise\u003Cany>)[] = [];\n  private running = 0;\n\n  constructor(private concurrency: number) {}\n\n  add\u003CT>(fn: () => Promise\u003CT>): Promise\u003CT> {\n    return new Promise((resolve, reject) => {\n      this.queue.push(async () => {\n        try { resolve(await fn()); }\n        catch (e) { reject(e); }\n      });\n      this.process();\n    });\n  }\n\n  private async process() {\n    if (this.running >= this.concurrency || !this.queue.length) return;\n    this.running++;\n    await this.queue.shift()!();\n    this.running--;\n    this.process();\n  }\n}\n```\n\n### Debounce\n```typescript\n\u002F\u002F When: Limiting rapid-fire function calls\nfunction debounce\u003CT extends (...args: any[]) => any>(\n  fn: T,\n  delay: number\n): (...args: Parameters\u003CT>) => void {\n  let timeout: NodeJS.Timeout;\n  return (...args) => {\n    clearTimeout(timeout);\n    timeout = setTimeout(() => fn(...args), delay);\n  };\n}\n```\n\n## Data Patterns\n\n### Repository\n```typescript\n\u002F\u002F When: Abstracting data access\ninterface Repository\u003CT> {\n  findById(id: string): Promise\u003CT | null>;\n  findAll(): Promise\u003CT[]>;\n  save(entity: T): Promise\u003CT>;\n  delete(id: string): Promise\u003Cvoid>;\n}\n\nclass UserRepository implements Repository\u003CUser> {\n  constructor(private db: Database) {}\n\n  async findById(id: string) {\n    return this.db.query('SELECT * FROM users WHERE id = ?', [id]);\n  }\n  \u002F\u002F ... other methods\n}\n```\n\n### Unit of Work\n```typescript\n\u002F\u002F When: Coordinating writes across multiple repositories\nclass UnitOfWork {\n  private operations: (() => Promise\u003Cvoid>)[] = [];\n\n  register(operation: () => Promise\u003Cvoid>) {\n    this.operations.push(operation);\n  }\n\n  async commit() {\n    await this.db.beginTransaction();\n    try {\n      for (const op of this.operations) await op();\n      await this.db.commit();\n    } catch (e) {\n      await this.db.rollback();\n      throw e;\n    }\n  }\n}\n```\n\n## When to Use Each\n\n| Problem | Pattern |\n|---------|---------|\n| Complex object creation | Builder |\n| Multiple similar objects | Factory |\n| Global state (careful!) | Singleton |\n| Incompatible interfaces | Adapter |\n| Adding features dynamically | Decorator |\n| Swappable algorithms | Strategy |\n| Event-based communication | Observer |\n| Expected failures | Result Type |\n| Transient failures | Retry |\n| Rate limiting | Debounce\u002FThrottle |\n| Data access abstraction | Repository |\n| Transactional consistency | Unit of Work |\n",{"name":5,"description":7},"main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002Faiskillstore\u002Fmarketplace\u002Fbenny9193\u002Fcode-patterns",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":8,"skillName":5,"commands":41,"prompt":51,"zipAvailable":52},[42,45,48],{"tool":43,"command":44},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill code-patterns",{"tool":46,"command":47},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill code-patterns",{"tool":49,"command":50},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill code-patterns","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fbenny9193\u002Fcode-patterns\u002FSKILL.md",true,[54],{"path":55,"resourceType":56,"resourceTypeDesc":57,"sizeBytes":58,"sourceHtmlUrl":59},"skill-report.json","REFERENCE","参考文档",9203,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Fbenny9193\u002Fcode-patterns\u002Fskill-report.json",[61,70,79,88,94,100],{"skillNo":62,"name":63,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":26},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[],[67,68,69],"model","model hierarchy","model hierarchy skill",{"skillNo":71,"name":72,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":26},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[],[76,77,78],"MCP","zoom","zoom mcp",{"skillNo":80,"name":81,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":26},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[85,86,87,77],"sdk","zoom apps sdk","apps",{"skillNo":89,"name":90,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":91,"categories":92,"keywords":93,"publishedAt":26},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[90],{"skillNo":95,"name":96,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":97,"categories":98,"keywords":99,"publishedAt":26},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[],[96],{"skillNo":101,"name":102,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":103,"categories":104,"keywords":105,"publishedAt":26},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[102]]