Skip to content

Instantly share code, notes, and snippets.

View ClementTsang's full-sized avatar
🙃
Busy with IRL things so I might take a bit of time to respond!

Clement Tsang ClementTsang

🙃
Busy with IRL things so I might take a bit of time to respond!
View GitHub Profile
@ClementTsang
ClementTsang / normalize_youtube_title_text.user.js
Created January 20, 2024 23:37
Greasemonkey Script: Normalize YouTube Title Text
// ==UserScript==
// @name Normalize YouTube Title Text
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Normalizes the annoying fancy text that some video titles use.
// @author You
// @match https://www.youtube.com/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=youtube.com
// @run-at document-idle
// @grant none
@ClementTsang
ClementTsang / gtag-cscope-reeee.txt
Created December 9, 2023 08:22
"Gtags-cscope: this vim does not include cscope support"
If you've ever encountered this warning in neovim, uninstall the `global` package.
@ClementTsang
ClementTsang / truncate_str_bench.rs
Last active November 27, 2023 04:07
Speeding up string truncation even more with ASCII fast paths and combining iterative ASCII detection and string building together. PR: https://github.com/ClementTsang/bottom/pull/1334
//! ```cargo
//! [dependencies]
//! unicode-segmentation = "1.10.1"
//! unicode-width = "0.1.11"
//!
//! [dev-dependencies]
//! criterion = "0.5"
//!
//! [[bench]]
//! name = "truncate_str_bench"
@ClementTsang
ClementTsang / truncate_str_bench.rs
Last active November 24, 2023 04:20
A simple fast path for truncate_str code when the entire string is ASCII. Related PR: https://github.com/ClementTsang/bottom/pull/1330
//! ```cargo
//! [dependencies]
//! unicode-segmentation = "1.10.1"
//! unicode-width = "0.1.11"
//!
//! [dev-dependencies]
//! criterion = "0.5"
//!
//! [[bench]]
//! name = "truncate_str_bench"
@ClementTsang
ClementTsang / solaar.py
Created May 3, 2022 23:22
Obtains battery data from solaar (requires solaar installed)
#!/bin/python3
import subprocess
import sys
nicknames = dict(tuple(n.split("=")) for n in sys.argv[1:])
call = subprocess.run(["solaar", "show"], stdout=subprocess.PIPE)
out = call.stdout
devices = [o for o in out.split(b"\n\n")]
@ClementTsang
ClementTsang / bt_battery.py
Last active May 3, 2022 23:21
Ugly script for polybar to get bluetooth battery and display to stdout; requires FA
#!/bin/python3
import subprocess
import sys
nicknames = dict(tuple(n.split("=")) for n in sys.argv[1:])
call = subprocess.run(["upower", "-d"], stdout=subprocess.PIPE)
out = call.stdout
devices = [o for o in out.split(b"\n\n")]
@ClementTsang
ClementTsang / download_script.py
Created April 10, 2022 22:20
A simple parallel download script, taking in a file that consists of multiple URLs, separated by newlines. The URLs can have quotes or commas as well, those are stripped.
#!/bin/python3
import requests
from concurrent.futures import ThreadPoolExecutor, as_completed
import urllib.parse
import sys
def download(url):
stripped_url = str.strip(url).removeprefix('"').removesuffix('",')
file_name = urllib.parse.unquote_plus(stripped_url.split("/")[-1].split("?")[0])
@ClementTsang
ClementTsang / youtube_comment_hider.js
Created May 20, 2020 22:34
Hides comments on YouTube. Not the greatest thing ever, but it works. Run via https://addons.mozilla.org/en-US/firefox/addon/enhancer-for-youtube/.
let parent_node = document.getElementById('primary-inner');
const CONFIG = { attributes: true, childList: true, subtree: true };
const OBSERVER = new MutationObserver(() => {
let target_node = document.getElementById('comments');
if (target_node != null) {
target_node.hidden = true;
// console.log("Hiding comments...");
OBSERVER.disconnect();
// console.log("Disconnected. Job done.");
@ClementTsang
ClementTsang / latex_to_md.sh
Created May 8, 2019 04:06
Convert Latex files to Markdown
#!/bin/bash
find . -name "*.tex" | while read file_name; do pandoc "${file_name}" -f latex+lhs -o "${file_name%.*}.md"; done