Skip to content

Instantly share code, notes, and snippets.

View aasmith's full-sized avatar

Andrew A Smith aasmith

View GitHub Profile
@aasmith
aasmith / nested-json.sh
Created September 19, 2017 21:23
How to decode nested json with jq
# Typical use-case is decoding an AWS STS message. The DecodedMessage key contains escaped JSON.
jq '.DecodedMessage | fromjson | .' message.json
@aasmith
aasmith / ec2-private-ip.sh
Last active May 20, 2017 16:04
Get the private IP address of an EC2 instance
aws ec2 describe-instances --instance-ids <id> --output text --query 'Reservations[*].Instances[*].PrivateIpAddress'
@aasmith
aasmith / .curlrc
Created May 10, 2017 05:37
.curlrc
# print timings after each call. Use curl -q to suppress this file.
write-out = "%{http_code} ns:%{time_namelookup} conn:%{time_connect} appconn:%{time_appconnect} prexfr:%{time_pretransfer} rdr:%{time_redirect} ttfb:%{time_starttransfer} TOTAL:%{time_total}\n"
@aasmith
aasmith / streaming.rb
Last active May 25, 2016 05:48
Rails Streaming: chunked + gzip/deflate
# Adapted from http://stackoverflow.com/questions/7986150/http-streaming-in-rails-not-working-when-using-rackdeflater
#
# * Place this file in config/initializers/streaming.rb.
# * Place 'config.middleware.use Rack::Deflater' in application.rb.
# * Ensure you have a controller action that uses 'render stream: true'
# * This should work in rails 3.1+, 4.x, and 5.x. See the original class:
# https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/streaming.rb
module GzipStreaming
def _process_options(options)
@aasmith
aasmith / gist:1f50c4354d2cc7a16470
Last active October 18, 2015 19:28 — forked from pvalkone/gist:9292589
How to set up IPMI Serial-Over-LAN (SOL) on a ASRock C2550D4I motherboard running FreeNAS
BIOS Setup
----------
1) Boot into the BIOS setup utility (press F2 or DEL) and open Advanced > Serial Port Console Redirection.
2) Disable COM1 and EMS console redirection and enable SOL redirection.
3) Set the SOL console redirection settings as follows:
Aptio Setup Utility - Copyright (C) 2012 American Megatrends, Inc.
Advanced
/----------------------------------------------------+-------------------------\
@aasmith
aasmith / Big Tiles.markdown
Last active August 29, 2015 14:25
Big Tiles
@aasmith
aasmith / cpu.rb
Created March 1, 2015 18:46
Print CPU usage in ruby
require "vmstat" # gem install vmstat
CPU_DETAIL = false # set to true if you want to see details for each cpu.
CPU_USAGE = "CPU %s: %5.1f%% sys %5.1f%% user %5.1f%% idle"
def delta prev, curr
all = prev.cpus.zip(curr.cpus).map do |prev_cpu, curr_cpu|
@aasmith
aasmith / clock.rb
Created January 1, 2015 09:05
Clock!
loop { d = `date`.chomp; print d; sleep 0.05; print "\b"*d.size }
irb(main):002:0> Dir.glob("../x/*").shuffle.each { |x| `mv #{x} .`; puts "Added #{x}"; `time foo`; }
Added ../x/sexp_processor-4.4.1.gemspec
0.10 real 0.08 user 0.01 sys
Added ../x/diff-lcs-1.2.4.gemspec
0.10 real 0.08 user 0.01 sys
Added ../x/wirble-0.1.3.gemspec
0.10 real 0.08 user 0.01 sys
Added ../x/byebug-2.7.0.gemspec
0.10 real 0.08 user 0.01 sys
Added ../x/ruby-progressbar-1.2.0.gemspec
irb(main):002:0> Dir.glob("../x/*") { |x| `mv #{x} .`; puts "Added #{x}"; `time derp`; }
Added ../x/actionpack-3.2.20.gemspec
0.07 real 0.05 user 0.01 sys
Added ../x/activemodel-3.2.20.gemspec
0.06 real 0.05 user 0.01 sys
Added ../x/activerecord-3.2.20.gemspec
0.06 real 0.05 user 0.01 sys
Added ../x/activeresource-3.2.20.gemspec
0.07 real 0.05 user 0.01 sys
Added ../x/activesupport-3.2.20.gemspec