Skip to content

Instantly share code, notes, and snippets.

View bk2204's full-sized avatar

brian m. carlson bk2204

View GitHub Profile
import urwid
def setup_cells():
layout = [0, None, None, 1, 2, 3, None, 4, None, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, None, 15, 16, None, 17, None]
cells = []
for item in layout:
if item is None:
pile = urwid.Pile([])
else:
def main
something_that_might_explode_violently
rescue YourError => error
case
when error.status == 404
search
when error.on_fire
FireDepartment.call(type: :emergency)
when error.status_code == 500
shame caller(1)
@bk2204
bk2204 / .gitignore
Last active August 29, 2015 14:08
Comcast
*.html

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 / 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.

@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 / 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 () {
alert(1);
#!/usr/bin/perl
use strict;
use warnings;
use Crypt::Passwd::XS;
use MIME::Base64;
my $password = <STDIN>;
chomp $password;
@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")'