Skip to content

Instantly share code, notes, and snippets.

@stilist
stilist / build-merge-branch.sh
Last active February 10, 2022 18:42
Script for creating a branch that combines multiple other branches
#!/usr/bin/env bash
set -euo pipefail
destination_branch_name="${1:-merge-pile}"
branch_list="${2:-branch-list.txt}"
if [[ ! -f "${branch_list}" ]] ; then
echo "ERROR: Branch list file (${branch_list}) doesn't exist" >&2
exit 1
@stilist
stilist / log-volume-by-date.sh
Created June 30, 2020 21:14
Count date-like strings in files in /var/log
#!/bin/bash
set -euo pipefail
log_directory="${1:-/var/log}"
year="20[[:digit:]]{2}"
day="[[:digit:]]{2}"
month_num="[[:digit:]]{1,2}"
month_alpha="[[:upper:]][[:lower:]]{2}"
@stilist
stilist / README.md
Last active April 24, 2020 04:47
Accurately count the number of lines from PS1, PS2, and the command the user entered.
@stilist
stilist / README.md
Created April 21, 2020 16:49
Correctly handle an arbitrary number of lines in PS0 rewriting

This is a small revision to the move_cursor_to_start_of_ps1 function described in ‘When did I run that command?’. The original relies on a specific number of lines in PS1; this works with an arbitrary number of lines.

The original code works correctly for the PS1 provided in the article, but my PS1 has an additional line, and I wanted to avoid using a magic number in case I change my PS1 in the future.

@stilist
stilist / netflix-ratings-to-json.js
Created February 8, 2019 00:32
Export Netflix ratings as JSON
// You can run this from your browser's JavaScript console.
console.log(JSON.stringify(Array.from(document.querySelectorAll('.retableRow')).map(node => {
let rating
const stars = node.querySelectorAll('.rating .personal')
if (stars.length) {
rating = stars.length
} else {
rating = node.querySelector('.rated-up') ? 'up' : 'down'
}
@stilist
stilist / dribbble-likes.js
Last active December 23, 2018 03:02
Scrape Dribbble likes into JSON that matches the real API's structure (but with some missing data)
// Copyright 2018 Jordan Cole
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
@stilist
stilist / svn_log_to_json.rb
Created March 5, 2018 03:48
Extract Subversion log data
require 'fileutils'
require 'json'
# LOG = ARGF.read.freeze
LOG = File.read('log.txt')
COMMIT_PATTERN = /
\A
r(?<revision>\d+)
\s\|\s
@stilist
stilist / LICENSE
Created August 7, 2017 04:34
Extract protocol-buffer–encoded location data from the Photos.app database
MIT License
Copyright (c) 2017-present Jordan Cole
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
@stilist
stilist / LICENSE
Created February 3, 2017 01:06
Uninstall all non-default Ruby gems
Copyright (c) 2017 Jordan Cole
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR O
@stilist
stilist / monitoring.md
Last active October 27, 2020 05:36
Notes on site reliability

Monitoring

Alerting

  • base rate fallacy: given 1% false positive, 1% false negative, and 99.9% uptime: 9.1% chance positive predictive value (true positive)
  • sensitivity (% true positives) vs specificity (% not false positive)
  • ‘Alert liberally; page judiciously. Page on symptoms, rather than causes.’
  • ‘An alert should communicate something specific about your systems in plain language: “Two Cassandra nodes are down” or “90% of all web requests are taking more than 0.5s to process and respond.”’
  • ‘Not all alerts carry the same degree of urgency.’
  • ‘Many alerts will not be associated with a service problem, so a human may never even need to be aware of them. […] should generate a low-urgency alert that is recorded in your monitoring system for future reference or investigation but does not interrupt anyone’s work.’