Skip to content

Instantly share code, notes, and snippets.

@spajak
spajak / mpeg2mkv-steps.ps1
Last active February 29, 2024 20:35
Convert/rip DVD to MKV. Encode to MPEG-4 & merge into MKV - all without GUI, only command line tools
# My steps to:
# Convert DVD Video to MPEG-4 in MKV without GUI, using only CLI (Command Line Interface) tools.
# No need for MeGUI, Avisynth, Handbrake etc..
# ------------------------------------------------------------------------------
# Tools needed: `mediainfo`, `ffmpeg` & `ffprobe`, `x264`, `mkvmerge`, `mplayer` (optional).
# Google for them. Use latest versions. Windows tip: avoid Cygwin and get
# the official builds, x64, when possible.
# Before start use `mediainfo` & `ffprobe` and note down informations about the source material:
@spajak
spajak / IPv6.ps1
Last active January 29, 2024 14:04
Disable random IPv6 addresses and use SLAAC IPv6 (Windows 10)
# Disable random IPv6 addresses (but keep temporary addresses),
# and use SLAAC address as a preferred IPv6 address in Windows 10
# ------------------------------------------------------------------------------
# UseTemporaryAddresses
#
# Always. The computer always generates temporary addresses by using random numbers.
# Counter. The computer generates temporary addresses by using the interface identifier.
# You typically use this identifier for test purposes.
# Disabled. The computer does not use temporary addresses.
@spajak
spajak / vhd4wsl2.md
Last active October 1, 2023 05:09
Creating virtual hard disk (VHD) for WSL2

Creating additional virtual hard disk (VHDX) for WSL2 with ext4 filesystem

Lines starting with # mean the commands have to be executed by root user under Linux shell (WSL distro). All other commands have to be executed under Windows-PowerShell as Administrator.

Make VHDX disk file and mount it under Windows

New-VHD support.vhdx -SizeBytes 25GB -Dynamic -BlockSizeBytes 1MB
Write-Output "\\.\PhysicalDrive$((Mount-VHD -Path support.vhdx -PassThru | Get-Disk).Number)"
@spajak
spajak / make-epub.py
Created August 27, 2021 17:54
Make EPUB e-book file from a given directory. The directory must be a valid EPUB ebook source.
import sys
from pathlib import Path
from zipfile import ZipFile, ZIP_DEFLATED, ZIP_STORED
def main():
usage = f'{sys.argv[0]} source_dir [destination_file]'
if len(sys.argv) > 1:
src = Path(sys.argv[1])
dst = Path(sys.argv[2]) if len(sys.argv) > 2 else Path(src.name + ".epub")
validate(src, dst)
@spajak
spajak / build-epub.ps1
Last active April 30, 2023 19:42
Creates EPUB e-book package from a given directory containing ebook source files.
[CmdletBinding(DefaultParameterSetName = "Default")]
param(
[Parameter(Position=0, Mandatory=$true, ValueFromPipeline=$true)]
[Alias("i", "Path", "Source")]
[String] $SourceDirectory,
[Parameter(Mandatory=$true, ParameterSetName="DestinationAlongSource")]
[Alias("ds", "os")]
[Switch] $DestinationAlongSource,
@spajak
spajak / 7zip-epub.md
Last active April 30, 2023 19:41
Make epub using 7zip command line utility

Make epub archive using 7zip command line utility in PowerShell.

$source = ".\ebook"
$epub = ".\ebook.epub"

$source = (Resolve-Path $source -ErrorAction Stop).Path
Move-Item "${source}\mimetype" ".mimetype" -ErrorAction Stop
Remove-Item "$epub" -ErrorAction Ignore
& 7za a -mx0 "$epub" ".mimetype"
@spajak
spajak / png2ico.ps1
Last active January 3, 2023 06:54
Simple script to convert PNG image to Windows ICO format using ImageMagick
param(
[String] $png
)
$root = Split-Path "$png" -Parent
$name = Split-Path "$png" -LeafBase
$icon = Join-Path $root ($name + ".ico")
& magick "$png" -strip -background none `
-gravity center -extent "%[fx:max(w,h)]x%[fx:max(w,h)]" `
@spajak
spajak / ogm-chapters.py
Last active December 7, 2022 08:44
Simple OGM chapters generator for MKVToolNix
# Simple OGM chapters generator for MKV Video
# -------------------------------------------
# Use it like this:
# $ python ogm-chapters.py times.txt [chapters.txt]
# Where times.txt contains timestamps separated by a whitespace or comma
import sys
from pathlib import Path
import re
@spajak
spajak / rpi-temp.sh
Last active August 5, 2022 20:42
Raspberry Pi - get CPU and GPU temperature
#!/bin/bash
cpu=$(</sys/class/thermal/thermal_zone0/temp)
cpu=$(printf %.1f "${cpu}e-3")
gpu=$(vcgencmd measure_temp)
gpu=${gpu:5:-2}
echo "CPU: ${cpu} °C"
echo "GPU: ${gpu} °C"
@spajak
spajak / ccs.py
Last active June 3, 2022 01:20
Generate console colors scheme for Windows Console, Windows Terminal and Putty in a form of .reg files (Windows Registry) and json
# Console colors for Windows
# --------------------------
# Script outputs console color scheme files for Windows in the followng formats:
# <win>.reg file - Windows legancy console colors
# <putty>.reg file - Putty console colors
# <concfg>.json - concfg.json scheme
# <wt>.json - Windows Terminal color scheme
#
# Windows reg file is for default console. Putty sessions are configurable below, see: `puttySessions` variable.
# Feel free to change the colors. Provided palette is a simple and reasonable default for dark background.