Skip to content

Instantly share code, notes, and snippets.

View wknapik's full-sized avatar

Wojciech Knapik wknapik

View GitHub Profile
@wknapik
wknapik / README.md
Last active December 28, 2022 00:17
Users who collaborate on the same GitHub repo can write on each other's timeline

Description

Users who collaborate on the same GitHub repo can write on each other's timeline.

This includes github-spray-type writing to inject messages on the user's "pixelated" activity overview for any period.

This is effective:

  • even when writes to the repo happened before the victim was a collaborator
  • even when the commits predate the user joining GitHub
  • when commits are pushed to the repo's default branch
  • even when the default branch history is rewritten at any point to include commits attributed to the victim
@wknapik
wknapik / README.md
Created March 1, 2022 14:18
Enable packet filter on macOS

Run

launchctl load -w /Library/LaunchDaemons/local.pfctl.plist

Explanation

macOS 10.11 introduced System Integrity Protection, which makes /System (and consequently /System/Library/LaunchDaemons/com.apple.pfctl.plist) immutable, even to root. This means the plist can't be modified to enable packet filter (by adding the -E switch to pfctl). The solution is to create a custom launchd daemon, which only calls pfctl -E (calling pfctl -E -f /etc/pf.conf conflicts with com.apple.pfctl.plist, which may cause failure and pf not being enabled).

@wknapik
wknapik / repolink.sh
Last active December 3, 2021 16:17
Print link(s) to file(s) in repo(s) with optional line numbers (add to your shell profile; works with GitHub and GitLab)
@wknapik
wknapik / Jenkinsfile
Last active March 26, 2020 00:07
Stagger timed declarative multibranch pipeline executions in Jenkins
// This generates a consistent, per-branch, not-really-random,
// execution time between 20:00 and 5:59 every day.
branchNum = BRANCH_NAME.inject(0) { acc, c -> acc + ((c as char) as int) }
cronHour = [20, 21, 22, 23, 0, 1, 2, 3, 4, 5][branchNum % 10]
cronMinute = branchNum % 60
cronParams = "${cronMinute} ${cronHour} * * *"
// ...
@wknapik
wknapik / amsterdam-restaurants.md
Last active April 15, 2024 22:15
Restaurant recommendations, Amsterdam
@wknapik
wknapik / .zshrc
Last active December 28, 2022 13:55
[tmux/zsh] Print matching lines of output (stdout and stderr) from the last command run in an interactive shell, without rerunning the command
# This function greps everything between the last two prompts in the current tmux pane.
# Arguments are passed to `grep -i', so any valid `grep' options can be supplied.
# Requirements: coreutils, grep, sed, tmux, zsh.
just() {
local -r max=10000 psone="$(print -P "$PS1"|sed "s,\x1B\[[0-9;]*[a-zA-Z],,g")"
local inside=0;
tmux capture-pane -pS-"$max" -E"$max"|tac|\
while IFS= read -r line; do
case "$inside,$line" in
@wknapik
wknapik / README
Created June 21, 2019 09:41
Verify whether a hash generated with htpasswd matches a password
% htpasswd -nb foo bar >passwd
% ./chkpasswd.exp passwd foo bar
% echo "$?"
# 0 = match, 1 = no match
@wknapik
wknapik / fuzzy_run
Last active January 24, 2020 16:26
An application launcher with fuzzy search via fzy (fzf would also work)
#!/usr/bin/env bash
# Requirements: bash, coreutils, fzy, xdotool, xterm.
#
# Position and decorations can be set in i3 with something like:
# for_window [class="^FuzzyRun"] floating enable border none move position center
#
# Either `-fullscreen', or `-geometry' should be used. With both in place,
# `-fullscreen' takes precedence.
@wknapik
wknapik / retry.mk
Last active March 15, 2019 16:32
Retry an action in a make recipe if it fails (up to a specified number of times)
# Example usage: $(call retry,3,something that might fail)
retry = for ((i=0; i < $1; ++i)); do ( $2 ) && exit 0; sleep 3; done; false
@wknapik
wknapik / find.mk
Last active July 24, 2019 20:50
A declarative, recursive find implementation in pure make.
# Example usage: $(call find,. /foo,*.bar *.baz)
find = $(foreach path,$1,$(foreach pattern,$2,$(wildcard $(path)/$(pattern)) $(foreach dir,$(wildcard $(path)/*/),$(call find,$(dir:%/=%),$(pattern)))))