Skip to content

Instantly share code, notes, and snippets.

@bobstrange
bobstrange / sshkit_sample.rb
Last active February 4, 2016 06:39
Use SSHKit
require 'sshkit'
require 'sshkit/dsl'
HOST = '' # 'foo.domain'
USER = '' # 'ec2-user'
KEYS = [''] # '~/.ssh/id_rsa'
hoge = "hoge"
command = SSHKit::Command.new <<-EOF
echo # Need to place bare "echo".
@bobstrange
bobstrange / spot_check.rb
Created January 14, 2016 06:42
Check spot instance termination
require 'aws-sdk'
TERMINAL_CODES = %w(
request-canceled-and-instance-running
marked-for-termination
instance-terminated-by-price
instance-terminated-by-user
instance-terminated-no-capacity
instance-terminated-capacity-oversubscribed
instance-terminated-launch-group-constraint
@bobstrange
bobstrange / url_pattern.rb
Last active February 4, 2016 06:20
List Rails routes URI Pattern
# Returns rake routes like formatted string.
def get_formatted_routes_data(routes)
inspector = ActionDispatch::Routing::RoutesInspector.new(all_routes)
inspector.format(ActionDispatch::Routing::ConsoleFormatter.new, nil)
end
all_routes = Rails.application.routes.routes
data = get_formatted_routes(all_routes)
list = data.split("\n")
@bobstrange
bobstrange / git.md
Last active April 1, 2016 06:15
Operation Commands

Git

HEAD

HEAD is pointed current branch's newest commit. (also @ is pointed same)

See previous commit

# first commit before
git show HEAD^
@bobstrange
bobstrange / fixture_class_not_found.md
Last active February 29, 2016 05:05
To resolve ActiveRecord::FixtureClassNotFound:

How to resolve ActiveRecord::FixtureClassNotFound error when you run unit test

Refers

rspec/rspec-rails#510

Example

We have Doctor and User model. We also have DoctorsUsers model to represent with the relationship between those two models.

@bobstrange
bobstrange / atom_debugging.md
Created March 8, 2016 06:19
Atom debugging
@bobstrange
bobstrange / unicorn.md
Created March 9, 2016 03:37
Unicorn configuration for Rails

Retrieve self information

instance_id

instance_id = `ec2-metadata --instance-id | sed 's/instance-id: //'`.chomp
@bobstrange
bobstrange / gist:37936887d206b0fc008e45bdbbb570d9
Created November 24, 2016 05:23
agent-stats-api ruby sample
require 'net/https'
require 'uri'
require 'json'
require 'csv'
token = "*******"
def retrieve_stats(token)
url = "*******"
uri = URI.parse("https://api.agent-stats.com/groups/#{url}/now")

Show Database size

SELECT 
  table_schema,
  sum(data_length+index_length) / 1024 / 1024 AS 'Total size(MB)'
FROM
  information_schema.tables
GROUP BY
 table_schema