[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"snippets-all":3},{"snippets":4,"tags":196},[5,27,45,63,82,100,118,138,156,174],{"title":6,"slug":7,"code":8,"excerpt":9,"language":10,"description":11,"tags":24,"createdAt":25,"updatedAt":25,"codePreview":26},"TypeScript - Generic Class with Constraints","typescript-generic-class","interface Repository\u003CT extends { id: string }> {\n  find(id: string): Promise\u003CT | null>\n  findAll(): Promise\u003CT[]>\n  create(data: Omit\u003CT, 'id'>): Promise\u003CT>\n  update(id: string, data: Partial\u003CT>): Promise\u003CT>\n  delete(id: string): Promise\u003Cvoid>\n}\n\nclass InMemoryRepository\u003CT extends { id: string }> implements Repository\u003CT> {\n  private items = new Map\u003Cstring, T>()\n\n  async find(id: string): Promise\u003CT | null> {\n    return this.items.get(id) ?? null\n  }\n\n  async findAll(): Promise\u003CT[]> {\n    return Array.from(this.items.values())\n  }\n\n  async create(data: Omit\u003CT, 'id'>): Promise\u003CT> {\n    const id = crypto.randomUUID()\n    const item = { ...data, id } as T\n    this.items.set(id, item)\n    return item\n  }\n\n  async update(id: string, data: Partial\u003CT>): Promise\u003CT> {\n    const existing = await this.find(id)\n    if (!existing) throw new Error('Not found')\n    const updated = { ...existing, ...data }\n    this.items.set(id, updated)\n    return updated\n  }\n\n  async delete(id: string): Promise\u003Cvoid> {\n    this.items.delete(id)\n  }\n}","Generic repository pattern with type constraints and inference","typescript",{"nodeType":12,"data":13,"content":14},"document",{},[15],{"nodeType":16,"data":17,"content":18},"paragraph",{},[19],{"nodeType":20,"value":21,"marks":22,"data":23},"text","Build type-safe generic classes with constraints and inference",[],{},[10],"2026-02-01T00:58:03.681Z","interface Repository\u003CT extends { id: string }> {\n  find(id: string): Promise\u003CT | null>\n  findAll(): Promise\u003CT[]>\n  create(data: Omit\u003CT, 'id'>): Promis",{"title":28,"slug":29,"code":30,"excerpt":31,"language":10,"description":32,"tags":42,"createdAt":43,"updatedAt":43,"codePreview":44},"TypeScript - Utility Type Helpers","typescript-utility-types","// Make all properties optional recursively\ntype DeepPartial\u003CT> = {\n  [P in keyof T]?: T[P] extends object ? DeepPartial\u003CT[P]> : T[P]\n}\n\n// Make specific keys required\ntype RequireKeys\u003CT, K extends keyof T> = T & Required\u003CPick\u003CT, K>>\n\n// Exclude null and undefined\ntype NonNullableFields\u003CT> = {\n  [P in keyof T]: NonNullable\u003CT[P]>\n}\n\n// Create union from object values\ntype ValueOf\u003CT> = T[keyof T]\n\n// Example usage\ninterface User {\n  id: string\n  name?: string\n  email?: string\n  settings?: {\n    theme?: string\n    notifications?: boolean\n  }\n}\n\ntype PartialUser = DeepPartial\u003CUser>\ntype UserWithEmail = RequireKeys\u003CUser, 'email'>\ntype NonNullableUser = NonNullableFields\u003CUser>\n\n// Extract function return type\ntype AsyncReturnType\u003CT extends (...args: any) => Promise\u003Cany>> =\n  T extends (...args: any) => Promise\u003Cinfer R> ? R : never","Advanced utility types for flexible type transformations",{"nodeType":12,"data":33,"content":34},{},[35],{"nodeType":16,"data":36,"content":37},{},[38],{"nodeType":20,"value":39,"marks":40,"data":41},"Powerful utility types for transforming and manipulating types",[],{},[10],"2026-02-01T00:58:02.437Z","// Make all properties optional recursively\ntype DeepPartial\u003CT> = {\n  [P in keyof T]?: T[P] extends object ? DeepPartial\u003CT[P]> : T[P]\n}\n\n// Make speci",{"title":46,"slug":47,"code":48,"excerpt":49,"language":10,"description":50,"tags":60,"createdAt":61,"updatedAt":61,"codePreview":62},"TypeScript - Advanced Type Guards","typescript-type-guards","// Type predicates for runtime checks\nfunction isString(value: unknown): value is string {\n  return typeof value === 'string'\n}\n\nfunction isUser(obj: unknown): obj is User {\n  return (\n    typeof obj === 'object' &&\n    obj !== null &&\n    'id' in obj &&\n    'email' in obj &&\n    typeof obj.email === 'string'\n  )\n}\n\n// Discriminated union guard\ntype Shape =\n  | { kind: 'circle'; radius: number }\n  | { kind: 'square'; size: number }\n  | { kind: 'rectangle'; width: number; height: number }\n\nfunction getArea(shape: Shape): number {\n  switch (shape.kind) {\n    case 'circle':\n      return Math.PI * shape.radius ** 2\n    case 'square':\n      return shape.size ** 2\n    case 'rectangle':\n      return shape.width * shape.height\n  }\n}\n\n// Array type guard\nfunction isStringArray(arr: unknown): arr is string[] {\n  return Array.isArray(arr) && arr.every(item => typeof item === 'string')\n}","Type predicates and guards for runtime type safety",{"nodeType":12,"data":51,"content":52},{},[53],{"nodeType":16,"data":54,"content":55},{},[56],{"nodeType":20,"value":57,"marks":58,"data":59},"Create type-safe guards for runtime type checking with TypeScript",[],{},[10],"2026-02-01T00:58:01.136Z","// Type predicates for runtime checks\nfunction isString(value: unknown): value is string {\n  return typeof value === 'string'\n}\n\nfunction isUser(obj: ",{"title":64,"slug":65,"code":66,"excerpt":67,"language":10,"description":68,"tags":78,"createdAt":80,"updatedAt":80,"codePreview":81},"Nuxt 4 - Plugin with Auto-imports","nuxt-plugin","// plugins/api.ts\nexport default defineNuxtPlugin(() => {\n  const config = useRuntimeConfig()\n\n  const api = $fetch.create({\n    baseURL: config.public.apiBase,\n    onRequest({ request, options }) {\n      // Add auth header\n      const token = useCookie('auth-token')\n      if (token.value) {\n        options.headers = {\n          ...options.headers,\n          Authorization: `Bearer ${token.value}`,\n        }\n      }\n    },\n    onResponseError({ response }) {\n      // Handle errors globally\n      if (response.status === 401) {\n        navigateTo('/login')\n      }\n    },\n  })\n\n  return {\n    provide: {\n      api,\n    },\n  }\n})\n\n// Usage in components:\n// const { $api } = useNuxtApp()\n// const data = await $api('/users')","Global API client plugin with authentication and error handling",{"nodeType":12,"data":69,"content":70},{},[71],{"nodeType":16,"data":72,"content":73},{},[74],{"nodeType":20,"value":75,"marks":76,"data":77},"Create a Nuxt plugin that provides global utilities and composables",[],{},[79,10],"vue","2026-02-01T00:57:59.822Z","// plugins/api.ts\nexport default defineNuxtPlugin(() => {\n  const config = useRuntimeConfig()\n\n  const api = $fetch.create({\n    baseURL: config.publi",{"title":83,"slug":84,"code":85,"excerpt":86,"language":10,"description":87,"tags":97,"createdAt":98,"updatedAt":98,"codePreview":99},"Nuxt 4 - Server API Route with Validation","nuxt-server-route","// server/api/users/[id].post.ts\nimport { z } from 'zod'\n\nconst updateUserSchema = z.object({\n  name: z.string().min(2).max(100),\n  email: z.string().email(),\n  role: z.enum(['admin', 'user', 'guest']).optional(),\n})\n\nexport default defineEventHandler(async (event) => {\n  const id = getRouterParam(event, 'id')\n\n  // Validate request body\n  const body = await readBody(event)\n  const validatedData = updateUserSchema.parse(body)\n\n  // Check authentication\n  const session = await requireUserSession(event)\n  if (session.user.id !== id && !session.user.isAdmin) {\n    throw createError({\n      statusCode: 403,\n      message: 'Unauthorized',\n    })\n  }\n\n  // Update user\n  const user = await prisma.user.update({\n    where: { id },\n    data: validatedData,\n  })\n\n  return user\n})","Complete server route with validation, auth, and error handling",{"nodeType":12,"data":88,"content":89},{},[90],{"nodeType":16,"data":91,"content":92},{},[93],{"nodeType":20,"value":94,"marks":95,"data":96},"Type-safe server API route with request validation and error handling",[],{},[79,10],"2026-02-01T00:57:58.669Z","// server/api/users/[id].post.ts\nimport { z } from 'zod'\n\nconst updateUserSchema = z.object({\n  name: z.string().min(2).max(100),\n  email: z.string().",{"title":101,"slug":102,"code":103,"excerpt":104,"language":10,"description":105,"tags":115,"createdAt":116,"updatedAt":116,"codePreview":117},"Nuxt 4 - Auto-imported Composable","nuxt-composable","// composables/useUser.ts\nexport const useUser = () => {\n  const user = useState\u003CUser | null>('user', () => null)\n  const loading = ref(false)\n  const error = ref\u003CError | null>(null)\n\n  const fetchUser = async (id: string) => {\n    loading.value = true\n    error.value = null\n\n    try {\n      const data = await $fetch\u003CUser>(`/api/users/${id}`)\n      user.value = data\n    } catch (e) {\n      error.value = e as Error\n    } finally {\n      loading.value = false\n    }\n  }\n\n  const logout = () => {\n    user.value = null\n  }\n\n  return {\n    user: readonly(user),\n    loading: readonly(loading),\n    error: readonly(error),\n    fetchUser,\n    logout,\n  }\n}","Reusable composable pattern with state management and error handling",{"nodeType":12,"data":106,"content":107},{},[108],{"nodeType":16,"data":109,"content":110},{},[111],{"nodeType":20,"value":112,"marks":113,"data":114},"Create a reusable composable with state management and async data fetching",[],{},[79,10],"2026-02-01T00:57:57.123Z","// composables/useUser.ts\nexport const useUser = () => {\n  const user = useState\u003CUser | null>('user', () => null)\n  const loading = ref(false)\n  const",{"title":119,"slug":120,"code":121,"excerpt":122,"language":123,"description":124,"tags":134,"createdAt":136,"updatedAt":136,"codePreview":137},"Laravel 12 - Database Transactions with Retry","laravel-database-transactions","\u003C?php\n\nuse Illuminate\\Support\\Facades\\DB;\n\n// Simple transaction\nDB::transaction(function () {\n    DB::table('users')->update(['votes' => 1]);\n    DB::table('posts')->delete();\n});\n\n// Transaction with manual control\nDB::beginTransaction();\ntry {\n    $user = User::create($data);\n    $user->profile()->create($profileData);\n    DB::commit();\n} catch (\\Exception $e) {\n    DB::rollBack();\n    throw $e;\n}\n\n// Transaction with automatic retry on deadlock (Laravel 12)\nDB::transaction(function () {\n    // Your database operations\n}, attempts: 5);","Handle database transactions safely with automatic rollback and retry logic","php",{"nodeType":12,"data":125,"content":126},{},[127],{"nodeType":16,"data":128,"content":129},{},[130],{"nodeType":20,"value":131,"marks":132,"data":133},"Safe database transactions with automatic retry on deadlock",[],{},[135,123],"laravel","2026-02-01T00:57:55.626Z","\u003C?php\n\nuse Illuminate\\Support\\Facades\\DB;\n\n// Simple transaction\nDB::transaction(function () {\n    DB::table('users')->update(['votes' => 1]);\n    DB:",{"title":139,"slug":140,"code":141,"excerpt":142,"language":123,"description":143,"tags":153,"createdAt":154,"updatedAt":154,"codePreview":155},"Laravel 12 - Service Container Contextual Binding","laravel-contextual-binding","\u003C?php\n\n// In app/Providers/AppServiceProvider.php\npublic function register(): void\n{\n    // Contextual binding - different implementations for different classes\n    $this->app->when(PhotoController::class)\n        ->needs(StorageInterface::class)\n        ->give(S3Storage::class);\n\n    $this->app->when(VideoController::class)\n        ->needs(StorageInterface::class)\n        ->give(LocalStorage::class);\n\n    // Tagged bindings for multiple implementations\n    $this->app->tag([S3Storage::class, LocalStorage::class], 'storage');\n\n    // Resolve all tagged services\n    $storageServices = $this->app->tagged('storage');\n}","Context-aware dependency injection for flexible service resolution",{"nodeType":12,"data":144,"content":145},{},[146],{"nodeType":16,"data":147,"content":148},{},[149],{"nodeType":20,"value":150,"marks":151,"data":152},"Bind different implementations of an interface based on the class that needs it",[],{},[135,123],"2026-02-01T00:57:54.479Z","\u003C?php\n\n// In app/Providers/AppServiceProvider.php\npublic function register(): void\n{\n    // Contextual binding - different implementations for differe",{"title":157,"slug":158,"code":159,"excerpt":160,"language":123,"description":161,"tags":171,"createdAt":172,"updatedAt":172,"codePreview":173},"Laravel 12 - Route Model Binding with Scoping","laravel-route-model-binding","\u003C?php\n\n// In routes/web.php\nRoute::get('/users/{user}/posts/{post}', function (User $user, Post $post) {\n    return $post;\n})->scopeBindings(); // Laravel 12 automatically scopes $post to $user\n\n// Alternative: Implicit scoping in route definition\nRoute::get('/users/{user}/posts/{post:slug}', [PostController::class, 'show'])\n    ->scopeBindings();\n\n// In your Post model\npublic function user(): BelongsTo\n{\n    return $this->belongsTo(User::class);\n}","Automatic model injection with scoped bindings for clean route handlers",{"nodeType":12,"data":162,"content":163},{},[164],{"nodeType":16,"data":165,"content":166},{},[167],{"nodeType":20,"value":168,"marks":169,"data":170},"Automatically inject model instances into routes with scoped bindings for multi-tenant applications",[],{},[135,123],"2026-02-01T00:57:52.800Z","\u003C?php\n\n// In routes/web.php\nRoute::get('/users/{user}/posts/{post}', function (User $user, Post $post) {\n    return $post;\n})->scopeBindings(); // Lar",{"title":175,"slug":176,"code":177,"tag":178,"excerpt":181,"language":123,"description":182,"tags":192,"createdAt":193,"updatedAt":194,"codePreview":195},"Rate Limiting","rate-limiting","// In a controller method\n\nuse Illuminate\\Support\\Facades\\RateLimiter;\nuse Illuminate\\Http\\Request;\nuse Illuminate\\Support\\Str;\n\npublic function handle(Request $request)\n{\n    $key = Str::lower($request->ip()) . '|' . $request->path();\n\n    if (RateLimiter::tooManyAttempts($key, 5)) {\n        return response()->json([\n            'message' => 'Too many requests. Try again later.',\n        ], 429);\n    }\n\n    RateLimiter::hit($key, 60); // 5 attempts per 60 seconds\n\n    // Proceed with logic\n    return response()->json([\n        'message' => 'Request successful!',\n    ]);\n}\n",[179,180],"PHP","Laravel","Rate limiting middleware",{"data":183,"content":184,"nodeType":12},{},[185],{"data":186,"content":187,"nodeType":16},{},[188],{"data":189,"marks":190,"value":191,"nodeType":20},{},[],"This is an example of how you can setup rate limiting in Laravel",[123,135],"2025-05-24T13:59:24.968Z","2026-02-01T00:46:52.397Z","// In a controller method\n\nuse Illuminate\\Support\\Facades\\RateLimiter;\nuse Illuminate\\Http\\Request;\nuse Illuminate\\Support\\Str;\n\npublic function handl",[197,200,203,206,209,212,215,216,219,222,225,226,229,232,234],{"name":198,"slug":199},"AI","ai",{"name":201,"slug":202},"Architecture","architecture",{"name":204,"slug":205},"AWS","aws",{"name":207,"slug":208},"Best Practices","best-practices",{"name":210,"slug":211},"Cypress","cypress",{"name":213,"slug":214},"DevOps","devops",{"name":180,"slug":135},{"name":217,"slug":218},"Nuxt","nuxt",{"name":220,"slug":221},"Opinion","opinion",{"name":223,"slug":224},"Personal","personal",{"name":179,"slug":123},{"name":227,"slug":228},"Testing","testing",{"name":230,"slug":231},"Tutorial","tutorial",{"name":233,"slug":10},"TypeScript",{"name":235,"slug":79},"Vue"]