Skip to content

Instantly share code, notes, and snippets.

View niedzielski's full-sized avatar
🥨

stephen niedzielski

🥨
View GitHub Profile
@niedzielski
niedzielski / docker-123.sh
Last active August 15, 2018 03:23
Create a quick Docker Ubuntu container.
docker run \
-it --rm \
-u "$(id -u "$USER"):$(id -g "$USER")" \
-v /etc/group:/etc/group:ro \
-v /etc/passwd:/etc/passwd:ro \
-v "$PWD:/vol" \
ubuntu:18.04 \
bash
@niedzielski
niedzielski / grep-no-buffer.sh
Created April 29, 2018 17:37
Grep without buffering—that is, print results immediately.
tail -f foo.bar|
grep -E --line-buffered baz
@niedzielski
niedzielski / word-wrap.sh
Last active April 29, 2018 17:38
Word-wrap text from and back to the clipboard.
xclip -sel c -o|
fold -sw 72|
xclip -sel c
@niedzielski
niedzielski / npm-up.sh
Created April 18, 2018 01:29
Upgrade all NPM packages.
# Sadly needed until npm up supports more options.
# npm install -g npm-check-updates
npm outdated
ncu -au
npm i
@niedzielski
niedzielski / cmd.sh
Last active February 10, 2018 22:41
Shell wrapper for mapping an NPM-style command to a shell command.
#!/usr/bin/env sh
set -eu ${VERBOSE:+-x}
execute() {
local cmd="$1"
shift
case "$cmd" in
start) echo a b|exec xargs -P0 -n1 "$0";;
a) sleep 1; echo a; sleep 2; exec echo a;;
@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 / marvin.js
Created January 15, 2018 21:08
Toggle Wikipedia (English) and Marvin URLs.
javascript:(_ => {
const marvin = 'marvin.wmflabs.org';
window.location.host = window.location.host === marvin ? 'en.wikipedia.org' : marvin;
})()
@niedzielski
niedzielski / mw-toggle-mobile.js
Created January 15, 2018 04:35
Toggle MediaWiki mobile (Minerva Neue) / desktop (Vector) skin.
javascript:(_ => {
const url = new URL(window.location.href);
url.searchParams.set('useformat', url.searchParams.get('useformat') !== 'mobile' ? 'mobile' : 'desktop');
window.location.href = url.toString();
})()
@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 / git-pull-dirs.sh
Created December 26, 2017 20:32
Wildcard Git pull.
for i in *; do git --work-tree="$i" --git-dir="$i/.git" pull; done