Skip to content

Instantly share code, notes, and snippets.

View zhiyuan-lin's full-sized avatar
🎯
Focusing

Zhiyuan Lin zhiyuan-lin

🎯
Focusing
  • Tokyo, Japan
  • 14:06 (UTC +09:00)
View GitHub Profile
@zhiyuan-lin
zhiyuan-lin / Disable Signin to Microsoft Edge and Google Chrome on Windows.reg
Created February 21, 2024 09:37
Disable Signin to Microsoft Edge and Google Chrome on Windows
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Edge]
"BrowserSignin"=dword:00000000
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome]
"BrowserSignin"=dword:00000000
@zhiyuan-lin
zhiyuan-lin / ComicInfo.xml
Last active February 5, 2024 13:12
ComicInfo.xml 2.0 example, you have to put it at root level for Komga to recognize, you cannot put it inside a folder.
<?xml version="1.0" encoding="UTF-8"?>
<ComicInfo xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/anansi-project/comicinfo/main/schema/v2.0/ComicInfo.xsd">
<Title>神無月の巫女 (1)</Title>
<Series>神無月の巫女</Series>
<Number>1</Number>
<Count>2</Count>
<Summary>
宿命の巫女として転生した二人の少女と、運命に抗う一人の少年。そして暗黒神=ヤマタノオロチ復活を狙う巨大ロボ軍団! 現代に甦る神々が世界の命運を賭けて、壮絶なロボバトルを繰り広げる衝撃の第1巻!!
</Summary>
@zhiyuan-lin
zhiyuan-lin / manga-cutter.ps1
Created January 1, 2024 13:21
PowerShell 2 panel manga cutter
# Get the list of all .jpg files
$files = Get-ChildItem -LiteralPath . -Filter *.jpg
# Counter for the output file names
$counter = 1
foreach ($file in $files) {
# Determine the dimensions of the image
$imageInfo = magick identify -format "%wx%h" $file.FullName
$dimensions = $imageInfo -split 'x'
@zhiyuan-lin
zhiyuan-lin / avif-to-jpg.ps1
Last active January 1, 2024 12:48
Convert AVIF to JPG in PowerShell with ImageMagick
# Single thread
Get-ChildItem -LiteralPath . -Filter *.avif | ForEach-Object {
$jpgFileName = [System.IO.Path]::ChangeExtension($_.Name, '.jpg')
magick convert $_.FullName $jpgFileName
}
# Or parallel
$scriptBlock = {
param($inputFile)
$outputFile = [System.IO.Path]::ChangeExtension($inputFile, '.jpg')
@zhiyuan-lin
zhiyuan-lin / hello.pl
Created December 30, 2023 08:03
Modern Perl header
#!/usr/bin/env perl
use strict;
use warnings;
use 5.038;
use utf8;
use English;
use FindBin;
use lib "$FindBin::Bin/local/lib/perl5";
@zhiyuan-lin
zhiyuan-lin / hello-gtk4.pl
Last active July 25, 2023 04:24
GTK4 Hello world in Perl
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use v5.38;
use Glib::Object::Introspection;
Glib::Object::Introspection->setup(
basename => 'Gio',
version => '2.0',
package => 'Gio');
@zhiyuan-lin
zhiyuan-lin / ubuntu-systemd-cryptenroll-tpm.sh
Last active March 1, 2024 12:07
Systemd TPM Auto LUKS Unlock for Ubuntu 22.04
# See also: https://bugs.launchpad.net/ubuntu/+source/systemd/+bug/1969375
# See: https://github.com/wmcelderry/systemd_with_tpm2
# Install dependencies for systemd TPM
sudo apt install libtss2-rc0
# Check if Ubuntu recognize your TPM chip
systemd-cryptenroll --tpm2-device=list
# Check current LUKS info
sudo cryptsetup luksDump /dev/nvme0n1p3
# Enroll TPM as unlocker
sudo systemd-cryptenroll --tpm2-device=auto --tpm2-pcrs=7 /dev/nvme0n1p3
@zhiyuan-lin
zhiyuan-lin / hide-not-mounted-drives-from-ubuntu-dock.sh
Created July 24, 2023 10:04
Hide not mounted drives from Ubuntu Dock
gsettings set org.gnome.shell.extensions.dash-to-dock show-mounts-only-mounted true
@zhiyuan-lin
zhiyuan-lin / rename-files-for-image-set.ps1
Last active April 16, 2023 15:58
Rename files in image set to simple numbers in a single folder with hash based deduplication (mostly for packing to zip files).
# Specify the source directory containing the images
$srcDir = ".\src"
# Specify the destination directory to move the renamed images to
$destDir = ".\dest"
# Get all image files in the source directory and its subfolders
$imageFiles = Get-ChildItem -Path $srcDir -Recurse -Include *.jpg,*.jpeg,*.png,*.gif,*.bmp | Sort-Object @{Expression={[regex]::Match($_.Name, '(\d+)').Groups[1].Value.PadLeft(10,'0')}},FullName
# Get the number of digits needed to represent the count of files in $imageFiles
@zhiyuan-lin
zhiyuan-lin / proton-mail-enforce-pgp.sieve
Last active November 19, 2022 15:19
Proton Mail Sieve to enforce PGP encryption on all incoming emails
require ["reject", "imap4flags", "envelope", "extlists"];
if anyof (
# Domains for our addresses that we don't want to receive unencrypted emails.
envelope :domain "to" "protonmail.com",
envelope :domain "to" "proton.me",
envelope :domain "to" "pm.me",
envelope :domain "to" "protonmail.ch"
) {
if allof (
# Reject unencrypted emails.