Archives 2024

låt

[Verse]
Henrik’s the name
Coding’s my game
Teaching algorithms
Textbooks are my fame
From morning till night
Never taking a break
Putting bugs to sleep
No time for mistake
Late nights in the lab
Lines of codeI tackle
Debugging and testing
Never skipping a shackle
Stacking functions like bricks
to build a masterpiece
In my programming kingdom
I’m the high priest

[Verse 2]
Students looking tired
Minds filled with doubt
Losing motivation
Feeling left out
But I’m here to uplift
Lift the spirits high
Turning zeros to heroes
That’s my battle cry

https://suno.com/song/6038be8e-1dcf-4af1-9a52-190f3f1b28fd

convert to mp4

convert movie format to mp4 ?
this code are scanning for example mkv and convert all to mp4

#!/bin/bash

# Help message function
print_help() {
    echo "Usage: $0 <file_extension>"
    echo "Example: $0 mkv"
}

# Check if argument is provided
if [ $# -eq 0 ]; then
    print_help
    exit 1
fi

# Supported video file formats
supported_formats=("avi" "mkv" "mov" "mp4" "wmv" "flv" "mpg" "mpeg" "3gp")

# Check if provided file extension is supported
if [[ ! " ${supported_formats[@]} " =~ " $1 " ]]; then
    echo "Unsupported file format. Supported formats: ${supported_formats[*]}"
    print_help
    exit 1
fi

# Loop through all files with the provided extension in the current directory
for file in *."$1"; do
    # Check if the file exists
    if [ -e "$file" ]; then
        # Get the filename without extension
        filename="${file%.*}"

        # Convert the file to mp4 using ffmpeg
        ffmpeg -i "$file" "${filename}2.mp4"

        # Optional: Check if conversion was successful and remove the original file
        if [ $? -eq 0 ]; then
            echo "Conversion of $file successful."
            rm "$file"
        else
            echo "Conversion of $file failed."
        fi
    else
        echo "No files with .$1 extension found."
        exit 1
    fi
done

why not.. we do it in php to… but now you most write a dir to.

<?php

// Function to convert video files to mp4
function convertVideosToMp4($folder, $extension) {
    // Supported video file formats
    $supportedFormats = ["avi", "mkv", "mov", "mp4", "wmv", "flv", "mpg", "mpeg", "3gp"];

    // Check if provided file extension is supported
    if (!in_array($extension, $supportedFormats)) {
        echo "Unsupported file format. Supported formats: " . implode(", ", $supportedFormats) . PHP_EOL;
        return;
    }

    // Open the directory
    if ($handle = opendir($folder)) {
        // Loop through all files in the directory
        while (false !== ($file = readdir($handle))) {
            // Check if the file has the provided extension
            if (pathinfo($file, PATHINFO_EXTENSION) == $extension) {
                // Get the filename without extension
                $filename = pathinfo($file, PATHINFO_FILENAME);

                // Convert the file to mp4 using ffmpeg and rename to {filename}2.mp4
                $command = "ffmpeg -i \"$folder/$file\" \"$folder/{$filename}2.mp4\"";
                exec($command, $output, $return_var);

                // Check if conversion was successful and remove the original file
                if ($return_var == 0) {
                    echo "Conversion of $file successful." . PHP_EOL;
                    unlink("$folder/$file");
                } else {
                    echo "Conversion of $file failed." . PHP_EOL;
                }
            }
        }
        // Close the directory handle
        closedir($handle);
    } else {
        echo "Unable to open directory: $folder" . PHP_EOL;
    }
}

// Check if folder and extension are provided
if ($argc < 3) {
    echo "Usage: php convert.php <folder_path> <file_extension>" . PHP_EOL;
    echo "Example: php convert.php /path/to/folder mkv" . PHP_EOL;
    exit(1);
}

// Get folder path and extension from command line arguments
$folderPath = $argv[1];
$extension = $argv[2];

// Call function to convert videos to mp4
convertVideosToMp4($folderPath, $extension);

?>

 

why not… we do it in python to

import os
import subprocess
import sys

def convert_videos_to_mp4(folder, extension):
    # Supported video file formats
    supported_formats = ["avi", "mkv", "mov", "mp4", "wmv", "flv", "mpg", "mpeg", "3gp"]

    # Check if provided file extension is supported
    if extension not in supported_formats:
        print(f"Unsupported file format. Supported formats: {', '.join(supported_formats)}")
        return

    # Loop through all files in the folder
    for file in os.listdir(folder):
        # Check if the file has the provided extension
        if file.endswith(f".{extension}"):
            # Get the filename without extension
            filename = os.path.splitext(file)[0]

            # Convert the file to mp4 using ffmpeg and rename to {filename}2.mp4
            command = f"ffmpeg -i \"{os.path.join(folder, file)}\" \"{os.path.join(folder, filename)}2.mp4\""
            subprocess.run(command, shell=True)

            # Check if conversion was successful and remove the original file
            if os.path.exists(os.path.join(folder, f"{filename}2.mp4")):
                print(f"Conversion of {file} successful.")
                os.remove(os.path.join(folder, file))
            else:
                print(f"Conversion of {file} failed.")

# Check if folder and extension are provided
if len(sys.argv) < 3:
    print("Usage: python convert.py <folder_path> <file_extension>")
    print("Example: python convert.py /path/to/folder mkv")
    sys.exit(1)

# Get folder path and extension from command line arguments
folder_path = sys.argv[1]
extension = sys.argv[2]

# Call function to convert videos to mp4
convert_videos_to_mp4(folder_path, extension)

 

vägar olyckor api

Steg 1: Besök API:ets webbplats

Gå till https://henrikhjelm.se/api/vagar.php för att få en översikt över API:et och eventuellt se om det finns något användbart formulär.

Steg 2: Exempel på API-anrop

En exempel-URL för att hämta vägdata för en given plats och radie ser ut så här:

https://henrikhjelm.se/api/vagar.php?lat=62.3908&long=17.3069&radius=200

Steg 3: Exempel på API-svar

API:et kommer att returnera vägdata i JSON-format. Här är ett exempel på hur svaret kan se ut:

{
    "road": [
        {
            "id": 9181805,
            "priority": 3,
            "createddate": "2024-01-15 17:53:18",
            "title": "Lv 623 Håkanstaleden",
            "exactlocation": "Håkansta–Norderön",
            "description": "Färjan är ur trafik från tisdag 2/1 kl 09:00 på grund av rådande isläge. Isvägen mellan Sunne och Vällviken ersätter färjan.",
            "latitude": 63.136474609375,
            "longitude": 14.32264518737793,
            "category": 0,
            "subcategory": "Färja"
        },
        {
            "id": 9301925,
            "priority": 3,
            "createddate": "2024-01-15 23:42:31",
            "title": "Lv 586 Vällviken–Sunne",
            "exactlocation": "",
            "description": "Isvägen mellan Vällviken och Sunne är öppen för fordon upp till två ton.",
            "latitude": 63.09188461303711,
            "longitude": 14.383475303649902,
            "category": 1,
            "subcategory": "Färja"
        }
    ]
}