Skip to content

Instantly share code, notes, and snippets.

# detects whether a terminal is dark-on-light or light-on-dark.
# Only purposefully supports Terminal.app and iTerm, but a bunch of things use
# $COLORFGBG.
module BackgroundDetector
DARK = :dark
LIGHT = :light
def terminal_app
theme = `/usr/libexec/PlistBuddy -c "Print :'Default Window Settings'" ~/Library/Preferences/com.apple.Terminal.plist`.chomp
blob = `/usr/libexec/PlistBuddy -c "Print :'Window Settings':'#{theme}':BackgroundColor" ~/Library/Preferences/com.apple.Terminal.plist`.chomp
@burke
burke / 0.md
Last active April 27, 2017 18:01

#
# Step 1:
#
# FlameGraph.generate(output: 'asdf') { ... },
#
# Step 2:
#
# git clone https://github.com/brendangregg/FlameGraph
# cd FlameGraph
# ./flamegraph.pl < ../asdf > out.svg
@burke
burke / 0.md
Last active March 30, 2017 01:40

CSS-ish styling for graphviz DOT

digraph {
  rb_find_file_safe [class="emph,strong"];
  search_required [class=emph];
  open_load_file [class=emph];
  rb_find_file -> rb_find_file_safe;
  search_required -> rb_find_file_safe;
 rb_require_internal -&gt; search_required;
@burke
burke / fs.d
Last active March 24, 2017 18:47
#pragma D option dynvarsize=32M
#pragma D option switchrate=1msec
#pragma D option bufsize=25m
#pragma D option quiet
syscall::open:entry /pid == $target/ { self->path = arg0; }
syscall::shm_open:entry /pid == $target/ { self->path = arg0; }
syscall::open_extended:entry /pid == $target/ { self->path = arg0; }
syscall::accept:entry /pid == $target/ { self->fd = arg0; }
syscall::accept_nocancel:entry /pid == $target/ { self->fd = arg0; }
@burke
burke / genkey.rb
Created October 12, 2016 14:34
Create an Elliptic Curve keypair in ruby
require 'openssl'
k = OpenSSL::PKey::EC.new('secp384r1').generate_key
p = OpenSSL::PKey::EC.new(k.public_key.group)
p.public_key = k.public_key
puts k.to_pem, p.to_pem
@burke
burke / 0.md
Last active June 21, 2016 20:37
  1. Build app like this
  2. Open app
  3. open omgscheme://whatever
-- compiled from https://github.com/janko-m/vim-test/tree/master/bin
on run argv
set command to argv
-- without doing this as a var, it will launch iterm2
set iterm to "iTerm2"
if application iterm is running then
tell application "iTerm"
set _window to (current window)
if _window is equal to missing value then
@burke
burke / APKBUILD
Created October 28, 2015 05:29
Alpine Linux APKBUILD for runc
# Contributor: Burke Libbey <burke@libbey.me>
# Maintainer:
pkgname=runc
pkgver=0.0.4
pkgrel=0
_gitcommit=b0fd9fb7
pkgdesc="CLI tool for spawning and running containers according to the OCF specification"
url="http://runc.io/"
arch="x86_64"
license="ASL 2.0"

Lots of these commands have two versions: one with and one without a :. The colon modifies operators to treat a declared-but-empty variable as nonexistent.

More detailed docs and examples for all of these are at: http://www.tldp.org/LDP/abs/html/parameter-substitution.html.

bash ruby
${a} a
${a-b} `a
${a:-b} `(a == "" ? nil : a)
${a=b} `a