Skip to content

Instantly share code, notes, and snippets.

View tjsingleton's full-sized avatar

TJ Singleton tjsingleton

View GitHub Profile
@tjsingleton
tjsingleton / Chef Solo Bootstrap with Ruby 2.2.2
Last active November 5, 2021 21:41 — forked from nyxwulf/Chef Bootstrap Ruby 1.9.3-p194
Chef Solo Bootstrap with Ruby 2.2.2
#!/usr/bin/env bash
apt-get -y update
apt-get -y upgrade
apt-get -y install build-essential zlib1g-dev libssl-dev libreadline-gplv2-dev libyaml-dev libffi-dev libjemalloc-dev
apt-get -y install autoconf curl bzip2
apt-get -y autoremove
apt-get -y clean
cd /usr/local/src
curl http://cache.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz
# selenium-webclient does not clean up cookies unless your currently on that page.
module CookieRemover
def self.delete_all(path)
Capybara.current_session.driver.visit(path)
Capybara.reset_sessions!
end
end
After("@external-site") do
CookieRemover.delete_all("http://www.external-site.com")
@tjsingleton
tjsingleton / mysql-to-csv.rb
Created January 13, 2017 17:34
Reads from STDIN or a file, converts \G mysql formatted results to csv, and writes to STDOUT
require "csv"
# Reads from STDIN or a file, converts \G mysql formatted results to csv, and writes to STDOUT
#
# STDIN Usage:
# mysql ... | ruby mysql-to-csv.rb
#
# File Usage:
# ruby mysql-to-csv.rb results.txt
#
@tjsingleton
tjsingleton / delete-instance.rb
Last active May 12, 2016 03:09
For a list of instances returned from a chef search, terminate instances, release any elastic ips, and delete any attached volumes.
require 'time'
require 'json'
require 'pp'
require 'open3'
class DeleteShare
def initialize
@instances = Hash.new {|h,k| h[k] = [] }
@public_ips = Hash.new {|h,k| h[k] = [] }
@volumes = Hash.new {|h,k| h[k] = [] }
route: 66.249.64.0/20
descr: Google
origin: AS15169
notify: noc@google.com
mnt-by: MAINT-AS15169
changed: noc@google.com 20110301
source: RADB
route: 66.249.80.0/20
descr: Google
@tjsingleton
tjsingleton / create-feature-branch
Last active December 27, 2015 09:39
Git helpers I install to ~/bin
#!/usr/bin/env bash
usage (){
echo "Usage: $0 new-branch-name"
exit 1
}
[[ $# -eq 0 ]] && usage
git fetch origin
_ = nil
scope = binding
loop do
print "> "
code = gets.chomp
_ = eval(code, scope)
puts "=> #{_.inspect}"
end
@tjsingleton
tjsingleton / config.ru
Created July 9, 2013 14:30
require_relative in config.ru
require_relative './mylib'
run ->(env){ [200, {}, ['']] }
last_line = nil
index = 0
ARGF.each_line do |line|
index += 1
next if index < 35
puts last_line if last_line # skip last line
line.gsub!("#{0x01}\\#{0x01}", "#{0x01}#{0x01}")
line.gsub!("\\", "\\\\")
{"resource":"Orders","http_method":"POST","route":"/orders","description":"Creating an order","explanation":"First, create an order, then make a later request to get it back","parameters":[{"name":"name","description":"Name of order","required":true,"scope":"order"},{"name":"paid","description":"If the order has been paid for","required":true,"scope":"order"},{"name":"email","description":"Email of user that placed the order","scope":"order"}],"requests":[{"request_method":"POST","request_path":"/orders","request_body":"{\"order\":{\"name\":\"Order 1\",\"paid\":true,\"email\":\"email@example.com\"}}","request_headers":{"Accept":"application/json","Content-Type":"application/json","Host":"example.org","Cookie":""},"request_query_parameters":{},"request_content_type":"application/json","response_status":201,"response_status_text":"Created","response_body":"{\"email\":\"email@example.com\",\"name\":\"Order 1\",\"paid\":true}","response_headers":{"Content-Type":"application/json; charset=utf-8","Location":"http:/