For programming tasks I use ChatGPT as a kind of aggregator for programming searches. Before ChatGPT I would type a question into a search engine and then trawl through pages of stack overflow. Now I type the same question into ChatGPT and it's already done the trawling and just gives me the answer.
I'm not asking it to write a program for me, I'm asking it to give me a specific answer to a specific programming problem. One where I know what I want and the principles of how to do it but not necessarily the exact syntax to use.
For example yesterday I wanted to know how to find for multiple substrings within another string using PHP. My usual approach would be stristr and a loop but I was pretty sure there was a regex way to do it. ChatGPT provided a perfect answer that I was able to adapt for my needs.
Code: Select all
$haystack = "This is a sample string.";
$needles = array("sample", "string");
$pattern = '/' . implode('|', $needles) . '/';
if (preg_match($pattern, $haystack)) {
echo "At least one of the needles was found in the haystack.";
} else {
echo "None of the needles were found in the haystack.";
}
I also find it incredibly helpful for writing bash scripts, sometimes it can do the entire thing for me.
For example I asked it to write a script that converts a folder of wave files to ogg. Yes I could have written this myself, but it was much faster to get the bot to do it.
Code: Select all
#!/bin/bash
# Check if the input folder argument is provided
if [ $# -eq 0 ]; then
echo "Please provide the input folder as an argument."
exit 1
fi
# Get the input folder from the argument
input_folder="$1"
# Check if the input folder exists
if [ ! -d "$input_folder" ]; then
echo "Input folder does not exist."
exit 1
fi
# Create the output folder within the input folder
output_folder="$input_folder/ogg"
mkdir -p "$output_folder"
# Convert each WAV file to OGG format
for file in "$input_folder"/*.wav; do
# Get the filename without the extension
filename=$(basename "$file" .wav)
# Construct the output file path
output_file="$output_folder/$filename.ogg"
# Convert WAV to OGG using ffmpeg
ffmpeg -i "$file" "$output_file"
done
echo "Conversion completed."