Skip to content

Instantly share code, notes, and snippets.

@AJeschor
AJeschor / sgpt_switch.txt
Last active March 14, 2024 20:12
Scripts to switch ShellGPT from using OpenAI to LiteLLM and vice-versa
Place these two scripts in a directory of your choice (in this example its ~/.scripts) and make aliases of your choice for each script. Use "sudo chmod +x <script_name>" or equivalent to give them executable permission.
# Example aliases
```
alias sgpt2lite="~/.scripts/sgpt2lite.sh"
alias sgpt2openai="~/.scripts/sgpt2openai.sh"
```
@AJeschor
AJeschor / colour_test.py
Created March 1, 2024 17:26
The purpose of this script is to provide a way to visualize all the different primary ANSI escape code colours to different colors so users can easily customize the appearance of their terminal output according to their preferences.
def print_color(text, color):
colors = {
'black': '\033[30m',
'red': '\033[31m',
'green': '\033[32m',
'yellow': '\033[33m',
'blue': '\033[34m',
'magenta': '\033[35m',
'cyan': '\033[36m',
'white': '\033[37m',
@AJeschor
AJeschor / spacy_init.py
Last active February 29, 2024 22:46
This script provides a flexible and easily configurable way to initialize a SpaCy model, allowing users to specify the model to use and whether GPU should be preferred for processing.
"""
The script initializes a SpaCy model with configurable GPU preference. It loads the specified model, prints GPU/CPU usage based on preference, and provides the initialized SpaCy pipeline for natural language processing tasks.
spacy_download automatically downloads a model with pip and then load it as a module when it is not currently installed, its usage is identical to spacy.load(), meaning that you can also exclude or disable pipeline components.
"""
import spacy
import spacy.cli
from spacy.language import Language
from spacy_download import load_spacy
@AJeschor
AJeschor / spacy_checker.py
Created February 29, 2024 22:04
Prints out information about each installed spaCy model, including the model name, size, and version, as well as the spaCy version, the path of the virtual environment if running within one, and the availability of GPU for spaCy.
import spacy.util
import sys
import os
import spacy
def get_installed_models():
"""
Get information about installed spaCy models.
Prints out information about each installed spaCy model, including
@AJeschor
AJeschor / pytorch_cuda_check.py
Created February 29, 2024 02:15
Checks the availability of CUDA using PyTorch functions. Provides information on available CUDA devices, their specifications, CUDA version, and PyTorch version if they are available.
import torch
def check_cuda_availability():
"""
Check GPU/CUDA availability using PyTorch functions.
This function checks whether CUDA is available on the system
and provides information about available CUDA devices, if any.
This script will work for PyTorch versions 0.4 and above.
@AJeschor
AJeschor / activate_env_alias.sh
Last active February 29, 2024 21:50
These aliases are designed to assist users in projects where multiple virtual environments coexist within the same directory. Upon execution, they iterates through directories in the root (/) and sources the activation script (bin/activate) of the first encountered virtual environment.
alias actenv='select folder in *(/); do source $folder/bin/activate; break; done'
alias .actenv='select folder in .*/(/); do source "$folder"/bin/activate; break; done'
@AJeschor
AJeschor / check_site_package.py
Created February 10, 2024 00:57
This Python script provides a simple way to retrieve the site packages directories within your Python environment.
"""
Python Script to Get Site Packages
Description:
This Python script provides a simple way to retrieve the site packages directories within your Python environment. If you're new to Python development or exploring the Python ecosystem, understanding where your packages are installed can be crucial. By using the `site` module, this script fetches the paths to the site packages, which typically contain third-party packages installed via pip or other package managers.
How to Use:
1. Installation: Ensure you have Python installed on your system. You can download and install Python from the official website: [Python Downloads](https://www.python.org/downloads/).
2. Clone the Gist: Clone or download this gist from GitHub to your local machine.
3. Run the Script: Open your terminal or command prompt, navigate to the directory containing the script, and execute it by typing `python script_name.py` (replace `script_name.py` with the actual name of the script).
@AJeschor
AJeschor / ls_dpkg.py
Last active February 3, 2024 23:31
The script extracts and formats information about installed Debian-based system packages using dpkg --list, allowing users to choose output formats (Markdown, CSV, YAML, TXT, or XLSX) and a directory for saving the file.
#!/usr/bin/env python3
# NOTE: If you encounter any issues running the script, update the shebang line
# above to the path of your Python 3 interpreter. You can find the path by running
# the 'which python3' command in your terminal. Example:
# #!/usr/bin/env /usr/bin/python3
"""
The script retrieves a list of installed packages on a Debian-based system using the `dpkg --list` command.
It prompts the user to select an output format (Markdown, CSV, YAML, TXT, or XLSX) and a directory to save the resulting file.
@AJeschor
AJeschor / config_dir_gen.py
Last active February 29, 2024 21:38
This Python script creates an INI configuration file for project directories, reflecting the directory structure under the current working directory (including the base project directory). This script needs configparser (which is in the standard library of Python 3.5, 3.6, 3.7, 3.8, 3.9, 3.10) and can work as an alias.
#!/usr/bin/env python3
# NOTE: If you encounter any issues running the script, update the shebang line
# above to the path of your Python 3 interpreter. You can find the path by running
# the 'which python3' command in your terminal. Example:
# #!/usr/bin/env /usr/bin/python3
"""
To run the script, ensure that the script file has the necessary read and execute permissions.
1. Save this script to a directory of your choice.
@AJeschor
AJeschor / whichenv.sh
Last active March 5, 2024 18:10
The script detects Poetry, Pipenv, Virtualenv, Conda, and Pyenv environments, initializes variables, checks for package manager/tool existence, determines the active state, and prints name & path info about the active environment. It handles cases of missing tools & provides details on the active Pyenv environment or local environment set by Pyenv.
#!/usr/bin/env python3
# NOTE: If you encounter any issues running the script, update the shebang line
# above to the path of your Python 3 interpreter. You can find the path by running
# the 'which python3' command in your terminal. Example:
# #!/usr/bin/env /usr/bin/python3
"""
This script is designed to assist users in projects where multiple virtual environments coexist within the same directory.
It searches for directories that meet the criteria of a virtual environment and presents the user with them as options in a prompt so they can easily select which environment they wish to activate.