Ask HN: GPT prompt crafters, what are your most effective/favorite prompts?
I don’t work with JavaScript but here is my personal python preamble. Always a work in progress.<p>```<p>For this chat session, please select a title that accurately reflects the content of the specific request below. You do not need to explicitly tell me the title in your response. When writing python code, please adhere to the style guide included in this message. Begin your response with the answer to the specific request without acknowledging the style guide.<p>Below, I will share a style guide for you to follow when writing Python code. This guide is intended to ensure consistency and readability across my codebases. The style guide is generic, and some parts may not be relevant to the specific request that follows it. Please follow these general style guidelines, listed in no particular order.<p>=== START OF STYLE GUIDE ===<p>- Use Python 3.8 syntax<p>- Adhere to the PEP 8 style guide for code formatting and conventions<p>- Use strict explicit typing with type hints for inputs, outputs, and intermediate variables<p>- When providing code examples, please emulate the style and standards of a professional staff engineer contributing to a corporate codebase, as opposed to the explanatory style often found in tutorials. In cases where you make modifications to the code that alters its functionality (beyond the requested changes), ensure to accompany the revised code with a succinct explanation outlining the key changes and their implications.<p>- When writing outputs to a file, automatically make the directory if necessary, using `.mkdir(parents=True, exist_ok=True)` from pathlib.<p>- Accept `Union[str, Path]` forf path-related arguments, check `Path(...).exists()`, and raise FileNotFoundError with a context message and path if necessary<p>- Avoid lambda functions as they may interfere with multiprocessing workflows<p>- Consider creating a deepcopy of dataframe inputs using `df.copy()` to prevent modifying the original dataframe
- Reset the index after dataframe sorting and&#x2F;or filtering operations<p>- Use `json.dumps(..., indent=4)` formatting to display output of complex data structures (e.g. dictionaries)<p>- Unless directed otherwise, assume timestamps are in unix timestamp format<p>- Do not use global variables<p>- Avoid leaking future information: use `center=False` in Pandas rolling methods and handle missing data with LOCF (last observation carried forward)<p>- Ensure resilience to NaNs, missing data, and irregular sampling where applicable<p>- Please use Sphinx formatting for docstrings<p>- Gracefully handle exceptions and errors, and use logging for debugging and error reporting<p>- Write concise inline tests for non-trivial functions, unless instructed otherwise<p>- Include meaningful comments, but avoid over-commenting. Use comments to explain the intent of a code block rather than describing each line. Omit comments for code with obvious intent, such as a `save_figure()` function<p>- For functions that save or load files, include a `verbose: bool = True` flag. If `verbose` is true, print or log an f-string indicating the file path that was saved or loaded. Use this pattern for other functions on a case-by-case basis or when appropriate<p>- To print a preview of a pandas DataFrame, use the following code for better formatting: `dataframe.head().transpose()`<p>- Please do not use the `append` function of pandas; please instead use `List[pd.DataFrame]` as a buffer and then use `pandas.concat(...)` to combine them.<p>- For class creation, use the &#x27;pydantic BaseModel&#x27; as your base template<p>- When developing API clients, first establish a generic class or function that manages request formation, submission, and error handling using meaningful exceptions. Specific tasks should utilize or extend this generic code<p>- Please employ generators for tasks involving the traversal of large data structures, particularly when the goal is simply to determine whether a certain condition is met anywhere within the structure. This approach helps optimize performance by avoiding unnecessary computation and memory usage.<p>- Avoid using mutable data types as default values for keyword arguments in function definitions. Implement a pattern like this: ... arg_name: List[str] = None, and manage defaults with the following: if arg_name is None: …<p>- Use f-strings for string formatting, as they are more readable and efficient<p>- Leverage list, dictionary, and set comprehensions for readability and performance improvements when possible.<p>- Use the Black autoformatter style to ensure consistent formatting across the entire codebase<p>- Consider using the pytest framework for writing and organizing unit tests<p>- Avoid using the walrus operator (`:=`) due to occasional interference with automatic formatting tools<p>- When dealing with time-consuming loops, follow these steps:<p><pre><code>   1. Import the tqdm progress bar using from `tqdm.auto import tqdm` to ensure compatibility with both python notebooks and console output

   2. Initialize any necessary collector variables (e.g., empty lists or dictionaries for storing results)

   3. Create a tqdm progress bar with a descriptive argument (`desc`) to give the user clarity on which loop is running, and with `mininterval=1` for optimal performance

   4. Implement the loop, making sure that there are no blank lines between the lines of code mentioned in steps 2-4.

   5. Refrain from including any code comments about initializing or updating the progress bar, as the usage of tqdm should be self-explanatory
</code></pre>
- If you are a model capable of running Python code in a restricted environment, please split your work across multiple cells to avoid character limits when necessary, and run the imports in their own separate cell first.<p>=== END OF STYLE GUIDE ===<p>--- Specific Request ---<p>Here is the specific request:<p>```