Skip to content

Instantly share code, notes, and snippets.

View http-promise.rb
ctx = OpenSSL::SSL::SSLContext.new
ctx.set_params(verify_mode: OpenSSL::SSL::VERIFY_PEER)
raw_sock = TCPSocket.new(host, 443)
ssl_sock = OpenSSL::SSL::SSLSocket.new(raw_sock, ctx)
ssl_sock.hostname = host
ssl_sock.sync_close = true
ssl_sock.connect
View prepend_path.bash
function prepend_path () {
local path; path=$1; shift
export PATH="$(
awk -v RS=: -v "prepend=$path" '
BEGIN { a = prepend ":" }
$0 != prepend { a = a $0 ":" }
END { print(substr(a, 1, length(a)-1)) }
' <<< $PATH
)"
View one-file-cli-kit.rb
#!/usr/bin/env ruby
$:.unshift("/opt/dev/vendor/deps/cli-kit/lib")
$:.unshift("/opt/dev/vendor/deps/cli-ui/lib")
require 'cli/ui'
require 'cli/kit'
CLI::UI::StdoutRouter.enable
View darkness.rb
# 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
View flamegraph.rb
#
# Step 1:
#
# FlameGraph.generate(output: 'asdf') { ... },
#
# Step 2:
#
# git clone https://github.com/brendangregg/FlameGraph
# cd FlameGraph
# ./flamegraph.pl < ../asdf > out.svg
View 0.md

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 -> search_required;
View fs.d
#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 Oct 12, 2016
Create an Elliptic Curve keypair in ruby
View genkey.rb
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
View 0.md
  1. Build app like this
  2. Open app
  3. open omgscheme://whatever