Skip to content

Instantly share code, notes, and snippets.

View bk2204's full-sized avatar

brian m. carlson bk2204

View GitHub Profile
@bk2204
bk2204 / list-unsubscribe
Created February 2, 2024 21:13
A script to unsubscribe users from mailing lists
#!/bin/sh
# Pipe an email to standard input and, if it supports RFC 8058 one-click unsubscribe, you will be automatically unsubscribed.
formail -c -x List-Unsubscribe | perl -pe 's!<https?://([^>]+)>!$1!' | \
xargs curl -X POST -H'Content-Type: application/x-www-form-urlencoded' -dList-Unsubscribe=One-Click
#!/bin/sh
#
# Run this script as "ssh-key-algo git@github.com". You can also specify a
# different location if you'd like to run this against an GitHub Enterprise
# Server instance.
DIR=$(mktemp -d -t tmp.XXXXXXX)
trap 'rm -fr "$DIR"' EXIT
@bk2204
bk2204 / git-format-text
Created January 13, 2020 15:36
A script to flow a commit message for use in the GitHub UI
#!/bin/sh
REV="${1:-HEAD}"
git show --no-patch --format=tformat:"%b" -1 "$REV" | \
ruby -e 'puts $stdin.read.split("\n\n").map { |c| c.gsub("\n", " ") }.join("\n\n")'
#!/usr/bin/perl
use strict;
use warnings;
use Crypt::Passwd::XS;
use MIME::Base64;
my $password = <STDIN>;
chomp $password;
alert(1);
@bk2204
bk2204 / local.sh
Created October 31, 2016 23:45
Reasonably portable technique for local variables in shell scripts
#!/bin/sh -e
# This shell script demonstrates how to use the local keyword to create
# dynamically-scoped variables in various shells. Notably, this technique works
# with AT&T ksh, as well as bash, dash, mksh, pdksh, zsh, busybox sh, and other
# Debian Policy-compliant sh implementations.
# Simple Perl-compatible testing framework. Produces TAP output.
COUNT=0
is () {
@bk2204
bk2204 / mm-sorter.rb
Last active October 26, 2016 01:59
An algorithm for eating M&Ms in pairs
class MMSorter
def initialize(preference)
@preference = preference
@reverse = preference.each_with_index.to_h
end
def pairs(candy)
# Find the candies which aren't part of a pair and sort them in preference
# order.
leftovers = candy.select { |_c, cnt| cnt.odd? }.map { |p| p[0] }
@bk2204
bk2204 / README.adoc
Created June 10, 2016 22:38
Transcript of editing session using ex
What is this?

A transcript of an editing session using ex.

ex?

If you’ve used Vim or vi, any time you type a command starting with “:”, you’re writing an ex command. ex is the command-line only editor, and vi was originally written to provide better editing on non-dumb terminals.

Why use ex?

This is an exercise in what editing used to be like before the advent of vi.

Keybase proof

I hereby claim:

  • I am bk2204 on github.
  • I am bk2204 (https://keybase.io/bk2204) on keybase.
  • I have a public key whose fingerprint is 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187

To claim this, I am signing this object:

@bk2204
bk2204 / .gitignore
Last active August 29, 2015 14:08
Comcast
*.html