ix-cli 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (274) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +3 -0
  3. data/VERSION +1 -0
  4. data/bin/ix +14 -0
  5. data/bin/ix-acronym +21 -0
  6. data/bin/ix-add +8 -0
  7. data/bin/ix-append +8 -0
  8. data/bin/ix-arguments +12 -0
  9. data/bin/ix-array +17 -0
  10. data/bin/ix-ascii +3 -0
  11. data/bin/ix-avg +18 -0
  12. data/bin/ix-aws-pass +17 -0
  13. data/bin/ix-banner +2 -0
  14. data/bin/ix-base +24 -0
  15. data/bin/ix-base64-to-image +6 -0
  16. data/bin/ix-basename +8 -0
  17. data/bin/ix-bash-to-md +17 -0
  18. data/bin/ix-bcat +184 -0
  19. data/bin/ix-bellgrep +17 -0
  20. data/bin/ix-bench +9 -0
  21. data/bin/ix-binary-to-text +8 -0
  22. data/bin/ix-blackbox +45 -0
  23. data/bin/ix-blackbox-html-table +86 -0
  24. data/bin/ix-blamer +23 -0
  25. data/bin/ix-box +35 -0
  26. data/bin/ix-box2 +3 -0
  27. data/bin/ix-box3 +3 -0
  28. data/bin/ix-camel +17 -0
  29. data/bin/ix-cat +7 -0
  30. data/bin/ix-catafter +18 -0
  31. data/bin/ix-catan +6 -0
  32. data/bin/ix-chain +13 -0
  33. data/bin/ix-chars +4 -0
  34. data/bin/ix-checklist +23 -0
  35. data/bin/ix-child-math +10 -0
  36. data/bin/ix-chomp +6 -0
  37. data/bin/ix-chr +6 -0
  38. data/bin/ix-class +5 -0
  39. data/bin/ix-columns +41 -0
  40. data/bin/ix-combinations +11 -0
  41. data/bin/ix-command-class +21 -0
  42. data/bin/ix-commandify +22 -0
  43. data/bin/ix-commit +9 -0
  44. data/bin/ix-confirm +47 -0
  45. data/bin/ix-constants +9 -0
  46. data/bin/ix-cp +10 -0
  47. data/bin/ix-crack +163 -0
  48. data/bin/ix-crap +26 -0
  49. data/bin/ix-crazy-case +9 -0
  50. data/bin/ix-create-cluster-nodes +15 -0
  51. data/bin/ix-csv-to-json +16 -0
  52. data/bin/ix-day +12 -0
  53. data/bin/ix-debugging +33 -0
  54. data/bin/ix-decode-base64 +8 -0
  55. data/bin/ix-dequote +3 -0
  56. data/bin/ix-df +15 -0
  57. data/bin/ix-diagram +47 -0
  58. data/bin/ix-dirname +5 -0
  59. data/bin/ix-divide +8 -0
  60. data/bin/ix-done +11 -0
  61. data/bin/ix-dot-case +15 -0
  62. data/bin/ix-downcase +5 -0
  63. data/bin/ix-dto +39 -0
  64. data/bin/ix-each +7 -0
  65. data/bin/ix-edit +21 -0
  66. data/bin/ix-emails +10 -0
  67. data/bin/ix-escape +8 -0
  68. data/bin/ix-extensions +3 -0
  69. data/bin/ix-file-exists +11 -0
  70. data/bin/ix-filename +7 -0
  71. data/bin/ix-files +9 -0
  72. data/bin/ix-first +6 -0
  73. data/bin/ix-fish-diagram +47 -0
  74. data/bin/ix-flip-flop +20 -0
  75. data/bin/ix-flow +22 -0
  76. data/bin/ix-format-ruby-hash +61 -0
  77. data/bin/ix-gauge +86 -0
  78. data/bin/ix-get-colors +520 -0
  79. data/bin/ix-gift-exchange +52 -0
  80. data/bin/ix-glitter +29 -0
  81. data/bin/ix-grep-join +4 -0
  82. data/bin/ix-group +21 -0
  83. data/bin/ix-groups +15 -0
  84. data/bin/ix-gsub +5 -0
  85. data/bin/ix-gzip-dir +33 -0
  86. data/bin/ix-hash +10 -0
  87. data/bin/ix-hashtag +12 -0
  88. data/bin/ix-hex2rgb +5 -0
  89. data/bin/ix-histogram +80 -0
  90. data/bin/ix-hls +21 -0
  91. data/bin/ix-html +3 -0
  92. data/bin/ix-human-time +3 -0
  93. data/bin/ix-hyphen +9 -0
  94. data/bin/ix-hypothesis +546 -0
  95. data/bin/ix-ids +10 -0
  96. data/bin/ix-image-generate +3 -0
  97. data/bin/ix-image-to-base64 +9 -0
  98. data/bin/ix-increments +16 -0
  99. data/bin/ix-indent +42 -0
  100. data/bin/ix-indent-to-dot +36 -0
  101. data/bin/ix-int +5 -0
  102. data/bin/ix-interpolate +5 -0
  103. data/bin/ix-ips +4 -0
  104. data/bin/ix-jd +13 -0
  105. data/bin/ix-join +15 -0
  106. data/bin/ix-js-classic-functions +9 -0
  107. data/bin/ix-json-append +17 -0
  108. data/bin/ix-json-array-to-records +10 -0
  109. data/bin/ix-json-format +31 -0
  110. data/bin/ix-json-grep +16 -0
  111. data/bin/ix-json-interpolate +17 -0
  112. data/bin/ix-json-key +40 -0
  113. data/bin/ix-json-key-value +14 -0
  114. data/bin/ix-json-keys +12 -0
  115. data/bin/ix-json-merge +11 -0
  116. data/bin/ix-json-paths +61 -0
  117. data/bin/ix-json-paths-pretty +2 -0
  118. data/bin/ix-json-pp +11 -0
  119. data/bin/ix-json-query +14 -0
  120. data/bin/ix-json-records-to-array +13 -0
  121. data/bin/ix-json-remove-key +15 -0
  122. data/bin/ix-json-replace-values +35 -0
  123. data/bin/ix-json-template +267 -0
  124. data/bin/ix-json-to-csv +19 -0
  125. data/bin/ix-json-to-dot +5 -0
  126. data/bin/ix-json-to-html-table +84 -0
  127. data/bin/ix-json-to-ruby-hash +13 -0
  128. data/bin/ix-json-to-table +21 -0
  129. data/bin/ix-json-to-table-2 +22 -0
  130. data/bin/ix-json-to-xml +1 -0
  131. data/bin/ix-json-values +13 -0
  132. data/bin/ix-jsonpp +14 -0
  133. data/bin/ix-lake +6 -0
  134. data/bin/ix-lemmatize +17 -0
  135. data/bin/ix-length +6 -0
  136. data/bin/ix-linkify +35 -0
  137. data/bin/ix-linkify-html +70 -0
  138. data/bin/ix-links +3 -0
  139. data/bin/ix-llp +247 -0
  140. data/bin/ix-llp-indent +20 -0
  141. data/bin/ix-llp2 +224 -0
  142. data/bin/ix-log +44 -0
  143. data/bin/ix-make-readable +13 -0
  144. data/bin/ix-man +14 -0
  145. data/bin/ix-math +6 -0
  146. data/bin/ix-maze +3 -0
  147. data/bin/ix-md5 +7 -0
  148. data/bin/ix-md5s +3 -0
  149. data/bin/ix-military +39 -0
  150. data/bin/ix-morse-to-text +76 -0
  151. data/bin/ix-mr-robot +13 -0
  152. data/bin/ix-multiply +8 -0
  153. data/bin/ix-mv +10 -0
  154. data/bin/ix-ncsa-date-to-timestamp +27 -0
  155. data/bin/ix-nested-list +23 -0
  156. data/bin/ix-nnjj +16 -0
  157. data/bin/ix-noeol +6 -0
  158. data/bin/ix-noise +7 -0
  159. data/bin/ix-normalize +69 -0
  160. data/bin/ix-numbers +4 -0
  161. data/bin/ix-numerate +16 -0
  162. data/bin/ix-occurrence +8 -0
  163. data/bin/ix-open +9 -0
  164. data/bin/ix-parse +17 -0
  165. data/bin/ix-pass +17 -0
  166. data/bin/ix-path +8 -0
  167. data/bin/ix-path-stats +21 -0
  168. data/bin/ix-pbcopy +9 -0
  169. data/bin/ix-pdf +4 -0
  170. data/bin/ix-percentage +103 -0
  171. data/bin/ix-permutations +12 -0
  172. data/bin/ix-pick +4 -0
  173. data/bin/ix-planning-tickets +27 -0
  174. data/bin/ix-prefix +7 -0
  175. data/bin/ix-pretty +3 -0
  176. data/bin/ix-print-and-run +15 -0
  177. data/bin/ix-psd-to-json +16 -0
  178. data/bin/ix-quote +12 -0
  179. data/bin/ix-rainbow +21 -0
  180. data/bin/ix-ramp +15 -0
  181. data/bin/ix-random-hypothesis +10 -0
  182. data/bin/ix-range +9 -0
  183. data/bin/ix-remove-colors +519 -0
  184. data/bin/ix-remove-empty-lines +12 -0
  185. data/bin/ix-remove-leading-spaces +11 -0
  186. data/bin/ix-remove-trailing-spaces +11 -0
  187. data/bin/ix-replace +6 -0
  188. data/bin/ix-replay +34 -0
  189. data/bin/ix-retab +13 -0
  190. data/bin/ix-reverse +5 -0
  191. data/bin/ix-right +3 -0
  192. data/bin/ix-rm +8 -0
  193. data/bin/ix-rot13 +9 -0
  194. data/bin/ix-rot3 +9 -0
  195. data/bin/ix-rps +50 -0
  196. data/bin/ix-ruby-constructor-arguments +7 -0
  197. data/bin/ix-ruby-methods +40 -0
  198. data/bin/ix-ruby-options +189 -0
  199. data/bin/ix-ruby-procs +40 -0
  200. data/bin/ix-ruby-put-vars +11 -0
  201. data/bin/ix-ruby-setter-methods +47 -0
  202. data/bin/ix-ruby-to-json +9 -0
  203. data/bin/ix-ruler +13 -0
  204. data/bin/ix-run +105 -0
  205. data/bin/ix-saldo +25 -0
  206. data/bin/ix-sat +10 -0
  207. data/bin/ix-scan +13 -0
  208. data/bin/ix-scrum +13 -0
  209. data/bin/ix-scrum-summary +12 -0
  210. data/bin/ix-sentence +23 -0
  211. data/bin/ix-sentencify-comments +12 -0
  212. data/bin/ix-show-tabs +5 -0
  213. data/bin/ix-show-trailing-spaces +10 -0
  214. data/bin/ix-shuffle +11 -0
  215. data/bin/ix-signature +7 -0
  216. data/bin/ix-size +9 -0
  217. data/bin/ix-slider +201 -0
  218. data/bin/ix-snake +25 -0
  219. data/bin/ix-split +9 -0
  220. data/bin/ix-stack +42 -0
  221. data/bin/ix-stack-2 +31 -0
  222. data/bin/ix-stamp +5 -0
  223. data/bin/ix-stats +11 -0
  224. data/bin/ix-stream +15 -0
  225. data/bin/ix-string-similarity +152 -0
  226. data/bin/ix-string-similarity2 +35 -0
  227. data/bin/ix-strip +6 -0
  228. data/bin/ix-substract +5 -0
  229. data/bin/ix-success +2 -0
  230. data/bin/ix-suffix +7 -0
  231. data/bin/ix-sum +10 -0
  232. data/bin/ix-swap +3 -0
  233. data/bin/ix-symlink +13 -0
  234. data/bin/ix-tab +6 -0
  235. data/bin/ix-tabify +7 -0
  236. data/bin/ix-tac +11 -0
  237. data/bin/ix-task +20 -0
  238. data/bin/ix-technical +7 -0
  239. data/bin/ix-template +48 -0
  240. data/bin/ix-text-to-binary +7 -0
  241. data/bin/ix-text-to-dot +22 -0
  242. data/bin/ix-text-to-json +16 -0
  243. data/bin/ix-text-to-morse +72 -0
  244. data/bin/ix-tick +20 -0
  245. data/bin/ix-time +6 -0
  246. data/bin/ix-times +10 -0
  247. data/bin/ix-timestamp +79 -0
  248. data/bin/ix-timestamp-sort +16 -0
  249. data/bin/ix-timestamp2 +14 -0
  250. data/bin/ix-title +2 -0
  251. data/bin/ix-to-f +6 -0
  252. data/bin/ix-to-i +6 -0
  253. data/bin/ix-to-sym +6 -0
  254. data/bin/ix-to_i +6 -0
  255. data/bin/ix-todo +11 -0
  256. data/bin/ix-tokenize-for-template +25 -0
  257. data/bin/ix-transpose +48 -0
  258. data/bin/ix-tree +19 -0
  259. data/bin/ix-trim +5 -0
  260. data/bin/ix-truncate +22 -0
  261. data/bin/ix-ts +6 -0
  262. data/bin/ix-tsv-to-json +15 -0
  263. data/bin/ix-ucwords +11 -0
  264. data/bin/ix-unescape +8 -0
  265. data/bin/ix-unhtml +8 -0
  266. data/bin/ix-upcase +5 -0
  267. data/bin/ix-url-check +25 -0
  268. data/bin/ix-urls +46 -0
  269. data/bin/ix-vim +9 -0
  270. data/bin/ix-words +9 -0
  271. data/bin/ix-wrap +10 -0
  272. data/bin/ix-xy +81 -0
  273. data/bin/ix-zebra +122 -0
  274. metadata +597 -0
data/bin/ix-histogram ADDED
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+
4
+ require 'tmpdir'
5
+ require 'optparse'
6
+
7
+ options = {}
8
+
9
+ OptionParser.new do |opts|
10
+
11
+ opts.banner = "
12
+ histogram - Creates png charts using date-time and value data from text.
13
+
14
+ Reads two numeric columns from stdin (x, y)
15
+ and creates a png graphical chart.
16
+
17
+ Usage: cat data | #{File.basename($0)} [options]
18
+ "
19
+
20
+ opts.on("-tTITLE", "--title=TITLE", "title of chart") do |v|
21
+ options[:title] = v
22
+ end
23
+
24
+ opts.on("-xTEXT", "--x-label=TEXT", "label for x axis") do |v|
25
+ options[:x_label] = v
26
+ end
27
+
28
+ opts.on("-yTEXT", "--y-label=TEXT", "label for y axis") do |v|
29
+ options[:y_label] = v
30
+ end
31
+
32
+ opts.on("-oOUTPUT_NAME", "--output-name=OUTPUT_NAME", "name of output file (example: speed_vs_time") do |v|
33
+ options[:output] = v
34
+ end
35
+
36
+ end.parse!
37
+
38
+ unless options[:title]
39
+ options[:title] = 'title'
40
+ end
41
+
42
+ unless options[:x_label]
43
+ options[:x_label] = 'x'
44
+ end
45
+
46
+ unless options[:y_label]
47
+ options[:y_label] = 'y'
48
+ end
49
+
50
+ unless options[:output]
51
+ options[:output] = 'output'
52
+ end
53
+
54
+ Dir.mktmpdir do |dir|
55
+
56
+ data_path = "#{dir}/histogram.data"
57
+ script_path = "#{dir}/script.gnuplot"
58
+
59
+ File.open(data_path, 'w+') do |file|
60
+ STDIN.each_line do |line|
61
+ file.puts line
62
+ end
63
+ end
64
+
65
+ File.open(script_path, 'w+') do |script|
66
+ script.puts "set term png size 800,600"
67
+ script.puts "set style histogram clustered"
68
+ script.puts "set grid"
69
+ script.puts "set timestamp"
70
+ script.puts "set output \"#{options[:output]}.png\""
71
+ script.puts "plot for [COL=2:4] '#{data_path}' using COL:xticlabels(1) title columnheader"
72
+ script.puts "plot for [COL=2:4] '#{data_path}' using COL:xticlabels(1) title columnheader(2), for [i=3:22] '' using i title columnheader(i)"
73
+ script.puts "quit"
74
+ end
75
+
76
+ system "gnuplot #{script_path}"
77
+ puts "open #{options[:output]}.png"
78
+
79
+ end
80
+
data/bin/ix-hls ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #
4
+ # options
5
+ #
6
+ # line ix-highlight-line highlight a specific line
7
+ # vertical ix-highlight-vertical highlight a particular column
8
+ # highlight ix-highlight-match highlight whatever matches a regex
9
+ #
10
+
11
+
12
+ abort 'No pattern given' if ARGV[0].nil?
13
+
14
+ trap('SIGINT') { }
15
+
16
+ $stdout.sync = true
17
+
18
+ STDIN.each_line do |line|
19
+ puts line.gsub(/(#{ARGV[0]})/i) { |x| "#{$1}" }
20
+ end
21
+
data/bin/ix-html ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ix bcat | ix prefix '<pre>' | ix suffix '</pre>'
data/bin/ix-human-time ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ puts Time.now.strftime("%Y%m%d%H%M%S")
data/bin/ix-hyphen ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ STDIN.each_line do |line|
4
+ line = line.chomp
5
+ line.gsub!(/\W+/, ' ')
6
+ line.gsub!(/\s+/, '-')
7
+ line.gsub!(/^[-]+|[-]+$/, '')
8
+ puts line.downcase
9
+ end
data/bin/ix-hypothesis ADDED
@@ -0,0 +1,546 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'fileutils'
5
+ require 'optparse'
6
+ require 'ostruct'
7
+ require 'isna'
8
+
9
+ # Percentage bar.
10
+ #
11
+ # items = (1..100).to_a
12
+ # size = (10..100).to_a
13
+ # length = size.shuffle.first
14
+ #
15
+ # items.each do |item|
16
+ # puts Percentage.new(100, item, length).to_bar
17
+ # end
18
+ #
19
+ class Percentage
20
+ def initialize(product, divisor, scale = 100)
21
+ @product = product
22
+ @scale = scale - 5
23
+ @pre_percentage = (divisor * @scale / product).to_f
24
+ @percentage = (@pre_percentage * 100 / @scale)
25
+ end
26
+ def to_i
27
+ @percentage.to_i
28
+ end
29
+ def to_f
30
+ @percentage.to_f
31
+ end
32
+
33
+ # 0 ~ 50 green
34
+ # 50 ~ 80 yellow
35
+ # 80 ~ 100 red
36
+ def to_bar(color = true, bar = '|')
37
+ filling = (bar * @pre_percentage.to_i)
38
+ padding = 0
39
+ if color
40
+ if to_i >= 0 and to_i < 50
41
+ filling = "" + (bar * @pre_percentage.to_i) + ""
42
+ end
43
+ if to_i >= 50 and to_i < 80
44
+ filling = "" + (bar * @pre_percentage.to_i) + ""
45
+ end
46
+ if to_i >= 80
47
+ filling = "" + (bar * @pre_percentage.to_i) + ""
48
+ end
49
+ if filling.size > 0
50
+ padding = 13
51
+ end
52
+ end
53
+ bindings = [filling, to_f, '%']
54
+ "[%-#{@scale + padding}s%5.1f%s]" % bindings
55
+ end
56
+ end
57
+
58
+ # Usage:
59
+ #
60
+ # sample = [2, 4, 4, 4, 5, 5, 7, 9]
61
+ # puts sample.to_stat
62
+ #
63
+ # #=> mean: 5, standard deviation: 2.0
64
+ #
65
+ # http://easycalculation.com/statistics/standard-deviation.php
66
+ # http://en.wikipedia.org/wiki/Standard_deviation
67
+ #
68
+ class Array
69
+
70
+ def mean
71
+ product / size
72
+ end
73
+
74
+ def product
75
+ sum
76
+ end
77
+
78
+ def normalize(scale_min, scale_max)
79
+ map do |number|
80
+ divisor = (number - min) * (scale_max - scale_min)
81
+ dividend = max - min
82
+ divisor / dividend
83
+ end
84
+ end
85
+
86
+ def median
87
+ return size[0] if size == 1
88
+ self[(size + 1) / 2]
89
+ end
90
+
91
+ def sum_of_squares(avg = nil)
92
+ avg = mean unless avg
93
+ sqares = map do |number|
94
+ result = number - avg
95
+ result ** 2
96
+ end
97
+ sqares.sum
98
+ end
99
+
100
+ def variance(minus = 0)
101
+ sum_of_squares / (size - minus)
102
+ end
103
+
104
+ def standard_deviation
105
+ Math.sqrt(variance(1.5))
106
+ end
107
+
108
+ def population_standard_deviation
109
+ Math.sqrt(variance(0))
110
+ end
111
+
112
+ def sample_standard_deviation
113
+ med = median
114
+ sqr = map do |number|
115
+ result = number - med
116
+ result ** 2
117
+ end
118
+ Math.sqrt(sqr.mean)
119
+ end
120
+
121
+ def sum
122
+ inject do |cumulative, value|
123
+ cumulative += value
124
+ end
125
+ end
126
+
127
+ def sigmas(length, sigma)
128
+ avg = mean
129
+ list = []
130
+ length.times { |n| list << avg - ((n + 1) * sigma) }
131
+ list << avg
132
+ length.times { |n| list << avg + ((n + 1) * sigma) }
133
+ list.sort
134
+ end
135
+
136
+ def to_bell(text, standard_deviations_to_show = 3, base = :population, kazu_dev = 1, percentage_scale, hide)
137
+
138
+ if base == :population
139
+ sigma = population_standard_deviation
140
+ end
141
+
142
+ if base == :sample
143
+ sigma = sample_standard_deviation
144
+ end
145
+
146
+ if base == :normal
147
+ sigma = standard_deviation
148
+ end
149
+
150
+ total = size
151
+ avg = mean
152
+
153
+ sigmas_copy = sigmas(standard_deviations_to_show * kazu_dev, sigma / kazu_dev)
154
+
155
+ puts ''
156
+ puts "#{text} Normal distribution for a #{base} standard distribution."
157
+ puts " (#{sigma})"
158
+ puts '-' * 80
159
+ groups = group_by do |number|
160
+ return_value = nil
161
+ sigmas_copy.each_with_index do |sigma, index|
162
+ if number < sigma
163
+ if number > sigmas_copy[index -1]
164
+ return_value = sigma
165
+ end
166
+ end
167
+ unless return_value
168
+ if number == sigma
169
+ return_value = sigma
170
+ end
171
+ end
172
+ end
173
+ return_value
174
+ end
175
+
176
+ template = "%6s %15s %6s %s"
177
+ headers = ['sigma', 'deviation', 'samples', 'percentage']
178
+ puts template % headers
179
+ template = "%6s %s %s %s %s"
180
+
181
+ the_min = sigmas_copy.map do |sigma|
182
+ ((groups[sigma] ? groups[sigma].size : 0.0) / total.to_f) * 100
183
+ end.min
184
+
185
+ the_max = sigmas_copy.map do |sigma|
186
+ ((groups[sigma] ? groups[sigma].size : 0.0) / total.to_f) * 100
187
+ end.max
188
+
189
+ puts [the_min, the_max].inspect
190
+
191
+ sigmas_copy.each_with_index do |sigma, index|
192
+
193
+ size = groups[sigma] ? groups[sigma].size : 0
194
+
195
+ if hide
196
+ next if size == 0
197
+ end
198
+
199
+ bell_line = []
200
+ std_dev_ruler = "%3.3f" % ((index - sigmas_copy.size / 2) / kazu_dev.to_f)
201
+ if std_dev_ruler == '0.000'
202
+ bell_line << ' ' + std_dev_ruler.to_ansi.green.to_s
203
+ else
204
+ bell_line << std_dev_ruler
205
+ end
206
+
207
+ if sigma == avg
208
+ bell_line << ("%15.4f" % [sigma.to_s]).to_ansi.green.to_s
209
+ else
210
+ bell_line << ("%15.4f" % [sigma.to_s])
211
+ end
212
+
213
+ if size > 0
214
+ bell_line << (size.to_s.ljust(10, ' ').to_ansi.green.to_s)
215
+ else
216
+ bell_line << '-'.ljust(10, ' ')
217
+ end
218
+
219
+ bell_line << ("%6.2f%% " % [(size.to_f / total.to_f) * 100]).to_s
220
+
221
+ # puts groups[sigma].inspect
222
+
223
+ bn = [
224
+ the_min,
225
+ (size.to_f / total.to_f) * 100,
226
+ the_max
227
+ ]
228
+
229
+ an = bn.normalize(
230
+ 0,
231
+ percentage_scale
232
+ )
233
+
234
+ # bell_line << Percentage.new(total, size, percentage_scale).to_bar
235
+
236
+ case (std_dev_ruler).to_f
237
+ when 0.000
238
+ bell_line << '|' + ('|' * an[1]).to_s.to_ansi.pink.to_s
239
+ when 0..1
240
+ bell_line << '|' + ('|' * an[1]).to_s.to_ansi.green.to_s
241
+ when -1..0
242
+ bell_line << '|' + ('|' * an[1]).to_s.to_ansi.green.to_s
243
+ when 1..2
244
+ bell_line << '|' + ('|' * an[1]).to_s.to_ansi.yellow.to_s
245
+ when -2..1
246
+ bell_line << '|' + ('|' * an[1]).to_s.to_ansi.yellow.to_s
247
+ when 2..3
248
+ bell_line << '|' + ('|' * an[1]).to_s.to_ansi.red.to_s
249
+ when -3..2
250
+ bell_line << '|' + ('|' * an[1]).to_s.to_ansi.red.to_s
251
+ when 3..100
252
+ bell_line << '|' + ('|' * an[1]).to_s.to_ansi.cyan.blink.to_s
253
+ when -3..-100
254
+ bell_line << '|' + ('|' * an[1]).to_s.to_ansi.cyan.blink.to_s
255
+ else
256
+ bell_line << '|' + ('|' * an[1]).to_s.to_ansi.yellow.to_s
257
+ end
258
+
259
+ puts template % bell_line
260
+
261
+ end
262
+ if groups[nil]
263
+ puts "#{groups[nil].size} outliers: => #{groups[nil].sort.inspect}"
264
+ end
265
+ end
266
+
267
+ def to_stat(padding = 15)
268
+ symbols = ['x', 'µ', 'σ', 'P', 'S', 'VP', 'VS', 'N', '∑x']
269
+ template = symbols.map { |symbol| "#{symbol}: %-#{padding}.2f" }
270
+ template = template.join(" ")
271
+ bindings = [
272
+ median,
273
+ mean,
274
+ standard_deviation,
275
+ population_standard_deviation,
276
+ sample_standard_deviation,
277
+ variance(1),
278
+ variance(0),
279
+ size,
280
+ sum
281
+ ]
282
+ template % bindings
283
+ end
284
+
285
+ end
286
+
287
+ # =============================================================================
288
+
289
+ def print_header(title)
290
+ puts ''
291
+ puts title
292
+ puts '-' * 80
293
+ end
294
+
295
+ # =============================================================================
296
+
297
+ def print_help
298
+ puts 'Hypothesis crunches data and performs statistical analysis.'
299
+ puts ''
300
+ puts 'USAGE'
301
+ puts ''
302
+ puts ' $ cat some_file | ix hypothesis'
303
+ puts ''
304
+ puts 'INPUT'
305
+ puts ''
306
+ puts ' Send data to STDIN in a key value format.'
307
+ puts ' KEYS must be strings no bigger than ten chars'
308
+ puts ' VALUES must be numeric floats or integers'
309
+ puts ' each line must be KEY VALUE separated by a space in between'
310
+ puts ' then terminate with an EOL'
311
+ puts ''
312
+ puts 'EXAMPLE'
313
+ puts ''
314
+ puts ' Key value format is explained below'
315
+ puts ' "|" char means begining of line in a file.'
316
+ puts ''
317
+ puts ' -----------------------------------'
318
+ puts ' |group-a 1'
319
+ puts ' |group-a 3'
320
+ puts ' |group-b 2'
321
+ puts ' |group-b 1'
322
+ puts ' |group-c 3'
323
+ puts ' |group-c 5'
324
+ puts ''
325
+ puts ' Heva fun!'
326
+ puts ''
327
+ end
328
+
329
+ # =============================================================================
330
+
331
+ @configuration = {}
332
+
333
+ @configuration[:kazus_deviation] = 1
334
+ @configuration[:sigma] = 3
335
+ @configuration[:distribution] = :normal
336
+ @configuration[:scale] = 34
337
+ @configuration[:hide_points] = false
338
+ @configuration[:print_statistics] = false
339
+
340
+ OptionParser.new do |opts|
341
+
342
+ opts.banner = "USAGE: #{File.basename($0)} [OPTIONS]"
343
+
344
+ help_string = 'Expand the bell to expose kazu\'s deviation.'
345
+ opts.on('-k', '--kazus-deviation [N]', OptionParser::DecimalInteger, help_string) do |value|
346
+ @configuration[:kazus_deviation] = value
347
+ end
348
+
349
+ help_string = 'How many standard deviations (sigmas) to show'
350
+ opts.on('-s', '--sigma [N]', OptionParser::DecimalInteger, help_string) do |value|
351
+ @configuration[:sigma] = value
352
+ end
353
+
354
+ help_string = 'Render analysis as a normal standard deviation'
355
+ opts.on('-n', '--normal', help_string) do |value|
356
+ @configuration[:distribution] = :normal
357
+ end
358
+
359
+ help_string = 'Render analysis as a population standard deviation'
360
+ opts.on('-p', '--population', help_string) do |value|
361
+ @configuration[:distribution] = :population
362
+ end
363
+
364
+ help_string = 'Render analysis as a sample standard deviation'
365
+ opts.on('-a', '--sample', help_string) do |value|
366
+ @configuration[:distribution] = :sample
367
+ end
368
+
369
+ help_string = 'Scale, expand and show more detail on probabilistic bar data.'
370
+ opts.on('-b', '--bars [N]', OptionParser::DecimalInteger, help_string) do |value|
371
+ @configuration[:scale] = value.to_i
372
+ end
373
+
374
+ help_string = 'Hide away points that dont have data.'
375
+ opts.on('-i', '--hide-points', help_string) do |value|
376
+ @configuration[:hide_points] = true
377
+ end
378
+
379
+ help_string = 'Print Statistical Breakdown.'
380
+ opts.on('-r', '--print-statistics', help_string) do |value|
381
+ @configuration[:print_statistics] = true
382
+ end
383
+
384
+ opts.on('-e', '--example', 'Give me more iformation about this program') do |value|
385
+ print_help
386
+ exit 0
387
+ end
388
+
389
+ end.parse!
390
+
391
+ # =============================================================================
392
+
393
+ $stdin.sync = true
394
+
395
+ sample = { }
396
+
397
+ STDIN.each do |line|
398
+ key, value = line.split(/\s+/)
399
+ sample[key] ||= {}
400
+ sample[key][:data] ||= []
401
+ if sample[key][:total]
402
+ sample[key][:total] += value.to_f
403
+ else
404
+ sample[key][:total] = value.to_f
405
+ end
406
+ sample[key][:data] << value.to_f
407
+ end
408
+
409
+ print_header "Report Generated on: #{Time.now}"
410
+
411
+ grand_total = 0
412
+ number_of_groups = 0
413
+ categories = sample.keys.sort
414
+
415
+ categories.each do |category|
416
+ grand_total += sample[category][:total]
417
+ number_of_groups += 1
418
+ end
419
+
420
+ if @configuration[:print_statistics]
421
+
422
+ print_header 'Median'.to_ansi.green.to_s
423
+ categories.each do |category|
424
+ puts "%-60s %19.6f" % [category, sample[category][:data].median]
425
+ end
426
+
427
+ print_header 'Mean'.to_ansi.green.to_s
428
+ categories.each do |category|
429
+ puts "%-60s %19.6f" % [category, sample[category][:data].mean]
430
+ end
431
+
432
+ print_header 'Standard Deviation'.to_ansi.green.to_s
433
+ categories.each do |category|
434
+ puts "%-60s %19.6f" % [category, sample[category][:data].standard_deviation]
435
+ end
436
+
437
+ print_header 'Population Standard Deviation'.to_ansi.green.to_s
438
+ categories.each do |category|
439
+ puts "%-60s %19.6f" % [category, sample[category][:data].population_standard_deviation]
440
+ end
441
+
442
+ print_header 'Sample Standard Deviation'.to_ansi.green.to_s
443
+ categories.each do |category|
444
+ puts "%-60s %19.6f" % [category, sample[category][:data].sample_standard_deviation]
445
+ end
446
+
447
+ print_header 'Variance of a Population'.to_ansi.green.to_s
448
+ categories.each do |category|
449
+ puts "%-60s %19.6f" % [category, sample[category][:data].variance(1)]
450
+ end
451
+
452
+ print_header 'Variance of a Sample'.to_ansi.green.to_s
453
+ categories.each do |category|
454
+ puts "%-60s %19.6f" % [category, sample[category][:data].variance(0)]
455
+ end
456
+
457
+ print_header 'Count of samples'.to_ansi.green.to_s
458
+ categories.each do |category|
459
+ puts "%-60s %19.6f" % [category, sample[category][:data].size]
460
+ end
461
+
462
+ print_header 'Product'.to_ansi.green.to_s
463
+ categories.each do |category|
464
+ puts "%-60s %19.6f" % [category, sample[category][:data].sum]
465
+ end
466
+
467
+ print_header 'Percentage breakdown per category'
468
+ categories.each do |category|
469
+ percentage = Percentage.new(grand_total, sample[category][:data].sum, 66)
470
+ # puts "%-10s %-s" % [category, percentage.to_bar]
471
+ puts "%-s %s" % [percentage.to_bar, category]
472
+ end
473
+ end
474
+
475
+ categories.each do |category|
476
+ sample[category][:data].to_bell(
477
+ category,
478
+ @configuration[:sigma],
479
+ @configuration[:distribution],
480
+ @configuration[:kazus_deviation],
481
+ @configuration[:scale],
482
+ @configuration[:hide_points],
483
+ )
484
+ end
485
+
486
+ # All ANOVA goes below.
487
+ # ==============================================================================
488
+
489
+ if sample.size < 2
490
+ print_header "You must provide at least two groups for an anova calculation."
491
+ exit 0
492
+ end
493
+
494
+ if sample.map { |k, v| v[:data].size }.uniq.size > 1
495
+ print_header "All groups must have the same size in order for a reliable anova calculation."
496
+ exit 0
497
+ end
498
+
499
+ if sample.map { |k, v| v[:data].size }.all? { |data_size| data_size == 1 }
500
+ print_header "You must provide more samples for each category."
501
+ exit 0
502
+ end
503
+
504
+ # In anova we first grab the grand mean.
505
+ # eaither by individually or altogether.
506
+
507
+ sum_of_sizes = 0
508
+ sample.each do |name, data|
509
+ sum_of_sizes += data[:data].size
510
+ end
511
+ grand_mean = grand_total / sum_of_sizes
512
+
513
+ # Next we want to extract the sum of squares using the grand mean.
514
+ sum_of_squares_total = 0
515
+ sum_of_squares_within = 0
516
+ sum_of_squares_between = 0
517
+
518
+ sample.each do |name, data|
519
+ sum_of_squares_total += data[:data].sum_of_squares(grand_mean)
520
+ sum_of_squares_within += data[:data].sum_of_squares
521
+ sum_of_squares_between += (data[:data].size * ((data[:data].mean - grand_mean) ** 2))
522
+ end
523
+
524
+ degrees_of_freedom_between = number_of_groups - 1;
525
+ degrees_of_freedom_within = number_of_groups * (sample.first[1][:data].size - 1);
526
+
527
+ f_test = (sum_of_squares_between / degrees_of_freedom_between) / (sum_of_squares_within / degrees_of_freedom_within)
528
+
529
+ output = {
530
+ :number_of_groups => number_of_groups,
531
+ :grand_total => grand_total,
532
+ :grand_mean => grand_mean,
533
+ :sum_of_squares_total => sum_of_squares_total,
534
+ :sum_of_squares_within => sum_of_squares_within,
535
+ :sum_of_squares_between => sum_of_squares_between,
536
+ :degrees_of_freedom_within => degrees_of_freedom_within,
537
+ :degrees_of_freedom_between => degrees_of_freedom_between,
538
+ :f_test => f_test,
539
+ # :f_bars => '|' * f_test,
540
+ }
541
+
542
+ print_header 'ANOVA Breakdown.'
543
+ output.keys.map { |key| key.to_s }.sort.each do |key|
544
+ puts "#{key.to_s.ljust(40, '.')} #{output[key.to_sym].to_s}"
545
+ end
546
+
data/bin/ix-ids ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+
3
+
4
+ if [ "$1" == "" ]; then
5
+ regex='\d+'
6
+ else
7
+ regex="$1"
8
+ fi
9
+
10
+ ix scan "$regex" | ix array | ix prefix 'ids = ' | par
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env bash
2
+
3
+ echo "https://placeholdit.imgix.net/~text?txtsize=33&txt=$1%C3%97$2&w=$1&h=$2"
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'base64'
4
+
5
+ template = '<img src=\"data:image/png;base64,/%s\" />'
6
+
7
+ base64 = Base64.encode64(STDIN.read)
8
+
9
+ puts template % [base64]
data/bin/ix-increments ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ NUMBER_REGEX = /\d+/
4
+
5
+ previous_number = nil
6
+
7
+ STDIN.each_line do |line|
8
+ next unless NUMBER_REGEX =~ line
9
+ number = line.scan(NUMBER_REGEX).first.to_f
10
+ if previous_number == nil
11
+ previous_number = number
12
+ end
13
+ puts "#{number} #{number - previous_number}"
14
+ previous_number = number
15
+ end
16
+