Skip to content

Instantly share code, notes, and snippets.

View stuaxo's full-sized avatar
💭
 

Stuart Axon stuaxo

💭
 
View GitHub Profile
@stuaxo
stuaxo / parquet_schema.py
Created June 26, 2024 13:32
Output data types of the columns in a parquet file
DATA_FILE = "your-file.parquet"
import pandas as pd
# Read the Parquet file
df = pd.read_parquet(DATA_FILE)
def df_schema(df):
# Print the column names and their types
for column in df.columns:
@stuaxo
stuaxo / addvenvkernel.sh
Created May 9, 2024 11:13
Create a Jupyter Kernel for for the current virtualenv.
#!/bin/bash
# This script creates a Jupyter kernel for a virtual environment.
# Get the name of the virtual environment from the command line or default to the current environment.
VENV_NAME="$1"
# Check if a virtual environment name was provided
if [ -z "$VENV_NAME" ]; then
if [ -z "$VIRTUAL_ENV" ]; then
@stuaxo
stuaxo / utm-linux-vm-playbook.md
Last active August 10, 2023 17:19
Ubuntu VM in a Mac Host [QEmu with UTM frontend]
@stuaxo
stuaxo / download_file.sh
Last active July 16, 2023 00:56
Download a file using intermediate .part file and automatically resume.
#!/bin/bash
# Function to handle the download
download_file() {
local delete_flag="${1:-false}"
local url="$2"
local filename="$3"
# Extract filename from URL if not provided
if [ -z "$filename" ]; then
@stuaxo
stuaxo / download-gist.sh
Last active May 15, 2023 22:08
Download all files in a github gist to the current directory
#!/bin/bash
#
# Download all the files in a GitHub Gist
#
# Example usage:
# $ download-gist.sh https://gist.github.com/stuaxo/2e110aaa42050490ad3fd73cfbedf76a
#
# By default, files are not overwritten. The -f option overrides this behavior:
# $ download-gist.sh -f https://gist.github.com/stuaxo/2e110aaa42050490ad3fd73cfbedf76a
#
@stuaxo
stuaxo / download-ow1.9.sh
Last active July 16, 2023 00:57
Install openwatcom-1.9 on Linux
#!/bin/bash
#
# Download open watcom 1.9 from sourceforge.
#
# Requires curl or wget
FILENAME="open-watcom-c-linux-1.9"
URL="https://master.dl.sourceforge.net/project/openwatcom/open-watcom-1.9/$FILENAME"
# Check if curl is available
if command -v curl >/dev/null 2>&1; then
@stuaxo
stuaxo / dirtollm.py
Last active September 10, 2024 16:31
Output files in subdirectories for ingestion to an LLM such as Claude, ChatGPT etc.
#!/usr/bin/env python3
# Usage: python dirtollm.py [files or glob patterns...] [options]
# Example: python dirtollm.py "*.py" "*.txt" /path/to/specific/file.py --exclude "*.pyc" --copy --verbose -x --binaries
import argparse
import pathlib
import fnmatch
import sys
import os
@stuaxo
stuaxo / hyperlink.sh
Last active July 16, 2023 00:57
Output OSC-8 hyperlink in the terminal
@stuaxo
stuaxo / sys_path_via_dotenv.py
Created February 3, 2023 12:34
Update sys.path if PYTHONPATH is changed by dotenv
def update_paths():
import os
import sys
import dotenv
dotenv.load_dotenv(override=True)
new_paths = {*os.environ["PYTHONPATH"].split(":")} - set(sys.path)
sys.path.extend(new_paths)
@stuaxo
stuaxo / concat_non_null_fields.py
Created April 5, 2022 12:32
Django concatenate non null fields. #snippet
# Ended up not using this, as there was only one place in the codebase.
def concat_non_null_fields(fields, seperator):
"""
Build a case statement expression to concatenate the supplied fields where isnull is False.
:param fields: List of fields to concatenate.
:param seperator: Seperator to use between fields.
:return: Case statement expression.