[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M77VKMPNDVCA8G64VJ7MFEP9":3,"skill-same:01M77VKMPNDVCA8G64VJ7MFEP9":52},{"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":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":27,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":30,"ownerDescription":6,"updatedAt":31,"install":32,"resources":45},"01M77VKMPNDVCA8G64VJ7MFEP9","python-resource-management",null,"Python resource management with context managers, cleanup patterns, and streaming. Use when managing connections, file handles, implementing cleanup logic, or building streaming responses with accumulated state.","Reihantt6\u002Fsns-myagent","Reihantt6","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F219822095?v=4","01M77KK94PV8B7C2D9XWXNS8DJ","Mohamad Reihan tegar prasetya","01M77KK958QFMTHYXGXFV7KZ79",2,"MIT","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fpython-resource-management\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\ndescription: \"Python resource management with context managers, cleanup patterns, and streaming. Use when managing connections, file handles, implementing cleanup logic, or building streaming responses with accumulated state.\"\n---\n# Python Resource Management\n\nManage resources deterministically using context managers. Resources like database connections, file handles, and network sockets should be released reliably, even when exceptions occur.\n\n## When to Use This Skill\n\n- Managing database connections and connection pools\n- Working with file handles and I\u002FO\n- Implementing custom context managers\n- Building streaming responses with state\n- Handling nested resource cleanup\n- Creating async context managers\n\n## Core Concepts\n\n### 1. Context Managers\n\nThe `with` statement ensures resources are released automatically, even on exceptions.\n\n### 2. Protocol Methods\n\n`__enter__`\u002F`__exit__` for sync, `__aenter__`\u002F`__aexit__` for async resource management.\n\n### 3. Unconditional Cleanup\n\n`__exit__` always runs, regardless of whether an exception occurred.\n\n### 4. Exception Handling\n\nReturn `True` from `__exit__` to suppress exceptions, `False` to propagate them.\n\n## Quick Start\n\n```python\nfrom contextlib import contextmanager\n\n@contextmanager\ndef managed_resource():\n    resource = acquire_resource()\n    try:\n        yield resource\n    finally:\n        resource.cleanup()\n\nwith managed_resource() as r:\n    r.do_work()\n```\n\n## Fundamental Patterns\n\n### Pattern 1: Class-Based Context Manager\n\nImplement the context manager protocol for complex resources.\n\n```python\nclass DatabaseConnection:\n    \"\"\"Database connection with automatic cleanup.\"\"\"\n\n    def __init__(self, dsn: str) -> None:\n        self._dsn = dsn\n        self._conn: Connection | None = None\n\n    def connect(self) -> None:\n        \"\"\"Establish database connection.\"\"\"\n        self._conn = psycopg.connect(self._dsn)\n\n    def close(self) -> None:\n        \"\"\"Close connection if open.\"\"\"\n        if self._conn is not None:\n            self._conn.close()\n            self._conn = None\n\n    def __enter__(self) -> \"DatabaseConnection\":\n        \"\"\"Enter context: connect and return self.\"\"\"\n        self.connect()\n        return self\n\n    def __exit__(\n        self,\n        exc_type: type[BaseException] | None,\n        exc_val: BaseException | None,\n        exc_tb: TracebackType | None,\n    ) -> None:\n        \"\"\"Exit context: always close connection.\"\"\"\n        self.close()\n\n# Usage with context manager (preferred)\nwith DatabaseConnection(dsn) as db:\n    result = db.execute(query)\n\n# Manual management when needed\ndb = DatabaseConnection(dsn)\ndb.connect()\ntry:\n    result = db.execute(query)\nfinally:\n    db.close()\n```\n\n### Pattern 2: Async Context Manager\n\nFor async resources, implement the async protocol.\n\n```python\nclass AsyncDatabasePool:\n    \"\"\"Async database connection pool.\"\"\"\n\n    def __init__(self, dsn: str, min_size: int = 1, max_size: int = 10) -> None:\n        self._dsn = dsn\n        self._min_size = min_size\n        self._max_size = max_size\n        self._pool: asyncpg.Pool | None = None\n\n    async def __aenter__(self) -> \"AsyncDatabasePool\":\n        \"\"\"Create connection pool.\"\"\"\n        self._pool = await asyncpg.create_pool(\n            self._dsn,\n            min_size=self._min_size,\n            max_size=self._max_size,\n        )\n        return self\n\n    async def __aexit__(\n        self,\n        exc_type: type[BaseException] | None,\n        exc_val: BaseException | None,\n        exc_tb: TracebackType | None,\n    ) -> None:\n        \"\"\"Close all connections in pool.\"\"\"\n        if self._pool is not None:\n            await self._pool.close()\n\n    async def execute(self, query: str, *args) -> list[dict]:\n        \"\"\"Execute query using pooled connection.\"\"\"\n        async with self._pool.acquire() as conn:\n            return await conn.fetch(query, *args)\n\n# Usage\nasync with AsyncDatabasePool(dsn) as pool:\n    users = await pool.execute(\"SELECT * FROM users WHERE active = $1\", True)\n```\n\n### Pattern 3: Using @contextmanager Decorator\n\nSimplify context managers with the decorator for straightforward cases.\n\n```python\nfrom contextlib import contextmanager, asynccontextmanager\nimport time\nimport structlog\n\nlogger = structlog.get_logger()\n\n@contextmanager\ndef timed_block(name: str):\n    \"\"\"Time a block of code.\"\"\"\n    start = time.perf_counter()\n    try:\n        yield\n    finally:\n        elapsed = time.perf_counter() - start\n        logger.info(f\"{name} completed\", duration_seconds=round(elapsed, 3))\n\n# Usage\nwith timed_block(\"data_processing\"):\n    process_large_dataset()\n\n@asynccontextmanager\nasync def database_transaction(conn: AsyncConnection):\n    \"\"\"Manage database transaction.\"\"\"\n    await conn.execute(\"BEGIN\")\n    try:\n        yield conn\n        await conn.execute(\"COMMIT\")\n    except Exception:\n        await conn.execute(\"ROLLBACK\")\n        raise\n\n# Usage\nasync with database_transaction(conn) as tx:\n    await tx.execute(\"INSERT INTO users ...\")\n    await tx.execute(\"INSERT INTO audit_log ...\")\n```\n\n### Pattern 4: Unconditional Resource Release\n\nAlways clean up resources in `__exit__`, regardless of exceptions.\n\n```python\nclass FileProcessor:\n    \"\"\"Process file with guaranteed cleanup.\"\"\"\n\n    def __init__(self, path: str) -> None:\n        self._path = path\n        self._file: IO | None = None\n        self._temp_files: list[Path] = []\n\n    def __enter__(self) -> \"FileProcessor\":\n        self._file = open(self._path, \"r\")\n        return self\n\n    def __exit__(\n        self,\n        exc_type: type[BaseException] | None,\n        exc_val: BaseException | None,\n        exc_tb: TracebackType | None,\n    ) -> None:\n        \"\"\"Clean up all resources unconditionally.\"\"\"\n        # Close main file\n        if self._file is not None:\n            self._file.close()\n\n        # Clean up any temporary files\n        for temp_file in self._temp_files:\n            try:\n                temp_file.unlink()\n            except OSError:\n                pass  # Best effort cleanup\n\n        # Return None\u002FFalse to propagate any exception\n```\n\n## Detailed worked examples and patterns\n\nDetailed sections (starting with `## Advanced Patterns`) live in `references\u002Fdetails.md`. Read that file when the navigation summary above is insufficient.\n\n## Best Practices Summary\n\n1. **Always use context managers** - For any resource that needs cleanup\n2. **Clean up unconditionally** - `__exit__` runs even on exception\n3. **Don't suppress unexpectedly** - Return `False` unless suppression is intentional\n4. **Use @contextmanager** - For simple resource patterns\n5. **Implement both protocols** - Support `with` and manual management\n6. **Use ExitStack** - For dynamic numbers of resources\n7. **Accumulate efficiently** - List + join, not string concatenation\n8. **Track metrics** - Time-to-first-byte matters for streaming\n9. **Document behavior** - Especially exception suppression\n10. **Test cleanup paths** - Verify resources are released on errors\n","# Python Resource Management\n\nManage resources deterministically using context managers. Resources like database connections, file handles, and network sockets should be released reliably, even when exceptions occur.\n\n## When to Use This Skill\n\n- Managing database connections and connection pools\n- Working with file handles and I\u002FO\n- Implementing custom context managers\n- Building streaming responses with state\n- Handling nested resource cleanup\n- Creating async context managers\n\n## Core Concepts\n\n### 1. Context Managers\n\nThe `with` statement ensures resources are released automatically, even on exceptions.\n\n### 2. Protocol Methods\n\n`__enter__`\u002F`__exit__` for sync, `__aenter__`\u002F`__aexit__` for async resource management.\n\n### 3. Unconditional Cleanup\n\n`__exit__` always runs, regardless of whether an exception occurred.\n\n### 4. Exception Handling\n\nReturn `True` from `__exit__` to suppress exceptions, `False` to propagate them.\n\n## Quick Start\n\n```python\nfrom contextlib import contextmanager\n\n@contextmanager\ndef managed_resource():\n    resource = acquire_resource()\n    try:\n        yield resource\n    finally:\n        resource.cleanup()\n\nwith managed_resource() as r:\n    r.do_work()\n```\n\n## Fundamental Patterns\n\n### Pattern 1: Class-Based Context Manager\n\nImplement the context manager protocol for complex resources.\n\n```python\nclass DatabaseConnection:\n    \"\"\"Database connection with automatic cleanup.\"\"\"\n\n    def __init__(self, dsn: str) -> None:\n        self._dsn = dsn\n        self._conn: Connection | None = None\n\n    def connect(self) -> None:\n        \"\"\"Establish database connection.\"\"\"\n        self._conn = psycopg.connect(self._dsn)\n\n    def close(self) -> None:\n        \"\"\"Close connection if open.\"\"\"\n        if self._conn is not None:\n            self._conn.close()\n            self._conn = None\n\n    def __enter__(self) -> \"DatabaseConnection\":\n        \"\"\"Enter context: connect and return self.\"\"\"\n        self.connect()\n        return self\n\n    def __exit__(\n        self,\n        exc_type: type[BaseException] | None,\n        exc_val: BaseException | None,\n        exc_tb: TracebackType | None,\n    ) -> None:\n        \"\"\"Exit context: always close connection.\"\"\"\n        self.close()\n\n# Usage with context manager (preferred)\nwith DatabaseConnection(dsn) as db:\n    result = db.execute(query)\n\n# Manual management when needed\ndb = DatabaseConnection(dsn)\ndb.connect()\ntry:\n    result = db.execute(query)\nfinally:\n    db.close()\n```\n\n### Pattern 2: Async Context Manager\n\nFor async resources, implement the async protocol.\n\n```python\nclass AsyncDatabasePool:\n    \"\"\"Async database connection pool.\"\"\"\n\n    def __init__(self, dsn: str, min_size: int = 1, max_size: int = 10) -> None:\n        self._dsn = dsn\n        self._min_size = min_size\n        self._max_size = max_size\n        self._pool: asyncpg.Pool | None = None\n\n    async def __aenter__(self) -> \"AsyncDatabasePool\":\n        \"\"\"Create connection pool.\"\"\"\n        self._pool = await asyncpg.create_pool(\n            self._dsn,\n            min_size=self._min_size,\n            max_size=self._max_size,\n        )\n        return self\n\n    async def __aexit__(\n        self,\n        exc_type: type[BaseException] | None,\n        exc_val: BaseException | None,\n        exc_tb: TracebackType | None,\n    ) -> None:\n        \"\"\"Close all connections in pool.\"\"\"\n        if self._pool is not None:\n            await self._pool.close()\n\n    async def execute(self, query: str, *args) -> list[dict]:\n        \"\"\"Execute query using pooled connection.\"\"\"\n        async with self._pool.acquire() as conn:\n            return await conn.fetch(query, *args)\n\n# Usage\nasync with AsyncDatabasePool(dsn) as pool:\n    users = await pool.execute(\"SELECT * FROM users WHERE active = $1\", True)\n```\n\n### Pattern 3: Using @contextmanager Decorator\n\nSimplify context managers with the decorator for straightforward cases.\n\n```python\nfrom contextlib import contextmanager, asynccontextmanager\nimport time\nimport structlog\n\nlogger = structlog.get_logger()\n\n@contextmanager\ndef timed_block(name: str):\n    \"\"\"Time a block of code.\"\"\"\n    start = time.perf_counter()\n    try:\n        yield\n    finally:\n        elapsed = time.perf_counter() - start\n        logger.info(f\"{name} completed\", duration_seconds=round(elapsed, 3))\n\n# Usage\nwith timed_block(\"data_processing\"):\n    process_large_dataset()\n\n@asynccontextmanager\nasync def database_transaction(conn: AsyncConnection):\n    \"\"\"Manage database transaction.\"\"\"\n    await conn.execute(\"BEGIN\")\n    try:\n        yield conn\n        await conn.execute(\"COMMIT\")\n    except Exception:\n        await conn.execute(\"ROLLBACK\")\n        raise\n\n# Usage\nasync with database_transaction(conn) as tx:\n    await tx.execute(\"INSERT INTO users ...\")\n    await tx.execute(\"INSERT INTO audit_log ...\")\n```\n\n### Pattern 4: Unconditional Resource Release\n\nAlways clean up resources in `__exit__`, regardless of exceptions.\n\n```python\nclass FileProcessor:\n    \"\"\"Process file with guaranteed cleanup.\"\"\"\n\n    def __init__(self, path: str) -> None:\n        self._path = path\n        self._file: IO | None = None\n        self._temp_files: list[Path] = []\n\n    def __enter__(self) -> \"FileProcessor\":\n        self._file = open(self._path, \"r\")\n        return self\n\n    def __exit__(\n        self,\n        exc_type: type[BaseException] | None,\n        exc_val: BaseException | None,\n        exc_tb: TracebackType | None,\n    ) -> None:\n        \"\"\"Clean up all resources unconditionally.\"\"\"\n        # Close main file\n        if self._file is not None:\n            self._file.close()\n\n        # Clean up any temporary files\n        for temp_file in self._temp_files:\n            try:\n                temp_file.unlink()\n            except OSError:\n                pass  # Best effort cleanup\n\n        # Return None\u002FFalse to propagate any exception\n```\n\n## Detailed worked examples and patterns\n\nDetailed sections (starting with `## Advanced Patterns`) live in `references\u002Fdetails.md`. Read that file when the navigation summary above is insufficient.\n\n## Best Practices Summary\n\n1. **Always use context managers** - For any resource that needs cleanup\n2. **Clean up unconditionally** - `__exit__` runs even on exception\n3. **Don't suppress unexpectedly** - Return `False` unless suppression is intentional\n4. **Use @contextmanager** - For simple resource patterns\n5. **Implement both protocols** - Support `with` and manual management\n6. **Use ExitStack** - For dynamic numbers of resources\n7. **Accumulate efficiently** - List + join, not string concatenation\n8. **Track metrics** - Time-to-first-byte matters for streaming\n9. **Document behavior** - Especially exception suppression\n10. **Test cleanup paths** - Verify resources are released on errors\n",{"description":7},"main","58843b159d7a4050d6b785a98b908cce505c0b92","agent\u002Fskills\u002Fpython-resource-management",0,"https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent","https:\u002F\u002Fgithub.com\u002FReihantt6","reihsns.web.id","2026-08-19 20:08:18",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add Reihantt6\u002Fsns-myagent --skill python-resource-management",{"tool":38,"command":39},"bunx","bunx skills add Reihantt6\u002Fsns-myagent --skill python-resource-management",{"tool":41,"command":42},"pnpm","pnpm dlx skills add Reihantt6\u002Fsns-myagent --skill python-resource-management","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fpython-resource-management\u002FSKILL.md",true,[46],{"path":47,"resourceType":48,"resourceTypeDesc":49,"sizeBytes":50,"sourceHtmlUrl":51},"references\u002Fdetails.md","REFERENCE","参考文档",4721,"https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fpython-resource-management\u002Freferences\u002Fdetails.md",[53,60,67,74,81,88],{"skillNo":54,"name":55,"nameZh":6,"description":56,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":57,"categories":58,"keywords":59,"publishedAt":19},"01M77XDCYZ407XYMF2T4P6F7VT","youtube-transcript","Extract transcripts from YouTube videos. Use when the user asks for a transcript, subtitles, or captions of a YouTube video and provides a YouTube URL (youtube.com\u002Fwatch?v=, youtu.be\u002F, or similar). Supports output with or without timestamps.","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fyoutube-transcript\u002FSKILL.md",[],[],{"skillNo":61,"name":62,"nameZh":6,"description":63,"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":19},"01M77XD7PBC98J6MXGJJ2TJ8DX","youtube-thumbnail-design","YouTube thumbnail design with specific dimensions, contrast rules, and mobile preview optimization. Covers safe zones, text placement, face expression psychology, and A\u002FB testing. Use for: YouTube thumbnails, video cover images, click-through optimization. Triggers: youtube thumbnail, thumbnail design, video thumbnail, click through rate, ctr optimization, youtube cover, video cover image, thumbnail maker, thumbnail tips, youtube design, video preview image","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fyoutube-thumbnail-design\u002FSKILL.md",[],[],{"skillNo":68,"name":69,"nameZh":6,"description":70,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":19},"01M77XD2541C8HXJ6RHYZP4NGJ","youtube-short-maker","Make YouTube Shorts that hold attention with Pexo — vertical 9:16, fast-paced, hook in the first 3 seconds. Describe your topic and Pexo writes the script, generates the shots, picks the models, and assembles a finished Short with music and captions. Use for YouTube Shorts: \"youtube short\", \"make a youtube short\", \"shorts video\", \"short-form video\". NOT for long-form or landscape video.","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fyoutube-short-maker\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":19},"01M77XCXKVSYK7KTZ3PQBVVGFD","xcode-project-setup","Safely modifies Xcode projects (.pbxproj) to add Swift Packages and link files. Use this skill whenever an iOS project needs dependencies installed (e.g. Firebase, Alamofire).","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fxcode-project-setup\u002FSKILL.md",[],[],{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":19},"01M77XCR1DV8ZQK2NHWKVY4EWX","x402","Set up Browser Use Cloud payments with x402 — pay per request from a crypto wallet (USDC on Base mainnet), no signup or API key. Two setups it works out up front — \"just use it\" (set up a wallet so you or Claude Code can run cloud browser tasks paid from the wallet — Claude writes and runs throwaway scripts, nothing touches your codebase) or \"build it in\" (install the SDK and write the key + code into your project). Walks through wallet setup, funding, .env, and a ~$1 test run. Use when the user asks about x402, pay-per-use, USDC payments, or wants Browser Use Cloud without an API key. For the free-tier signup (reverse-CAPTCHA → API key), use `browser-use cloud signup` or the `cloud` skill instead.","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fx402\u002FSKILL.md",[],[],{"skillNo":89,"name":90,"nameZh":6,"description":91,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":19},"01M77XCMD3R3ZBZQQSW6E0793B","x-twitter-scraper","Build GitHub Copilot workflows with Xquik X API SDKs, REST endpoints, hosted Apify Actor runs, MCP tools, TweetClaw OpenClaw plugin installs, signed webhooks, tweet search, user lookup, follower exports, media actions, and agent automation.","https:\u002F\u002Fgithub.com\u002FReihantt6\u002Fsns-myagent\u002Fblob\u002Fmain\u002Fagent\u002Fskills\u002Fx-twitter-scraper\u002FSKILL.md",[],[]]