Skip to content

Instantly share code, notes, and snippets.

View niedzielski's full-sized avatar
🥨

stephen niedzielski

🥨
View GitHub Profile
@niedzielski
niedzielski / reverse.d.ts
Last active December 27, 2023 16:22
Reverse a type's keys and values in TypeScript.
type Reverse<T> = {[V in T[keyof T] & keyof T]: keyof T}
@niedzielski
niedzielski / pretty-print-json.js
Last active July 3, 2023 03:27
Pretty print JSON bookmarklet.
javascript:(_ => {
const pre = document.querySelector('pre');
pre.innerHTML = JSON.stringify(JSON.parse(pre.innerHTML), null, 2);
})()
@niedzielski
niedzielski / sos.sh
Last active June 23, 2020 14:16
Assemble Scrum of Scrums Notes
curl \
-sG \
-d o=TRACKING_IDS \
--data-urlencode q='(owner:niedzielski OR owner:sniedzielski OR owner:pmiazga OR owner:jdrewniak OR owner:jdlrobson OR owner:nray OR owner:phuedx OR owner:volkere) -age:1week -is:wip -message:wip' \
https://gerrit.wikimedia.org/r/changes/|
node -e '
JSON.parse(require("fs").readFileSync(0).toString("utf-8").substring(5))
.reduce((sum, val) => ([...sum, ...val.tracking_ids]), [])
.filter(({system}) => system === "Phab")
.map(({id}) => id)
@niedzielski
niedzielski / pixelate.js
Last active June 17, 2020 12:40
Pixelate images bookmarklet; disables zoomed image smoothing.
javascript:(_ => {
const sheet = document.createElement('style');
sheet.innerHTML = 'img { image-rendering: pixelated; }';
document.head.appendChild(sheet);
for(let i = 0; i < frames.length; ++i) {
frames[i].document.head.appendChild(sheet);
}
})()
@niedzielski
niedzielski / for-each.bash
Last active September 9, 2019 16:04
Some different Bash looping options.
find -not \( \( -name node_modules -o -name .git -o -name dist \) -prune \) -type f -name \*.css|
# a
while IFS= read -r file; do git mv "$file" "${file%.css}.less"; done
# b
xargs -rd\\n -i sh -c 'git mv {} $(dirname {})/$(basename {} .css).less'
time while IFS= read -ru9 -d $'\n' line; do
echo -n "$line"
@niedzielski
niedzielski / find-excluding-subdirectory.sh
Last active April 27, 2019 16:09
Find excluding one or more subdirectories.
find -not \( -path ./DIRECTORY -prune \)
find -not \( \( -name DIRECTORY0 -o -name DIRECTORY1 \) -prune \)
# see also: https://stackoverflow.com/q/10747039/970346
@niedzielski
niedzielski / format-json.sh
Created January 26, 2019 01:33
Pretty-print a JSON string from stdin.
node -pe 'JSON.stringify(JSON.parse(require("fs").readFileSync(0)), null, 2)'
@niedzielski
niedzielski / ripgrep.sh
Created January 26, 2019 01:31
ripgrep example.
rg -g\!/resources/dist/ -g\!/i18n/ -g\!/tests/ -g\!/doc/ -t js foo
@niedzielski
niedzielski / find-not-owner-or-not-group.sh
Last active January 26, 2019 00:14
Find and change files not in the current user's group or ownership
# Find all files not in the current user ownership AND group.
sudo find "$DIR" -not \( -uid $(id -u) -gid $(id -g) \)
# Recursively change owner and group to current user.
sudo chown -R $(id -nu):$(id -ng) "$DIR"
@niedzielski
niedzielski / shred.sh
Created January 20, 2019 21:28
Obliterate disk contents.
sudo sg_map -i
df -h /dev/sdX*
time sudo shred -v /dev/sdX