Skip to content

Instantly share code, notes, and snippets.

@bradland
bradland / ssh-known-hosts-mgmt.sh
Last active Jun 19, 2022
SSH known_hosts tools
View ssh-known-hosts-mgmt.sh
# 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
View datebench.rb
#!/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 Nov 18, 2011
Print POW config
View powconfig
#!/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.
View thread-deadlock-cache.txt
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 Dec 22, 2011
MCMap Live Slice Sorter
View mcsorter.rb
#!/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 Dec 27, 2011
NATO phonetic string converter for bash
View natophon.sh
#!/bin/bash
#########################################################################
# #
# #
# NATO String converter #
# #
# Description: converts string (first parameter given) #
# to NATO phonetics-alphabet #
# #
View bench_encoding.txt
# 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 Jan 26, 2012
Collect keys in nested hash
View collect_keys.rb
def collect_mysql_variables
@data.values.collect { |value| value.key }.uniq!
end
@bradland
bradland / compare_mysql_vars.rb
Created Jan 26, 2012
Compare MySQL variables between servers
View compare_mysql_vars.rb
#!/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 Jan 27, 2012
Analyze TSV log
View analyze.rb
#!/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