ix-cli 0.0.3 → 0.0.9

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4f15816063d5a25ec71bba2ceda821a244c5d19501709a04dd5d8626e613bc9d
4
- data.tar.gz: 6f96b6106a06455777b7f02da0bbffb2c981f2e91d7c28edc1365c28d53580c2
3
+ metadata.gz: 72a2619cd73f53565d9ce416626d3a1427634740336b60c75d767f06cf7ae5f9
4
+ data.tar.gz: 273331403a44e58f3b16d51f40f284ef242b982e839d7c9470d8692673a477db
5
5
  SHA512:
6
- metadata.gz: 5772e7c6123507f3689cdfff44ba52357412722ec0d63938798e7da4d3e2629f416c2d69a173987dda3b4d449f2b3f6b8248f143b509ce1bf70cbb0a384e5d9b
7
- data.tar.gz: 686f1b86366990b487706959b963cf8df3b1f575a114aa54644b5310f8d00d8df235aeadd1d5ee2b96f7ae2111f8fa659852e4fffc0fa8750968e864a5e4167e
6
+ metadata.gz: 900fe154770e1b644b345629ac9f9f0f786d471705b6802f44f8d282e37bca6667eb6cf1b7a9f97b87ef87931ddeceafc08ffcdd4ed88cfbf343975debb810ae
7
+ data.tar.gz: c9be4dd356b33c16fcaa0d1df11d81c0e62f070047bbe90b032d8eefca255a30ff7a822d2215ba94e20d4141ee5470818531a44df84aed7d128717f00ac87688
data/bin/ix-cat CHANGED
@@ -1,7 +1,7 @@
1
- #!/usr/bin/env bash
1
+ #!/usr/bin/env ruby
2
2
 
3
- application=$1
4
- target_path=`dirname $0`
5
- target_file="$target_path/ix-$application"
3
+ application = ARGV[0]
4
+ target_path = File.dirname(__FILE__)
5
+ target_file = "#{target_path}/ix-#{application}"
6
6
 
7
- cat $target_file
7
+ system "cat #{target_file}"
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'json'
4
+ require 'optparse'
5
+ require 'isna'
6
+
7
+ options = {}
8
+ options[:count] = 10
9
+ options[:errors] = false
10
+
11
+ OptionParser.new do |opts|
12
+
13
+ opts.banner = "Usage: #{$0} [OPTIONS]"
14
+
15
+ opts.on('-k', '--keys [KEYS]', 'List of keys to parse from json separated by :.') do |value|
16
+ options[:keys] = value
17
+ end
18
+
19
+ opts.on('-c', '--count [NUMBER]', 'Number of top N items to show.') do |value|
20
+ options[:count] = value.to_i
21
+ end
22
+
23
+ opts.on('-e', '--errors', 'If we should report errors.') do |value|
24
+ options[:errors] = value
25
+ end
26
+
27
+ end.parse!
28
+
29
+ required_options = [:keys]
30
+ required_options.each do |option|
31
+ unless options[option]
32
+ $stderr.puts "Can not run #{option.to_s} was not given."
33
+ exit 1
34
+ end
35
+ end
36
+
37
+ map = {}
38
+ keys = options[:keys].split(':')
39
+
40
+ STDIN.each_line do |line|
41
+ begin
42
+ object = JSON.parse(line)
43
+ object.each do |k, v|
44
+ next unless keys.include?(k)
45
+ submap = map[k] ||= {}
46
+ submap[v] ||= 0
47
+ submap[v] += 1
48
+ end
49
+ rescue => error
50
+ if options[:errors]
51
+ $stderr.puts error.message
52
+ end
53
+ end
54
+ end
55
+
56
+ def print_map(map, sample)
57
+ map.each do |category, stats|
58
+ values = []
59
+ total = 0
60
+
61
+ counter = 0
62
+ stats.values.sort.reverse.each do |value_1|
63
+ stats.each do |key, value_2|
64
+ if value_1 == value_2
65
+ counter += 1
66
+ break if counter > sample
67
+ total += value_1
68
+ values.push({ :value => value_1, :key => key })
69
+ end
70
+ end
71
+ end
72
+
73
+ puts ""
74
+ puts "#{category.to_s.to_ansi.cyan.to_s} (#{total})"
75
+
76
+ values.each do |object|
77
+ percentage = "%2.2f" % (object[:value] / total.to_f * 100)
78
+ h_percentage = (percentage.to_s + '%').rjust(6, ' ').to_ansi.yellow.to_s
79
+ value = object[:value].to_s.rjust(10, ' ').to_ansi.green.to_s
80
+ key = object[:key]
81
+ puts "%s %s %s" % [value, h_percentage, key]
82
+ end
83
+
84
+ end
85
+ end
86
+
87
+ print_map(map, options[:count])
88
+
@@ -3,7 +3,12 @@
3
3
  normal = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
4
4
  rot13 = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM"
5
5
 
6
- STDIN.each_line do |line|
7
- puts line.tr!(normal, rot13)
6
+ STDIN.each_char do |char|
7
+ candidate = char.tr!(normal, rot13)
8
+ if candidate
9
+ print candidate
10
+ else
11
+ print char
12
+ end
8
13
  end
9
14
 
@@ -0,0 +1,39 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'isna'
4
+
5
+ UNIVERSE = (0..9).to_a
6
+ ROT = 5
7
+ DIGIT_REGEX = /^\d$/
8
+
9
+ def resolve(set, candidate)
10
+ needle = set.index(candidate)
11
+ if (needle + ROT) > set.size
12
+ return (needle - set.size + ROT)
13
+ end
14
+ if (needle + ROT) < set.size
15
+ return needle + ROT
16
+ end
17
+ if (needle == 5)
18
+ return 0
19
+ end
20
+ end
21
+
22
+ STDIN.each_char do |char|
23
+ next if char.chomp == ''
24
+ unless char =~ DIGIT_REGEX
25
+ print char
26
+ next
27
+ end
28
+ rotation = resolve(UNIVERSE, char.to_i)
29
+ m = (0..9).to_a.map do |n|
30
+ if n.to_s == char
31
+ char.to_ansi.green.to_s
32
+ else
33
+ n.to_s
34
+ end
35
+ end
36
+ # puts "#{rotation.to_s.to_ansi.red.to_s} = [" + (m * ', ') + "]"
37
+ print rotation
38
+ end
39
+
data/bin/ix-rps CHANGED
@@ -10,7 +10,6 @@ end
10
10
  trap('QUIT', &shutdown)
11
11
  trap('INT', &shutdown)
12
12
  trap('TERM', &shutdown)
13
- trap('KILL', &shutdown)
14
13
 
15
14
  total_requests = 0
16
15
  requests_per_second = 0
@@ -0,0 +1,135 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+
5
+ options = {}
6
+
7
+ OptionParser.new do |opts|
8
+
9
+ opts.banner = "Usage: #{$0} [OPTIONS]"
10
+
11
+ opts.on('-m', '--min-sigma [min]', 'Min sigma.') do |value|
12
+ options[:min_sigma] = value.gsub(/\\/, '').to_f
13
+ end
14
+
15
+ opts.on('-a', '--max-sigma [max]', 'Max sigma.') do |value|
16
+ options[:max_sigma] = value.gsub(/\\/, '').to_f
17
+ end
18
+
19
+ opts.on('-c', '--column [max]', 'Col to be parsed.') do |value|
20
+ options[:column] = value.to_i
21
+ end
22
+
23
+ opts.on('-k', '--kdev [max]', 'kdev.') do |value|
24
+ options[:kdev] = value.to_i
25
+ end
26
+
27
+ end.parse!
28
+
29
+ required_options = [:min_sigma, :max_sigma, :column, :kdev]
30
+ required_options.each do |option|
31
+ unless options[option]
32
+ $stderr.puts "Can not run #{option.to_s} was not given."
33
+ exit 1
34
+ end
35
+ end
36
+
37
+ class Array
38
+ def mean
39
+ product / size
40
+ end
41
+
42
+ def product
43
+ sum
44
+ end
45
+ def sum_of_squares(avg = nil)
46
+ avg = mean unless avg
47
+ sqares = map do |number|
48
+ result = number - avg
49
+ result ** 2
50
+ end
51
+ sqares.sum
52
+ end
53
+
54
+ def variance(minus = 0)
55
+ sum_of_squares / (size - minus)
56
+ end
57
+
58
+ def standard_deviation
59
+ Math.sqrt(variance(1.5))
60
+ end
61
+
62
+ def population_standard_deviation
63
+ Math.sqrt(variance(0))
64
+ end
65
+
66
+ def median
67
+ return size[0] if size == 1
68
+ self[(size + 1) / 2]
69
+ end
70
+
71
+ def sample_standard_deviation
72
+ med = median
73
+ sqr = map do |number|
74
+ result = number - med
75
+ result ** 2
76
+ end
77
+ Math.sqrt(sqr.mean)
78
+ end
79
+
80
+ def sum
81
+ inject do |cumulative, value|
82
+ cumulative += value
83
+ end
84
+ end
85
+
86
+ end
87
+
88
+ data = []
89
+
90
+ STDIN.each_line do |line|
91
+ line.chomp!
92
+ index = options[:column]
93
+ item = line.split(' ')[index - 1]
94
+ data.push({ :number => item.to_f, :line => line })
95
+ end
96
+
97
+ numbers = data.map do |object|
98
+ object[:number]
99
+ end
100
+
101
+ options[:standard_deviation] = numbers.standard_deviation
102
+ options[:min_deviation_from_mean] = (options[:min_sigma] * options[:standard_deviation] + numbers.mean)
103
+ options[:max_deviation_from_mean] = (options[:max_sigma] * options[:standard_deviation] + numbers.mean)
104
+
105
+ data.each do |object|
106
+
107
+ smaller_than_max = (object[:number] > options[:min_deviation_from_mean])
108
+ bigger_than_min = (object[:number] < options[:max_deviation_from_mean])
109
+
110
+ # $stderr.puts [
111
+ # smaller_than_max,
112
+ # object[:number],
113
+ # bigger_than_min,
114
+ # options[:min_deviation_from_mean],
115
+ # options[:max_deviation_from_mean]
116
+ # ].map { |x| x.inspect } * ' '
117
+
118
+
119
+ if smaller_than_max && bigger_than_min
120
+ puts object[:line]
121
+ end
122
+ end
123
+
124
+ def pretty_options(hash, width = 20)
125
+ r = ''
126
+ hash.keys.sort.each do |key|
127
+ k = key.to_s.ljust(width, '.')
128
+ v = hash[key].to_s.rjust(width, '.')
129
+ r << [k, v] * ' ' + "\n"
130
+ end
131
+ r
132
+ end
133
+
134
+ # $stderr.puts pretty_options(options)
135
+
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  class Token
4
- REGEX = /(^)(\d+)(\s+)(\w+)(\s+)(.*)/
4
+ REGEX = /(^)([^ ]+)(\s+)(\w+)(\s+)(.*)/
5
5
  attr_accessor :column
6
6
  def initialize(string)
7
7
  @string = string
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ix-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuyoshi Tlacaelel
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
  date: 2020-02-05 00:00:00.000000000 Z
@@ -24,8 +24,8 @@ dependencies:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.0.4
27
- description:
28
- email:
27
+ description:
28
+ email:
29
29
  executables:
30
30
  - ix
31
31
  - ix-acronym
@@ -143,6 +143,7 @@ executables:
143
143
  - ix-json-paths-pretty
144
144
  - ix-json-pp
145
145
  - ix-json-query
146
+ - ix-json-stats
146
147
  - ix-json-records-to-array
147
148
  - ix-json-remove-key
148
149
  - ix-json-replace-values
@@ -216,6 +217,7 @@ executables:
216
217
  - ix-reverse
217
218
  - ix-right
218
219
  - ix-rm
220
+ - ix-rot5
219
221
  - ix-rot13
220
222
  - ix-rot3
221
223
  - ix-rps
@@ -238,6 +240,7 @@ executables:
238
240
  - ix-show-tabs
239
241
  - ix-show-trailing-spaces
240
242
  - ix-shuffle
243
+ - ix-sigma-grep
241
244
  - ix-signature
242
245
  - ix-size
243
246
  - ix-slider
@@ -422,6 +425,7 @@ files:
422
425
  - bin/ix-json-records-to-array
423
426
  - bin/ix-json-remove-key
424
427
  - bin/ix-json-replace-values
428
+ - bin/ix-json-stats
425
429
  - bin/ix-json-template
426
430
  - bin/ix-json-to-csv
427
431
  - bin/ix-json-to-dot
@@ -494,6 +498,7 @@ files:
494
498
  - bin/ix-rm
495
499
  - bin/ix-rot13
496
500
  - bin/ix-rot3
501
+ - bin/ix-rot5
497
502
  - bin/ix-rps
498
503
  - bin/ix-ruby-constructor-arguments
499
504
  - bin/ix-ruby-methods
@@ -514,6 +519,7 @@ files:
514
519
  - bin/ix-show-tabs
515
520
  - bin/ix-show-trailing-spaces
516
521
  - bin/ix-shuffle
522
+ - bin/ix-sigma-grep
517
523
  - bin/ix-signature
518
524
  - bin/ix-size
519
525
  - bin/ix-slider
@@ -574,10 +580,10 @@ files:
574
580
  - bin/ix-wrap
575
581
  - bin/ix-xy
576
582
  - bin/ix-zebra
577
- homepage:
583
+ homepage:
578
584
  licenses: []
579
585
  metadata: {}
580
- post_install_message:
586
+ post_install_message:
581
587
  rdoc_options: []
582
588
  require_paths:
583
589
  - lib
@@ -592,8 +598,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
592
598
  - !ruby/object:Gem::Version
593
599
  version: '0'
594
600
  requirements: []
595
- rubygems_version: 3.0.6
596
- signing_key:
601
+ rubygems_version: 3.1.2
602
+ signing_key:
597
603
  specification_version: 4
598
604
  summary: ix - string manipulation tools
599
605
  test_files: []