Thursday, February 20, 2025

ChatCommit: Auto-Generated Git Commit Message Summarizer

# Add to your profile the following bash function
# Use it with this command: git commit -m "$(summarize_git_diff)"
# To confirm how the commit message will look like: git log -1
export OPENAI_API_KEY='your openai api key'
summarize_git_diff() {
# Capture the full git diff (staged changes) without using a pager
local diff_file chunk_dir chunk_prefix final_summary chunk payload response chunk_summary
diff_file=$(mktemp)
git --no-pager diff --cached > "$diff_file"
# Create a temporary directory for the chunk files
chunk_dir=$(mktemp -d)
chunk_prefix="${chunk_dir}/chunk_"
# Split the diff file into chunks of 200 lines (adjust as needed)
split -l 200 "$diff_file" "$chunk_prefix"
# Initialize the final summary
final_summary=""
# Process each chunk
for chunk in "${chunk_dir}"/chunk_*; do
# Build the JSON payload safely using jq's --rawfile to avoid issues with quotes or newlines
payload=$(jq -n --rawfile chunk "$chunk" \
--arg preface "Summarize concisely without losing preciseness the following git diff output to produce a git commit message:\n" \
'{
model: "gpt-3.5-turbo",
messages: [{role: "user", content: ($preface + $chunk)}],
max_tokens: 150,
temperature: 0.3
}')
# Call the OpenAI API
response=$(curl -sS https://api.openai.com/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer ${OPENAI_API_KEY}" \
-d "$payload")
# Extract the summary for this chunk
chunk_summary=$(echo "$response" | jq -r '.choices[0].message.content')
# Append the chunk summary to the final summary
final_summary="${final_summary}\n\n${chunk_summary}"
done
# Clean up temporary files and directory
rm "$diff_file"
rm -r "$chunk_dir"
# Output the combined summary
echo -e "$final_summary"
}
view raw chat-commit.sh hosted with ❤ by GitHub

Thursday, December 19, 2024

Uninstalling python from windows where no uninstaller can be found

1. Find out the exact version installed for the package you want to remove. In this case 3.12:
PS > py --list
 -V:3.13 *        Python 3.13 (64-bit)
 -V:3.12          Python 3.12 (64-bit)
PS > py -3.12 --version
Python 3.12.0
2. Find out where the executable is for that version, in this case it is in C:\Program Files\Python312\python.exe:
PS > py -3.12 -c "import sys; print(sys.executable)"
C:\Program Files\Python312\python.exe
3. Delete the root folder containing the executable to remove that python version:
PS > Remove-Item -Path "C:\Program Files\Python312" -Recurse -Force
4. Remove registry entries for that installation (you should find 3.12 as an entry in our case in one or the two places below):
Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Python\PythonCore\
and/or
Computer\HKEY_CURRENT_USER\SOFTWARE\Python\PythonCore\
5. Confirm the only version installed is the one you expect. In our case we expect only 3.13:
PS > py --list
 -V:3.13 *        Python 3.13 (64-bit)

Tuesday, August 06, 2024

Remove server header in IIS to stop disclosing running version(s)

Set attribute removeServerHeader="true" in web.config node configuration."system.webServer".security.requestFiltering.

Thursday, July 18, 2024

When the clock on MAC OSX goes off

To sync your macOS clock and prevent it from drifting after sleep cycles, follow these steps:

- Run this command to sync time:
sudo sntp -sS time.apple.com
- Go to System Settings > Date & Time and turn off "Set time and date automatically."

- Remove the current time settings:
sudo rm /var/db/timed/com.apple.timed.plist
- Reboot the Mac.

- After reboot, turn on "Set time and date automatically" in System Settings > Date & Time. This should ensure your clock remains accurate.

Followers