Ctrl + Alt + Space
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ######## | |
| # app.py | |
| ######## | |
| # Example of how I use it in my project. This file cannot be run as-is. | |
| # The only difference with the example in the fastapi_singleton module docstring is | |
| # the use of a subclassed FastAPI application to define type annotations | |
| import fastapi | |
| import fastapi_singleton |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import List | |
| import aiohttp | |
| async def send_request(client_session: aiohttp.ClientSession, url: str, rate_limiter: RateLimiter): | |
| async with rate_limiter.throttle(): | |
| print(f'sending url: {url}') | |
| response = await client_session.get(url) | |
| print(f'releasing throttler') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import inspect | |
| import sys | |
| from datetime import datetime | |
| from enum import EnumMeta | |
| from typing import Any, Dict, List, Tuple, Union, _GenericAlias, get_type_hints | |
| from pydantic import BaseModel | |
| # Import your pydnatic models here | |
| models = inspect.getmembers( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // helps us in parsing the frontmatter from text content | |
| const matter = require('gray-matter') | |
| // helps us safely stringigy the frontmatter as a json object | |
| const stringifyObject = require('stringify-object') | |
| // helps us in getting the reading time for a given text | |
| const readingTime = require('reading-time') | |
| // please make sure you have installed these dependencies | |
| // before proceeding further, or remove the require statements | |
| // that you don't use |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "Detour.h" | |
| BYTE Detour::TrampolineBuffer[ 200 * 20 ] = {}; | |
| SIZE_T Detour::TrampolineSize = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| build: | |
| pandoc writing.md --standalone \ | |
| --bibliography writing.bib --csl writing.csl \ | |
| -c https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/2.10.0/github-markdown.css \ | |
| -t html \ | |
| | sed '/<body>/c\<body class="markdown-body">' \ | |
| | weasyprint - output.pdf |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| This gist shows how to run asyncio loop in a separate thread. | |
| It could be useful if you want to mix sync and async code together. | |
| Python 3.7+ | |
| """ | |
| import asyncio | |
| from datetime import datetime | |
| from threading import Thread | |
| from typing import Tuple, List, Iterable |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """Creating thread safe and managed sessions using SQLAlchemy. | |
| The sessions that are created are expected to be: | |
| - thread safe | |
| - handle committing | |
| - handle rolling back on errors | |
| - handle session removal/releasing once context or thread is closed. | |
| Author: Nitish Reddy Koripalli | |
| License: MIT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import asyncio | |
| from functools import wraps | |
| def dec(fn): | |
| @wraps(fn) | |
| async def wrapper(*args, **kwargs): | |
| print(fn, args, kwargs) # <function foo at 0x10952d598> () {} | |
| await asyncio.sleep(5) |