Skip to content

Instantly share code, notes, and snippets.

@bradland
bradland / ssh-known-hosts-mgmt.sh
Last active April 4, 2023 21:21
SSH known_hosts tools
# This is a short collection of tools that are useful for managing your
# known_hosts file. In this case, I'm using the '-f' flag to specify the
# global known_hosts file because I'll be adding many deploy users on this
# system. Simply omit the -f flag to operate on ~/.ssh/known_hosts
# Add entry for host
ssh-keyscan -H github.com >> /etc/ssh/ssh_known_hosts
# Scan known hosts
ssh-keygen -f /etc/ssh/ssh_known_hosts -F github.com
@bradland
bradland / datebench.rb
Created November 9, 2011 20:57
Date bench
#!/usr/bin/env ruby
require 'benchmark'
require 'date'
Benchmark.bm do|b|
ITERATE = 100000
b.report("strptime") do
time = "2011-05-25 00:00:03 -0400"
fmt = "%Y-%m-%d %H:%M:%S %z"
@bradland
bradland / powconfig
Created November 18, 2011 15:22
Print POW config
#!/usr/bin/env python
#############################################################################
# Print POW config with nice formatting #####################################
#
# Works as is with Python 2.6. For Python 2.7, 'import simplejson as json'
# instead. Save this file to a location in your PATH and make sure it is
# executable. Then you can call 'powconfig' from anywhere and see the active
# POW configuration.
cache: [GET /events] miss
E, [2011-12-09T16:30:47.083257 #7114] ERROR -- : app error: deadlock; recursive locking (ThreadError)
E, [2011-12-09T16:30:47.083428 #7114] ERROR -- : /var/www/staging-ra-eauctionservices-com/shared/bundle/ruby/1.9.1/gems/rack-1.3.5/lib/rack/lock.rb:14:in `lock'
E, [2011-12-09T16:30:47.083533 #7114] ERROR -- : /var/www/staging-ra-eauctionservices-com/shared/bundle/ruby/1.9.1/gems/rack-1.3.5/lib/rack/lock.rb:14:in `call'
E, [2011-12-09T16:30:47.083600 #7114] ERROR -- : /var/www/staging-ra-eauctionservices-com/shared/bundle/ruby/1.9.1/gems/rack-cache-1.1/lib/rack/cache/context.rb:132:in `forward'
E, [2011-12-09T16:30:47.083669 #7114] ERROR -- : /var/www/staging-ra-eauctionservices-com/shared/bundle/ruby/1.9.1/gems/rack-cache-1.1/lib/rack/cache/context.rb:241:in `fetch'
E, [2011-12-09T16:30:47.083739 #7114] ERROR -- : /var/www/staging-ra-eauctionservices-com/shared/bundle/ruby/1.9.1/gems/rack-cache-1.1/lib/rack/cache/context.rb:181:in `lookup'
E, [2011-12-09T16:30:47.083815 #7114] ERROR
@bradland
bradland / mcsorter.rb
Created December 22, 2011 18:19
MCMap Live Slice Sorter
#!/usr/bin/env ruby
# Sorts slice sequence images output by MCMap Live. Creates folders of every
# five and ten images for inspection.
require 'fileutils'
class McSorter
def initialize
@bradland
bradland / natophon.sh
Created December 27, 2011 15:06
NATO phonetic string converter for bash
#!/bin/bash
#########################################################################
# #
# #
# NATO String converter #
# #
# Description: converts string (first parameter given) #
# to NATO phonetics-alphabet #
# #
@bradland
bradland / bench_encoding.txt
Created January 7, 2012 03:30
Encoding benchmarks
# bench_encoding.rb
#!/usr/bin/env ruby -wKU
# encoding: UTF-8
require 'benchmark'
p "Encoding is currently: #{__ENCODING__}"
report_width = 32
Benchmark.bm(report_width) do|b|
@bradland
bradland / collect_keys.rb
Created January 26, 2012 16:51
Collect keys in nested hash
def collect_mysql_variables
@data.values.collect { |value| value.key }.uniq!
end
@bradland
bradland / compare_mysql_vars.rb
Created January 26, 2012 17:43
Compare MySQL variables between servers
#!/usr/bin/env ruby -wKU
require 'csv'
$: << File.expand_path(__FILE__)
# Compares the output of `show variables;` run in the CLI mysql client. The
# script expects the output of this query executed with the `--tables` flag.
# Output is written to the STDOUT, so you'll need to use standard shell
# redirection. Output format is CSV. Example usage:
@bradland
bradland / analyze.rb
Created January 27, 2012 15:37
Analyze TSV log
#!/usr/bin/env ruby -wKU
class DataAnalyzer
def initialize
# Check for Ruby 1.9
unless RUBY_VERSION.scan('1.9').length > 0
puts "This script reqires Ruby 1.9 (specifically, ordered hashes). Sorry! Check out RVM or rbenv for easy management of Ruby versions."
exit 1
end
# We must have at least one file to process