Skip to content

Instantly share code, notes, and snippets.

TJ Singleton tjsingleton

Block or report user

Report or block tjsingleton

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tjsingleton
tjsingleton / mysql-to-csv.rb
Created Jan 13, 2017
Reads from STDIN or a file, converts \G mysql formatted results to csv, and writes to STDOUT
View mysql-to-csv.rb
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
For a list of instances returned from a chef search, terminate instances, release any elastic ips, and delete any attached volumes.
View delete-instance.rb
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] = [] }
View apple_stock.rb
# swap loops so we can exit early from the inner loop once we've searched the valid range
require "pp"
require "minitest/autorun"
class StockTest < Minitest::Test
attr_accessor :loops
def pick_best_time_to_buy(stock)
best_value = 0
View google ips
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 Dec 27, 2015
Git helpers I install to ~/bin
View create-feature-branch
#!/usr/bin/env bash
usage (){
echo "Usage: $0 new-branch-name"
exit 1
}
[[ $# -eq 0 ]] && usage
git fetch origin
View repl.rb
_ = nil
scope = binding
loop do
print "> "
code = gets.chomp
_ = eval(code, scope)
puts "=> #{_.inspect}"
end
@tjsingleton
tjsingleton / config.ru
Created Jul 9, 2013
require_relative in config.ru
View config.ru
require_relative './mylib'
run ->(env){ [200, {}, ['']] }
View clean_epf.rb
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!("\\", "\\\\")
View creating_an_order.json
{"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:/
@tjsingleton
tjsingleton / 1mb_comment.rb
Created May 9, 2013
The memory cost of comments in Ruby
View 1mb_comment.rb
This file has been truncated, but you can view the full file.
You can’t perform that action at this time.