Skip to content

Instantly share code, notes, and snippets.

@yyogo
yyogo / extractObsidianSnapshots.js
Last active March 2, 2025 12:58
Extract file recovery snapshots from Obsidian
/**
* Obsidian Snapshot Exporter
* --------------------------
*
* This script helps you export snapshots (version history) from Obsidian's IndexedDB storage.
* It creates a ZIP file containing all your snapshots with proper file naming and organization.
*
* === HOW TO USE ===
*
* Step 1: Open Obsidian's Developer Tools
// Replace annoying tracking `http://t.co/...` links on Twitter ("X") with the actual target.
// Install as userscript or JSlet (prefix with `javascript:` and save as bookmark) or just run in console
document.querySelectorAll('a[href*="https://t.co"]').forEach(a => a.setAttribute('href', a.innerText.replace('…','')));
@yyogo
yyogo / style.sh
Last active August 15, 2023 08:16
easy ANSI styling in bash
#!/bin/bash
style() {
if [ $# -eq 0 ]; then
echo 'usage: style [[<color name>|[color] <index>|rgb R G B|#<rgb hex>] [fg|bg]]'
echo ' | bold | dim | italic'
echo ' | blink [fast|slow]'
echo ' | underline | invert | hide | strike | reset]]...'
return 1
fi
@yyogo
yyogo / unzoom.py
Last active November 16, 2022 09:25
iTerm 2 unzoom on switch pane script
#!/usr/bin/env python3.7
# Put this script in ~/.config/iterm/Scripts or whatever, then enable in the Scripts menu
# Map switch keys to "Invoke Script Function...": `unzoom_and_switch(direction: "above/below/left/right")`
import iterm2
async def async_turn_off_menu_option(conn: iterm2.Connection, option: str):
state = await iterm2.MainMenu.async_get_menu_item_state(conn, option)
if state.checked:
await iterm2.MainMenu.async_select_menu_item(conn, option)
@yyogo
yyogo / test_chmod_bug.sh
Last active January 30, 2022 16:15
script for testing Syncthing issue #7924
#!/bin/bash
set -e
# this script starts two ST instances, connects them, adds a shared folder,
# syncs a file, chmods it, and checks that the new permissions are synced
# within a reasonable time frame.
# Set to your local ST build
SYNCTHING=../bin/syncthing
@yyogo
yyogo / spliterr.sh
Last active January 23, 2024 10:37
Split stderr from comand to separate tmux pane
#!/bin/bash
set -m
showhelp() {
echo "Usage: $0 [-ohvrc] <command>"
echo "Pipes stderr from command to a new tmux pane."
echo " -h | -v split horizontally or vertically (default vertically)"
echo " -r send stdout to pane instead of stderr"
echo " -o send both stdout and stderr to new panes"
echo " -c close pane automatically after program terminates"
@yyogo
yyogo / keybase.md
Created January 12, 2021 16:00
keybase identity proof

Keybase proof

I hereby claim:

  • I am yyogo on github.
  • I am yyogo (https://keybase.io/yyogo) on keybase.
  • I have a public key ASBoezTXmapIvgewk-XhFriszvIc-VfNpPd7VJ9AZhiYIgo

To claim this, I am signing this object:

@yyogo
yyogo / take_while_inclusive.rs
Last active December 27, 2020 20:13
rust iterators: take_while_inclusive() - take_while including the first non-matching element
enum TakeWhileInclusive<I, P> {
Taking(I, P),
Done,
}
impl<I, P> Iterator for TakeWhileInclusive<I, P>
where
P: FnMut(&I::Item) -> bool,
I: Iterator,
@yyogo
yyogo / to_array.rs
Created November 20, 2020 19:33
rust traits for converting iterators to arrays with no extra allocations
#![feature(min_const_generics,maybe_uninit_extra)]
// VERY UNTESTED AND NOT REVIEWED
// THIS CODE USES UNSAFE RUST AND COULD LEAD TO UB
use std::mem::{self, MaybeUninit};
#[derive(Clone,Debug)]
enum ToArrayError {
TooShort(usize, usize),
@yyogo
yyogo / f_strings.py
Last active October 28, 2019 15:55
""backported"" string-interpolation for Python 2/3.5- (What do you mean, 'why'? Why not?)
import inspect
try:
unichr
except NameError:
unichr = chr
def f(s):
# find all {}'s
stack = []