Skip to content

Instantly share code, notes, and snippets.

@sam-roth
sam-roth / ansicolor.md
Last active September 26, 2018 17:23
How to Remember ANSI Escape Codes for Color

How to Remember ANSI Escape Codes for Color

ANSI escape codes set the attributes and positioning of text in a terminal. A common use of these codes is to set the text color.

The code "\033[3xm" sets the foreground color x. These values are the decimal representation of a three-bit BGR color:

blue green red binary decimal (x) color
0 0 0 000 0 black
0 0 1 001 1 red
@sam-roth
sam-roth / apaste
Last active April 9, 2018 17:58
Aligning `paste` alternative
#!/usr/bin/env python3
import argparse
import itertools
ap = argparse.ArgumentParser()
ap.add_argument('file', nargs='*', type=argparse.FileType('r'))
ap.add_argument('-p', '--pad-char', default=' ')
ap.add_argument('-d', '--delimiter', default=' ')
ap.add_argument('-c', '--pad-color', default=None)
ap.add_argument('-s', '--align-spec', default='')
@sam-roth
sam-roth / cartprod.js
Created September 22, 2016 00:07
Google Sheets Function for Cartesian Products
// Usually, you'll want to transpose the input (`CARTESIAN_PRODUCT(TRANSPOSE(X1:Y2))`)
function CARTESIAN_PRODUCT(args) {
if (args.length === 0) {
return [];
}
var first = args[0].filter(function (x) { return x; });
if (args.length === 1) {
return first;