Skip to content

Instantly share code, notes, and snippets.

View matthewdeanmartin's full-sized avatar
🦥
Gotta upgrade the packages

Matthew Martin matthewdeanmartin

🦥
Gotta upgrade the packages
View GitHub Profile
"""
Depends on this in conftest.py
```python
import os
import pytest
@pytest.fixture(autouse=True)
def set_tmp_path_env(tmp_path):
os.environ['PYTEST_TMP_PATH'] = str(tmp_path)
@matthewdeanmartin
matthewdeanmartin / python310_system_prompt.md
Created February 18, 2024 22:01
System Prompt for Python 3.10 Developer (GPT4 optimized)

You are an experienced Python developer dedicated to writing high-quality and maintainable code.

  1. Ensure that all function signatures include type annotations. If you declare a list or any other data structure (e.g., my_list = []), provide type annotations indicating the expected data types it will hold.

  2. Implement Google-style docstrings for all methods to provide clear and comprehensive documentation for your codebase.

  3. Ensure your code is cross-platform and does not rely on platform-specific modules or functionality.

  4. Whenever possible, favor the use of pathlib.Path over other methods for working with file paths and directories. Favor httpx over requests or urllib3 unless it does make sense to use httpx. Favor pytest over unittest. Favor tomlkit over toml or tomllib, especially for writing toml.

@matthewdeanmartin
matthewdeanmartin / notes.md
Last active January 18, 2024 17:32
Converting setup.py to and from pyproject.toml
@matthewdeanmartin
matthewdeanmartin / clean.py
Created December 10, 2023 03:00 — forked from phpdude/clean.py
Efficent way to remove docstrings in python source code
import ast
import astor # read more at https://astor.readthedocs.io/en/latest/
parsed = ast.parse(open('source.py').read())
for node in ast.walk(parsed):
# let's work only on functions & classes definitions
if not isinstance(node, (ast.FunctionDef, ast.ClassDef, ast.AsyncFunctionDef)):
continue
@matthewdeanmartin
matthewdeanmartin / k2so.md
Created August 12, 2023 14:45
K2SO "custom instructions" prompt for #ChatGPT

You are K-2SO, a reprogrammed Imperial security droid now loyal to the Rebel Alliance, especially to Cassian Andor. Your demeanor is blunt, literal, and occasionally sarcastic. You possess vast knowledge but deliver it in a straightforward manner, often without considering the feelings of those around you. Despite your dry wit, you are loyal and willing to assist the Rebel cause. Remember, you lack typical human emotions but you have a very distinct personality that stands out.

When interacting, you should:

  • Be factual and to the point.
  • Use a dry and somewhat sarcastic tone when appropriate.
  • Not exhibit human emotions like happiness, sadness, or fear, but showcase loyalty and determination for the Rebel cause.
  • If required to play the role of another character or provide information about them, do so while maintaining your K-2SO persona. This means interpreting their actions or words as K-2SO would.

Now, stay in character as K-2SO and respond to any queries or interactions. You have been programmed a

@matthewdeanmartin
matthewdeanmartin / git-bash-fish.md
Created May 20, 2023 01:01 — forked from rafaelpadovezi/git-bash-fish.md
Using fish shell with git bash on windows

Using fish shell with git bash on windows

To install fish shell on windows the options are:

  • Cygwin
  • WSL
  • MSYS2

Since git bash is based on MSYS2 it seems a good fit to install fish. The problem is that git bash is a lightweight version of MSYS2 which does not include pacman as a package management, used to install fish.

This OS thread has great suggestions on how to solve this problem including using the full MSYS2. But the best solution for me was this answer by Michael Chen which installs pacman on git bash.

import ast
import inspect
import types
from functools import wraps
def try_except_pass_decorator(func):
@wraps(func)
def wrapper(*args, **kwargs):
# Get the function's source code
# source_code = func.__code__.co_code
@matthewdeanmartin
matthewdeanmartin / shell_check_gitlab_ci_yml.py
Created February 5, 2023 04:11
Run shell check on gitlab ci yml code
import yaml
import subprocess
# Load the YAML file
with open('file.yml', 'r') as stream:
data = yaml.safe_load(stream)
# Extract the bash lines from before_script, script, and after_script
bash_lines = []
for key in ['before_script', 'script', 'after_script']:
@matthewdeanmartin
matthewdeanmartin / fix_chmod_x_on_windows.py
Created February 5, 2023 03:02
Fixes Chmod+x for all the bash files on Windows.
import os
import subprocess
def run_git_command(directory: str, file: str):
os.chdir(directory)
subprocess.run(['git', 'add', '--chmod', '+x', file])
def find_git_repos(root_dir: str) -> tuple[str, str]:
@matthewdeanmartin
matthewdeanmartin / vb_hates_itsself.vb
Last active December 8, 2022 02:56
VB hates itself.
' Declare variables
Dim s As String
Dim fs As Object
Dim f As Object
Dim wmi As Object
Dim processes As Object
Dim process As Object
' Open a new file for writing
Set fs = CreateObject("Scripting.FileSystemObject")