Skip to content

Instantly share code, notes, and snippets.

View glowinthedark's full-sized avatar

glowinthedark glowinthedark

  • URLError: <urlopen error [Errno 8] nodename nor servname provided, or not known>
  • HTTPError: HTTP Error 403: Forbidden
View GitHub Profile
-- modified version from https://bear.app/faq/Import%20&%20export/Migrate%20from%20Apple%20Notes/
-- fixed to write text in UTF8 encoding
set exportFolder to (choose folder) as string
-- Simple text replacing
on replaceText(find, replace, subject)
set prevTIDs to text item delimiters of AppleScript
set text item delimiters of AppleScript to find
set subject to text items of subject
@glowinthedark
glowinthedark / main.dart
Last active April 18, 2023 17:41
dart time duratin
void main() {
final start = DateTime.now();
final end = start.add(const Duration(days: 0, hours: 30, minutes: 1, seconds: 9));
print(start);
print(end);
print(getDurationText(start, end));
}
String getDurationText(DateTime start, DateTime end) {
Duration delta = end.difference(start);
@glowinthedark
glowinthedark / macos-set-audio-volume-command-line.sh
Created March 27, 2023 17:04
Set MacOS audio volume from command line: pass number from 0 to 100
#!/usr/bin/osascript
on run argv
log "before: " & output volume of (get volume settings)
set volume output volume argv as text
log "after: " & output volume of (get volume settings)
end run
@glowinthedark
glowinthedark / python_webserver_range_support_multithreaded.py
Last active March 13, 2023 19:49
Simplest python web server with range support and multithreading
#!/usr/bin/env python3
# spec: simplest python web server with range support and multithreading that takes root path,
# port and bind address as command line arguments; by default uses the current dir as webroot,
# port 8000 and bind address of 0.0.0.0
import argparse
import functools
import os
@glowinthedark
glowinthedark / build-mpv_silicon.sh
Created February 14, 2023 14:48 — forked from dbrookman/build-mpv_silicon.sh
How to build mpv & mpv.app on an Apple silicon (M1 / M2) Mac
#!/usr/bin/env bash
# builds mpv & mpv.app on Apple silicon (M1 / M2) Macs
# run this script from the root directory of the mpv repo
# if anything fails, gtfo
set -ex
meson setup build
meson compile -C build
@glowinthedark
glowinthedark / mutagen-embed-mp3-uslt-subtitles.py
Created January 28, 2023 14:31
Embed lyrics into MP3 files using mutagen (USLT tag), optionally set other ID3 tags
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# mirorred from https://code.activestate.com/recipes/577138-embed-lyrics-into-mp3-files-using-mutagen-uslt-tag/
import os
import sys
import codecs
from mutagen.mp3 import MP3
from mutagen.id3 import ID3NoHeaderError
from mutagen.id3 import ID3, TIT2, TALB, TPE1, TPE2, COMM, USLT, TCOM, TCON, TDRC
@glowinthedark
glowinthedark / ffmpeg-embed-hard-srt-subtitles-resize-540p.sh
Last active January 2, 2023 08:56
FFMPEG: Embed hard srt subtitles into a video; ❗️❗️ffmpeg *MUST* be compiled with `--enable-libfreetype --enable-libfontconfig`
#!/usr/bin/env bash
if [ "$#" -lt 2 ]; then
printf "Usage:\n $(basename $0) MyVideo.mp4 MySubtitles.srt\n"
else
ffmpeg -i "$1" -vf "subtitles=${2}, scale=540:-1" -acodec copy "${1%.mp4}-sub-540p.mp4"
fi
# FFMPEG custom build options
@glowinthedark
glowinthedark / macos-mount-ext4-partitions.sh
Created December 22, 2022 21:14
Mount Ext4/ext3/ext2 partitions on MacOS
#!/usr/bin/env bash
for device in $(diskutil list | awk '/Linux/ {print $NF}') ; do
read -p ">>> Found linux device: $device. Mount? y/n <<< " answer
if [[ "$answer" =~ [yY] ]]; then
mount_point="$HOME/mnt/$device"
mkdir -p $mount_point
@glowinthedark
glowinthedark / srt-convert-simplified-traditional-chinese.py
Last active February 7, 2023 18:22
Convert SRT subtitles between Chinese simplified and traditional
#!/usr/bin/env python3
import argparse
import sys
from pathlib import Path
import srt
from opencc import OpenCC
simp2trad = OpenCC('s2twp')
from fairseq.models.transformer import TransformerModel
zh2en = TransformerModel.from_pretrained(
'/path/to/checkpoints',
checkpoint_file='checkpoint_best.pt',
data_name_or_path='data-bin/wmt17_zh_en_full',
bpe='subword_nmt',
bpe_codes='data-bin/wmt17_zh_en_full/zh.code'
)
zh2en.translate('你好 世界')