Skip to content

Instantly share code, notes, and snippets.

View jswetzen's full-sized avatar

Johan Swetzén jswetzen

  • Göteborg, Sweden
View GitHub Profile
@jswetzen
jswetzen / srtsync.py
Created March 21, 2023 14:42
Subtitle (SRT) sync tool in Python
# Sync a subtitle file, both for offset and drift
#
# Find the time for the first and last spoken line, both in the audio and subtitles
# Fill in the times, in/out file names and encoding
# Run!
from datetime import timedelta
import srt
from srt import Subtitle
@jswetzen
jswetzen / joplin-icloud-gmail-import.py
Created February 9, 2022 13:54
Python script for importing iCloud notes into Joplin via Gmail
# Import Data from iCloud Notes to Joplin
# Developed and tested on Ubuntu only
# 1. Add a gmail connection to Notes
# 2. Copy all your note folders into that gmail space in Notes
# 3. Wait for all the notes to sync to your mailbox
# 4. Download all emails tagged with Notes with takeout.google.com
# 5. For each of the resulting mbox files, run this script
# 6. Import the markdown folder (with front matter) into Joplin
# Requires
@jswetzen
jswetzen / follow_binary_sensor.yaml
Last active January 3, 2022 11:33
Home assistant switch based on binary sensor
blueprint:
name: Control with sensor
description: 'Set the state based on a binary sensor'
domain: automation
input:
controller:
name: First entity
selector:
entity:
controllee:
@jswetzen
jswetzen / doors.py
Created April 9, 2016 10:37
Simulate the classical game show problem of choosing one of three doors. One of the wrong doors are exposed, so what do you do? Stay, switch or randomly choose which to do? Try this a million times to see what the statistics say.
#!/usr/bin/env python3
import random
def remove_door(doors, win, pick1):
doors.remove(win)
try:
doors.remove(pick1)
doors = [win, pick1]
except ValueError: