Skip to content

Instantly share code, notes, and snippets.

@roblogic
roblogic / zshexpn-explained.md
Created November 19, 2020 01:49
Regular Expressions in Zsh

The following is taken from a brilliant answer on unix.se. Posting it here for personal reference. The question was:

${var//pattern/replacement} is using zsh wildcard patterns for pattern, the same ones as used for filename generation aka globbing which are a superset of the sh wildcard patterns. The syntax is also affected by the kshglob and extendedglob options. The ${var//pattern/replacement} comes from the Korn shell initially.

I'd recommend enabling extendedglob (set -o extendedglob in your ~/.zshrc) which gives you the most features (more so than standard EREs) at the expense of some backward incompatibility in some corner cases.

You'll find it documented at info zsh 'filename generation'.

@ClearlyKyle
ClearlyKyle / STR_to_Sentences.py
Created October 8, 2020 21:11
Using pysrt to convert a SRT file to a list of sentences.
import pysrt
import os
output_folder_name = "txt"
try:
os.mkdir("./{}".format(output_folder_name))
except OSError:
pass # already exists
@glowinthedark
glowinthedark / srt_subtitles_append_pinyin.py
Last active February 6, 2023 02:25
Add pinyin subtitles to chinese mandarin SRT subtitles; optionally append traditional (-t) to existing simplified; or append simplified (-s) to existing traditional
#!/usr/bin/env python3
# also see https://github.com/tkarabela/pysubs2
# DEPENDENCIES:
# pip install -U srt opencc pypinyin hanzidentifier
# URL: https://gist.github.com/glowinthedark/83daa9531dd8c4cc3963e55c1a4f3b1c
# Add pinyin subtitles to chinese mandarin SRT subtitles;
# optionally also add traditional (-t) or existing simplified;
@varenc
varenc / capstoggle.sh
Created August 19, 2020 03:53
Toggle Caps Lock light on macOS Catalina from a shell scripts/terminal
#!/usr/bin/osascript -l JavaScript
# Usage: capstoggle.sh [1 or 0, defaulting to 0]
# Pass in "1" to turn caps lock on. By default it turns caps lock off (0)
#
# Make this an executable shell script by running `chmod +x capstoggle.sh`
# Then `./capstoggle.sh 1` to turn caps lock on, and hence toggle the caps lock keyboard light!
# You can make your caps lock light flash 5 times by running this
# for i in {0..5}; do ./capstoggle.sh 1; ./capstoggle.sh 0; done
ObjC.import("IOKit");
var _cf = _cf || [],
bmak = bmak || {
ver: 1.54,
ke_cnt_lmt: 150,
mme_cnt_lmt: 100,
mduce_cnt_lmt: 75,
pme_cnt_lmt: 25,
pduce_cnt_lmt: 25,
tme_cnt_lmt: 25,
tduce_cnt_lmt: 25,
#!/bin/bash
# We can find the index of the item in the array by extracting the key, finding the lines with
# 'string' in them, and then finding the search string.
cd /System/Volumes/Data/.Spotlight-V100
search_string=$1
let index="`plutil -extract Exclusions xml1 -o - VolumeConfiguration.plist | grep string | grep -wn "${search_string}" | cut -d ':' -f 1` - 1"
!/bin/bash
launchctl stop com.apple.metadata.mds && launchctl start com.apple.metadata.mds
vers=$( sw_vers | grep BuildVersion | awk '{print substr($2,0,2)}' )
sdir="/.Spotlight-V100"
if [[ "${vers}" > "18" ]]; then
sdir="/System/Volumes/Data${sdir}"
@klausondrag
klausondrag / README.md
Last active May 9, 2020 23:52
Pinyin support for Language Learning with Netflix Extension
@Matt-Jensen
Matt-Jensen / Firebase Local Storage IndexedDb Dump.js
Created February 17, 2020 17:04
Access your Firebase Auth Token by dumping your IndexedDB session
(() => {
const asyncForEach = (array, callback, done) => {
const runAndWait = i => {
if (i === array.length) return done();
return callback(array[i], () => runAndWait(i + 1));
};
return runAndWait(0);
};
const dump = {};
@dnicolson
dnicolson / MediaRemoteEvents.m
Created December 24, 2019 18:16
Use the MediaRemote private framework to get and set the playing state of the Touch Bar based on media change events
// clang -x objective-c -framework Foundation -framework MediaRemote -F /System/Library/PrivateFrameworks TouchBarMediaKeys.m -o TouchBarMediaKeys
// ./TouchBarMediaKeys
#import <Foundation/Foundation.h>
#import <MediaPlayer/MediaPlayer.h>
enum {
kMRPlaybackStateUnknown = 0,
kMRPlaybackStatePlaying,
kMRPlaybackStatePaused,