This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Well, this ended up being easier than I'd expected to implement with coreutils. | |
Wrapped it up into a little script that sorts by count and removes anything with only 1 result (like files). | |
Should be pretty easy to also add in a `du -sh` to get sizes if one wanted. Currently it runs in <2s on that 500,000 line file on my M1 Mac. Sharing in case useful for anyone else. | |
```bash | |
#!/usr/bin/env bash | |
# treecount.sh https://gist.github.com/a7c3b48eb971f662c03e9da17ecb9ea4 | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -Eeuf -o pipefail | |
log() { | |
echo "$*" > /dev/stderr | |
} | |
err() { | |
log "$*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
##### | |
# build-plugin.sh | |
# bash 3.2-compatible convenience script to: | |
# - search by partial name for a plugin in the `QSPLUGINS` subdirectory | |
# (default `./QSPlugins`) | |
# - clean plugin directory | |
# - clean QS directory | |
# - `rm -rf /tmp/QS` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
""" | |
Use the MacOS `airport` utility to get a running average of the WiFi signal | |
strength (RSSI). | |
Python 3.8+, so works with `/usr/bin/python3` on Monterey. | |
""" | |
import os | |
import statistics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# NB: I am no bash pro, so this could be dangerous. | |
# Please read through it and make sure you double check my work. | |
# Assuming nixos image nixos-sd-image-21.05pre-git-aarch64-linux.img and sdcard at /dev/sdx | |
# Example usage: `sudo ./modify_image.sh nixos-sd-image-21.05pre-git-aarch64-linux.img /dev/sdx` | |
# NB: This will overwrite /dev/sdx! | |
set -Eeuf -o pipefail |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using terms from application "Quicksilver" | |
on get direct types | |
return {"NSStringPboardType"} | |
end get direct types | |
on get indirect types | |
return {"NSStringPboardType"} | |
end get indirect types | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/osascript -l JavaScript | |
// For use in Hammerspoon via hs.osascript.javascriptFromFile | |
// | |
// Debugging: | |
// 1. Add a `delay` to the beginning | |
// 2. Add some `console.log`s | |
// 3. Run from console as `osascript Open\ in\ MacVim.js` | |
// 4. Switch to a Finder window before the sleep is done | |
'use strict'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(test)] | |
/// My naive implementation based on | |
/// [this javascript implementation](https://gist.github.com/thebopshoobop/b9531ceb67faae0a48a9f4aadb1aed55#file-perms_recursive-js) | |
/// ([blog post here](https://medium.com/@rwillt/two-very-different-algorithms-for-generating-permutations-412e8cc0039c)) | |
/// | |
/// NB: Runs fine on stable rust, unstable only needed for the benchmarking | |
/// | |
/// For comparison: | |
/// | |
/// using [itertools](https://crates.io/crates/itertools): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/osascript -l JavaScript | |
// Apple JXA script to create and populate an album with a random sample of favorite photos | |
// Author: @n8henrie | |
// Rename from .applescript.js to .applescript (.js for GitHub syntax highlighting) | |
// https://stackoverflow.com/a/11935263/1588795 | |
function getRandomSubarray(arr, size) { | |
var shuffled = arr.slice(0), i = arr.length, temp, index; | |
while (i--) { | |
index = Math.floor((i + 1) * Math.random()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import argparse | |
import sys | |
import typing as t | |
__author__ = "Benjamin Kane" | |
__version__ = "0.1.0" | |
__doc__ = f""" | |
Pretty-print simple Bash command from one line of stdin |