Skip to content

Instantly share code, notes, and snippets.

@promto-c
promto-c / silhouettefx_scripts_toggle_stabilize.py
Created March 13, 2025 20:16
SilhouetteFX's Script - Sets the selected layer (or its parent if it's a shape) as the stabilize layer, clears it if it's the active layer, and centers the selection in the viewer.
"""Copyright (C) 2020 promto-c
Permission Notice:
- You are free to use, copy, modify, and distribute this software for any purpose.
- No restrictions are imposed on the use of this software.
- You do not need to give credit or include this notice in your work.
- Use at your own risk.
- This software is provided "AS IS" without any warranty, either expressed or implied.
- This license does not cover any third-party libraries or dependencies used in this software. Those libraries are subject to their respective licenses.
"""
@promto-c
promto-c / text_similarity_mapper.py
Last active November 12, 2024 09:49
Python function to map strings in one list to the closest matches in another based on similarity scores. Useful for cases requiring best-effort text alignment, such as matching filenames or finding similar text patterns.
"""Copyright (C) 2024 promto-c
Permission Notice:
- You are free to use, copy, modify, and distribute this software for any purpose.
- No restrictions are imposed on the use of this software.
- You do not need to give credit or include this notice in your work.
- Use at your own risk.
- This software is provided "AS IS" without any warranty, either expressed or implied.
"""
from difflib import SequenceMatcher
@promto-c
promto-c / 3d_rendering_mvp_explanation.md
Created September 28, 2024 21:55
Explanation of the Model-View-Projection (MVP) matrix in 3D graphics programming. Covers the breakdown of Model, View, and Projection matrices, their roles, and how they are combined for 3D rendering.

Model-View-Projection (MVP) Matrix in 3D Graphics

In 3D graphics programming, MVP stands for Model-View-Projection matrix. It is a transformation matrix that combines three separate transformations—Model, View, and Projection—into a single matrix to convert 3D coordinates into 2D screen coordinates for rendering.

Components of MVP

1. Model Matrix (M)

  • Represents the transformation of an object from model space to world space.
  • This matrix is used to position, rotate, and scale the model within the world.
  • Example transformations include:
import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from sklearn.metrics import mean_squared_error
import category_encoders as ce
import time
# Load the dataset
file_path = 'car1.csv'
@promto-c
promto-c / nuke_node_alignment.py
Created July 12, 2024 19:48
Python script for aligning selected nodes in Nuke horizontally or vertically based on user preferences. Includes functionality to toggle alignment and retrieve grid spacing settings from Nuke's preferences.
import nuke
from typing import List, Tuple
class NodeAlignment:
"""Handles the alignment of nodes in Nuke."""
DEFAULT_SPACING = 100
@staticmethod
@promto-c
promto-c / sqlite_schema_to_dbml.py
Created May 29, 2024 06:32
This Python script converts the schema of an SQLite database to DBML format. It exports the table definitions and foreign key relationships, allowing for easy visualization of the database structure using tools like dbdiagram.io.
"""
Copyright (C) 2024 promto-c
Permission Notice:
- You are free to use, copy, modify, and distribute this software for any purpose.
- No restrictions are imposed on the use of this software.
- You do not need to give credit or include this notice in your work.
- Use at your own risk.
- This software is provided "AS IS" without any warranty, either expressed or implied.
"""
@promto-c
promto-c / nuke_toggle_nodes_alignment.py
Created April 23, 2024 07:00
A Python script to dynamically switch selected nodes between horizontal and vertical alignment using the 'L' shortcut, with configurable spacing.
import nuke
def toggle_nodes_alignment(spacing=100):
"""Toggle the alignment of selected nodes between horizontal and vertical.
Args:
spacing (int): The spacing between nodes after alignment.
"""
nodes = nuke.selectedNodes()
@promto-c
promto-c / SQLite_Journal_Modes_Explained.md
Last active April 22, 2025 21:00
A comprehensive guide to SQLite's journal modes, including WAL, DELETE, TRUNCATE, PERSIST, MEMORY, and OFF. Understand the differences, use cases, and how to switch modes to optimize your SQLite database for performance, concurrency, and reliability.

SQLite Journal Modes Explained

SQLite supports several journal modes, each offering advantages in performance, concurrency, and the way changes are logged and applied. This guide explains the journal modes available in SQLite so you can choose the right one for your application.

1. WAL (Write‑Ahead Logging)

PRAGMA journal_mode = WAL;
  • Description
@promto-c
promto-c / write_unlock_pdf.py
Created April 5, 2024 15:51
Python function to unlock a password-protected PDF using PyPDF2
import PyPDF2
def unlock_pdf(input_pdf_path, password, output_pdf_path):
"""Unlocks a password-protected PDF file and saves an unlocked version.
This function attempts to unlock a PDF file using the provided password. If successful,
it creates a new PDF file without the password protection. It handles both cases where
the PDF is encrypted and when it's not. In case of failure due to an incorrect password
or any other issue, it prints an error message.
@promto-c
promto-c / sanitize_string.py
Created March 22, 2024 10:45
A Python function to sanitize input strings by replacing non-alphanumeric characters with underscores, stripping leading/trailing underscores or spaces, and prepending an underscore if the string starts with a digit.
import re
def sanitize_string(input_string, prepend_char='_'):
"""
Replaces any character not in [a-zA-Z0-9_] with an underscore, strips leading and trailing underscores or spaces,
and prepends a character if the first character is a digit.
Args:
input_string (str): The string to be sanitized.
prepend_char (str): The character to prepend if the first character is a digit. Defaults to '_'.