ix-cli 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/ix-bcat +11 -1
- data/bin/ix-center +28 -0
- data/bin/ix-cloudfront-to-json +31 -0
- data/bin/ix-cycle +54 -0
- data/bin/ix-df-to-json +33 -0
- data/bin/ix-df2 +40 -0
- data/bin/ix-domain-dns +43 -0
- data/bin/ix-elb-to-json +217 -0
- data/bin/ix-hls +5 -1
- data/bin/ix-json-filter +41 -0
- data/bin/ix-json-join +76 -0
- data/bin/ix-json-key-on-steroids +3 -0
- data/bin/ix-json-swap +8 -0
- data/bin/ix-json-to-yaml +6 -0
- data/bin/ix-ljust +5 -0
- data/bin/ix-matrioshka +76 -0
- data/bin/ix-mysqldump-to-json +120 -0
- data/bin/ix-pad +36 -0
- data/bin/ix-percentage +18 -3
- data/bin/ix-query-string-to-json +10 -0
- data/bin/ix-remove +46 -0
- data/bin/ix-rjust +5 -0
- data/bin/ix-rulers +79 -0
- data/bin/ix-s3-log-to-json +38 -0
- data/bin/ix-time-distance +47 -0
- data/bin/ix-yaml-to-json +7 -0
- metadata +49 -5
- data/bin/ix-json-to-xml +0 -1
data/bin/ix-matrioshka
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
options = {}
|
6
|
+
options[:style] = :round
|
7
|
+
|
8
|
+
OptionParser.new do |opts|
|
9
|
+
|
10
|
+
opts.banner = "Usage: #{$0} [OPTIONS]"
|
11
|
+
|
12
|
+
opts.on('-s', '--style [STRING]', 'One of [round, square, mysql, double].') do |value|
|
13
|
+
options[:style] = value.to_sym
|
14
|
+
end
|
15
|
+
|
16
|
+
end.parse!
|
17
|
+
|
18
|
+
required_options = [:style]
|
19
|
+
required_options.each do |option|
|
20
|
+
unless options[option]
|
21
|
+
$stderr.puts "Can not run #{option.to_s} was not given."
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def box(string, style = :round)
|
27
|
+
styles = {
|
28
|
+
round: {
|
29
|
+
top: '╭╮',
|
30
|
+
bottom: '╰╯',
|
31
|
+
side: '│',
|
32
|
+
horizontal: '─'
|
33
|
+
},
|
34
|
+
square: {
|
35
|
+
top: '┌┐',
|
36
|
+
bottom: '└┘',
|
37
|
+
side: '│',
|
38
|
+
horizontal: '─'
|
39
|
+
},
|
40
|
+
double: {
|
41
|
+
top: '╔╗',
|
42
|
+
bottom: '╚╝',
|
43
|
+
side: '║',
|
44
|
+
horizontal: '═'
|
45
|
+
},
|
46
|
+
mysql: {
|
47
|
+
top: '++',
|
48
|
+
bottom: '++',
|
49
|
+
side: '|',
|
50
|
+
horizontal: '-'
|
51
|
+
}
|
52
|
+
}
|
53
|
+
if styles[style].nil?
|
54
|
+
$stderr.puts "Unknown style #{style}"
|
55
|
+
exit 1
|
56
|
+
end
|
57
|
+
s = styles[style]
|
58
|
+
lines = []
|
59
|
+
string.each_line do |line|
|
60
|
+
lines.push(line.chomp)
|
61
|
+
end
|
62
|
+
result = ''
|
63
|
+
max = lines.map { |line| line.size }.sort.last
|
64
|
+
line = (s[:horizontal] * (max + 2))
|
65
|
+
result << "#{s[:top][0]}#{line}#{s[:top][1]}\n"
|
66
|
+
lines.each do |line|
|
67
|
+
line = line.ljust(max)
|
68
|
+
padding_left = ' ' * ((max - line.size) / 2)
|
69
|
+
padding_right = ' ' * (max - line.size - padding_left.size)
|
70
|
+
result << "#{s[:side]} #{padding_left}#{line}#{padding_right} #{s[:side]}\n"
|
71
|
+
end
|
72
|
+
result << "#{s[:bottom][0]}#{line}#{s[:bottom][1]}\n"
|
73
|
+
result
|
74
|
+
end
|
75
|
+
|
76
|
+
puts box(STDIN.read, options[:style])
|
@@ -0,0 +1,120 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# ai did not cut it, I had to write this myself..
|
4
|
+
# cat file.sql | ruby parse.rb
|
5
|
+
|
6
|
+
require 'json'
|
7
|
+
|
8
|
+
class Buffer
|
9
|
+
def initialize
|
10
|
+
@buffer = []
|
11
|
+
end
|
12
|
+
def add(line)
|
13
|
+
@buffer << line
|
14
|
+
end
|
15
|
+
def flush
|
16
|
+
@buffer.join("\n")
|
17
|
+
end
|
18
|
+
def reset
|
19
|
+
@buffer = []
|
20
|
+
end
|
21
|
+
def to_s
|
22
|
+
flush
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Database
|
27
|
+
attr_accessor :name
|
28
|
+
attr_accessor :tables
|
29
|
+
def initialize(name)
|
30
|
+
@name = name
|
31
|
+
@tables = []
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Table
|
36
|
+
attr_accessor :name
|
37
|
+
attr_accessor :columns
|
38
|
+
def initialize(name)
|
39
|
+
@name = name
|
40
|
+
@columns = []
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
class Column
|
45
|
+
attr_accessor :name
|
46
|
+
attr_accessor :type
|
47
|
+
def initialize(name, type)
|
48
|
+
@name = name
|
49
|
+
@type = type
|
50
|
+
end
|
51
|
+
end
|
52
|
+
# -- Host: localhost Database: empowerkit_DBnew
|
53
|
+
REGEX_DATABASE_1 = /(^USE `)([^`]+)(`;)|(-- Host: [^\s]+Database: )(\w+)(\n)/
|
54
|
+
REGEX_DATABASE_2 = /(-- Host: [^\s]+\s+Database: )(\w+)($)/
|
55
|
+
REGEX_TABLE_START = /(^CREATE TABLE `)([^`]+)(` \()/
|
56
|
+
REGEX_TABLE_END = /(^\)( ENGINE.)(\w+))/
|
57
|
+
REGEX_COLUMN = /(^ `)([^`]+)(` )(\w+)([^\n]+)/
|
58
|
+
|
59
|
+
database = nil
|
60
|
+
parsing_table = false
|
61
|
+
buffer = Buffer.new
|
62
|
+
|
63
|
+
def get_table_object(string)
|
64
|
+
table_name = string.match(REGEX_TABLE_START)[2]
|
65
|
+
table_columns = []
|
66
|
+
string.scan(REGEX_COLUMN) do |column|
|
67
|
+
table_columns << Column.new(column[1], column[3])
|
68
|
+
end
|
69
|
+
table = Table.new(table_name)
|
70
|
+
table.columns = table_columns
|
71
|
+
table
|
72
|
+
end
|
73
|
+
|
74
|
+
STDIN.each_line do |line|
|
75
|
+
# line = line.force_encoding('UTF-8')
|
76
|
+
line = line.force_encoding('ISO-8859-1').encode('UTF-8')
|
77
|
+
|
78
|
+
if line =~ REGEX_DATABASE_1
|
79
|
+
database = Database.new($2)
|
80
|
+
next
|
81
|
+
end
|
82
|
+
|
83
|
+
if line =~ REGEX_DATABASE_2
|
84
|
+
database = Database.new($2)
|
85
|
+
next
|
86
|
+
end
|
87
|
+
|
88
|
+
next unless database
|
89
|
+
|
90
|
+
if line =~ REGEX_TABLE_START
|
91
|
+
buffer.reset
|
92
|
+
buffer.add(line.chomp)
|
93
|
+
parsing_table = true
|
94
|
+
next
|
95
|
+
end
|
96
|
+
|
97
|
+
if parsing_table
|
98
|
+
buffer.add(line.chomp)
|
99
|
+
if line =~ REGEX_TABLE_END
|
100
|
+
parsing_table = false
|
101
|
+
get_table_object(buffer.flush).tap do |table|
|
102
|
+
database.tables << table
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
database.tables.each do |table|
|
110
|
+
table.columns.each do |column|
|
111
|
+
object = {
|
112
|
+
:database => database.name,
|
113
|
+
:table => table.name,
|
114
|
+
:column => column.name,
|
115
|
+
:type => column.type
|
116
|
+
}
|
117
|
+
puts object.to_json
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
data/bin/ix-pad
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
options = {}
|
6
|
+
options[:size] = 2
|
7
|
+
|
8
|
+
OptionParser.new do |opts|
|
9
|
+
|
10
|
+
opts.banner = "Usage: #{$0} [OPTIONS]"
|
11
|
+
|
12
|
+
opts.on('-s', '--size [NUMBER]', 'Size.') do |value|
|
13
|
+
options[:size] = value.to_i
|
14
|
+
end
|
15
|
+
|
16
|
+
end.parse!
|
17
|
+
|
18
|
+
required_options = [:size]
|
19
|
+
required_options.each do |option|
|
20
|
+
unless options[option]
|
21
|
+
$stderr.puts "Can not run #{option.to_s} was not given."
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
options[:size].times do |i|
|
27
|
+
puts ''
|
28
|
+
end
|
29
|
+
|
30
|
+
STDIN.each_line do |line|
|
31
|
+
puts (' ' * options[:size]) + line.chomp + (' ' * options[:size])
|
32
|
+
end
|
33
|
+
|
34
|
+
options[:size].times do |i|
|
35
|
+
puts ''
|
36
|
+
end
|
data/bin/ix-percentage
CHANGED
@@ -44,12 +44,21 @@ class Percentage
|
|
44
44
|
bars = bars.to_ansi.red.to_s
|
45
45
|
end
|
46
46
|
end
|
47
|
+
|
48
|
+
output_percentage = (to_f.round(2).to_s.rjust(5, ' ') + '%')
|
49
|
+
output_divisor = @divisor.round(2).to_s.rjust(10, ' ')
|
50
|
+
|
51
|
+
if color
|
52
|
+
output_percentage = output_percentage.to_ansi.pink.to_s
|
53
|
+
output_divisor = output_divisor.to_ansi.cyan.to_s
|
54
|
+
end
|
55
|
+
|
47
56
|
bindings = {
|
48
57
|
:open => '[',
|
49
58
|
:close => ']',
|
50
59
|
:bars => bars,
|
51
|
-
:percentage =>
|
52
|
-
:divisor =>
|
60
|
+
:percentage => output_percentage,
|
61
|
+
:divisor => output_divisor,
|
53
62
|
:label => label
|
54
63
|
}
|
55
64
|
format("%<open>s%<bars>s%<close>s %<percentage>s %<divisor>s %<label>s", bindings)
|
@@ -165,7 +174,13 @@ end.reverse.each do |key|
|
|
165
174
|
p = Percentage.new(total, array.product, options[:width])
|
166
175
|
|
167
176
|
template = "%s %s"
|
168
|
-
|
177
|
+
|
178
|
+
if options[:color]
|
179
|
+
bindings = [p.to_bar(options[:color], options[:char], options[:label]), key.to_ansi.yellow.to_s]
|
180
|
+
else
|
181
|
+
bindings = [p.to_bar(options[:color], options[:char], options[:label]), key]
|
182
|
+
end
|
183
|
+
|
169
184
|
puts template % bindings
|
170
185
|
end
|
171
186
|
|
data/bin/ix-remove
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'isna'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
|
8
|
+
OptionParser.new do |opts|
|
9
|
+
|
10
|
+
opts.banner = "Usage: #{$0} [OPTIONS]"
|
11
|
+
|
12
|
+
opts.on('-f', '--file []', 'File with entries to be removed.') do |value|
|
13
|
+
options[:file] = value
|
14
|
+
end
|
15
|
+
|
16
|
+
end.parse!
|
17
|
+
|
18
|
+
required_options = [:file]
|
19
|
+
required_options.each do |option|
|
20
|
+
unless options[option]
|
21
|
+
$stderr.puts "Can not run #{option.to_s} was not given."
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
unless File.exist?(options[:file])
|
27
|
+
$stderr.puts "File #{options[:file]} does not exist."
|
28
|
+
exit 1
|
29
|
+
end
|
30
|
+
|
31
|
+
inputs = []
|
32
|
+
entries = []
|
33
|
+
|
34
|
+
|
35
|
+
File.read(options[:file]).each_line do |line|
|
36
|
+
entries << line
|
37
|
+
end
|
38
|
+
|
39
|
+
STDIN.each_line do |line|
|
40
|
+
inputs << line
|
41
|
+
end
|
42
|
+
|
43
|
+
(inputs - entries).each do |item|
|
44
|
+
puts item.chomp
|
45
|
+
end
|
46
|
+
|
data/bin/ix-rjust
ADDED
data/bin/ix-rulers
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
options = {}
|
6
|
+
options[:padding] = 5
|
7
|
+
options[:count] = 0
|
8
|
+
|
9
|
+
OptionParser.new do |opts|
|
10
|
+
|
11
|
+
opts.banner = "Usage: #{$0} [OPTIONS]"
|
12
|
+
|
13
|
+
opts.on('-w', '--width [NUMBER]', 'Width of the horizontal ruler (custom).') do |value|
|
14
|
+
options[:width] = value.to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
opts.on('-p', '--padding [NUMBER]', 'Padding for numbers on the left.') do |value|
|
18
|
+
options[:padding] = value.to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on('-c', '--count [NUMBER]', 'Count lines starting from.') do |value|
|
22
|
+
options[:count] = value.to_i
|
23
|
+
end
|
24
|
+
|
25
|
+
end.parse!
|
26
|
+
|
27
|
+
required_options = [:padding, :count]
|
28
|
+
required_options.each do |option|
|
29
|
+
unless options[option]
|
30
|
+
$stderr.puts "Can not run #{option.to_s} was not given."
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
class Ruler
|
36
|
+
attr_accessor :length
|
37
|
+
def initialize(length)
|
38
|
+
@length = length
|
39
|
+
end
|
40
|
+
|
41
|
+
# we print the number of the column
|
42
|
+
# in various rows:
|
43
|
+
# for example first row will print:
|
44
|
+
# 00000000000
|
45
|
+
# 00000000011
|
46
|
+
# 12345678901
|
47
|
+
def to_s
|
48
|
+
items = (@length + 1).times.map do |item|
|
49
|
+
item.to_s.rjust(5, '0').chars
|
50
|
+
end
|
51
|
+
items.transpose.map(&:join).join("\n")
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
if options[:width]
|
57
|
+
Ruler.new(options[:width].to_i).to_s.lines.each do |line|
|
58
|
+
puts (' ' * (options[:padding] + 2)) + line
|
59
|
+
end
|
60
|
+
STDIN.each_line do |line|
|
61
|
+
puts "#{options[:count].to_s.rjust(options[:padding], '0')} | #{line}"
|
62
|
+
options[:count] += 1
|
63
|
+
end
|
64
|
+
else
|
65
|
+
lines = []
|
66
|
+
STDIN.each_line do |line|
|
67
|
+
lines << line
|
68
|
+
end
|
69
|
+
exit 0 if lines.empty?
|
70
|
+
options[:width] = lines.map(&:length).max
|
71
|
+
Ruler.new(options[:width].to_i).to_s.lines.each do |line|
|
72
|
+
puts (' ' * (options[:padding] + 2)) + line
|
73
|
+
end
|
74
|
+
lines.each do |line|
|
75
|
+
puts "#{options[:count].to_s.rjust(options[:padding], '0')} |#{line}"
|
76
|
+
options[:count] += 1
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
def parse_s3_log_line(line)
|
7
|
+
|
8
|
+
# Split the log line by spaces, respecting quoted strings
|
9
|
+
parts = line.scan(/"([^"]+)"|(\S+)/).flatten.compact
|
10
|
+
|
11
|
+
{
|
12
|
+
bucket_owner: parts[0],
|
13
|
+
bucket: parts[1],
|
14
|
+
time: parts[2] + parts[3], # Remove the brackets around the time
|
15
|
+
remote_ip: parts[4],
|
16
|
+
requester: parts[5],
|
17
|
+
request_id: parts[6],
|
18
|
+
operation: parts[7],
|
19
|
+
key: parts[8],
|
20
|
+
request_uri: parts[9],
|
21
|
+
http_status: parts[10].to_i,
|
22
|
+
error_code: parts[11],
|
23
|
+
bytes_sent: parts[12].to_i,
|
24
|
+
object_size: parts[13],
|
25
|
+
total_time: parts[14].to_i,
|
26
|
+
turnaround_time: parts[15].to_i,
|
27
|
+
referer: parts[16],
|
28
|
+
user_agent: parts[17],
|
29
|
+
version_id: parts[18]
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
# Read from standard input
|
34
|
+
ARGF.each_line do |line|
|
35
|
+
parsed_log = parse_s3_log_line(line)
|
36
|
+
puts parsed_log.to_json
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
require 'optparse'
|
6
|
+
|
7
|
+
options = {}
|
8
|
+
|
9
|
+
OptionParser.new do |opts|
|
10
|
+
|
11
|
+
opts.banner = "Usage: #{$0} [OPTIONS]"
|
12
|
+
|
13
|
+
opts.on('-k', '--key [NAME]', 'Key in json to look for a timestamp.') do |value|
|
14
|
+
options[:key] = value
|
15
|
+
end
|
16
|
+
|
17
|
+
end.parse!
|
18
|
+
|
19
|
+
required_options = [:key]
|
20
|
+
required_options.each do |option|
|
21
|
+
unless options[option]
|
22
|
+
$stderr.puts "Can not run #{option.to_s} was not given."
|
23
|
+
exit 1
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
times = []
|
28
|
+
distances = []
|
29
|
+
previous = nil
|
30
|
+
|
31
|
+
STDIN.each_line do |line|
|
32
|
+
object = JSON.parse(line)
|
33
|
+
times << object[options[:key]]
|
34
|
+
end
|
35
|
+
|
36
|
+
times.sort do |a, b|
|
37
|
+
a <=> b
|
38
|
+
end.each do |time|
|
39
|
+
if previous
|
40
|
+
distances << time - previous
|
41
|
+
end
|
42
|
+
previous = time
|
43
|
+
end
|
44
|
+
|
45
|
+
distances.each do |distance|
|
46
|
+
puts "distance #{distance}"
|
47
|
+
end
|