ix-cli 0.0.1

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.
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-slider ADDED
@@ -0,0 +1,201 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # TODO: decide if we should load current_value from flag or file override.
4
+ # TODO: allow user to type numbers to jump to a given part of the slider.
5
+
6
+ require 'io/console'
7
+ require 'timeout'
8
+ require 'isna'
9
+ require 'optparse'
10
+
11
+ $options = {}
12
+
13
+ # $options[:left_arrow] ||= "\e[D"
14
+ # $options[:right_arrow] ||= "\e[C"
15
+ $options[:left_arrow] ||= 'h'
16
+ $options[:right_arrow] ||= 'l'
17
+ $options[:up_arrow] ||= 'k'
18
+ $options[:down_arrow] ||= 'j'
19
+ $options[:bar_width] ||= 40
20
+ $options[:minimum_value] ||= 0
21
+ $options[:maximum_value] ||= 100
22
+ $options[:current_value] ||= 50
23
+ $options[:running] = true
24
+
25
+ OptionParser.new do |opts|
26
+
27
+ opts.banner = "Usage: #{File.basename($0)} [OPTIONS]"
28
+
29
+ opts.on('-r', '--right-arrow [KEY]', 'Keyboard key to use as a right arrow.') do |value|
30
+ $options[:right_arrow] = value
31
+ end
32
+
33
+ opts.on('-l', '--left-arrow [KEY]', 'Keyboard key to use as a left arrow.') do |value|
34
+ $options[:left_arrow] = value
35
+ end
36
+
37
+ opts.on('-u', '--up-arrow [KEY]', 'Keyboard key to use as an up arrow.') do |value|
38
+ $options[:up_arrow] = value
39
+ end
40
+
41
+ opts.on('-d', '--down-arrow [KEY]', 'Keyboard key to use as a down arrow.') do |value|
42
+ $options[:down_arrow] = value
43
+ end
44
+
45
+ opts.on('-b', '--bar-width [NUMBER]', 'Number of chars to use for bar the bar width.') do |value|
46
+ $options[:bar_width] = value.to_i
47
+ end
48
+
49
+ opts.on('-m', '--minimum-value [NUMBER]', 'Minimum value of slider.') do |value|
50
+ $options[:minimum_value] = value.to_i
51
+ end
52
+
53
+ opts.on('-a', '--maximum-value [NUMBER]', 'Maximum value of slider.') do |value|
54
+ $options[:maximum_value] = value.to_i
55
+ end
56
+
57
+ opts.on('-c', '--current-value [NUMBER]', 'Current value of slider.') do |value|
58
+ $options[:current_value] = value.to_i
59
+ end
60
+
61
+ opts.on('-f', '--file [FILE]', 'The filename where the value of slider will be written to.') do |value|
62
+ $options[:file] = value
63
+ end
64
+
65
+ end.parse!
66
+
67
+ required_options = [
68
+ :left_arrow,
69
+ :right_arrow,
70
+ :up_arrow,
71
+ :down_arrow,
72
+ :bar_width,
73
+ :minimum_value,
74
+ :maximum_value,
75
+ :current_value,
76
+ :file
77
+ ]
78
+
79
+ required_options.each do |option|
80
+ unless $options[option]
81
+ $stderr.puts "Can not run #{option.to_s} was not given."
82
+ exit 1
83
+ end
84
+ end
85
+
86
+ def readkey
87
+ c = ''
88
+ result = ''
89
+ $stdin.raw do |stdin|
90
+ c = stdin.getc
91
+ result << c
92
+ if c == "\e"
93
+ begin
94
+ while (c = Timeout::timeout(0.0001) { stdin.getc })
95
+ result << c
96
+ end
97
+ rescue Timeout::Error
98
+ # no action required
99
+ end
100
+ end
101
+ end
102
+ result
103
+ end
104
+
105
+ def legend
106
+ labels = {
107
+ $options[:right_arrow] => 'right',
108
+ $options[:left_arrow] => 'left',
109
+ $options[:up_arrow] => 'finish',
110
+ $options[:down_arrow] => 'start',
111
+ 'q' => 'quit'
112
+ }
113
+ parts = labels.keys.sort.map do |key|
114
+ "#{key.to_ansi.green.to_s} = #{labels[key]}"
115
+ end
116
+ parts * ', '
117
+ end
118
+
119
+ def print_slider(min, max, needle, open, close, spacer, marker)
120
+ print open
121
+ per_abstract_unit = (needle.to_f / max.to_f * $options[:bar_width])
122
+ print rainbow(marker, per_abstract_unit, $options[:bar_width])
123
+ print (spacer * ($options[:bar_width] - per_abstract_unit.to_i ))
124
+ print close
125
+ print " value: #{needle} "
126
+ end
127
+
128
+ def rainbow(marker, current, max)
129
+ result = (marker * current)
130
+ percent = (100 / $options[:bar_width].to_f * current)
131
+ case percent
132
+ when 0..25
133
+ return result
134
+ when 25..50
135
+ return result.to_ansi.green.to_s
136
+ when 50..75
137
+ return result.to_ansi.yellow.to_s
138
+ when 75..100
139
+ return result.to_ansi.red.to_s
140
+ end
141
+ end
142
+
143
+ def update_file(file, value)
144
+ File.open(file, 'w+') do |file|
145
+ file.puts value
146
+ end
147
+ end
148
+
149
+ $stdout.sync = true
150
+ puts legend
151
+
152
+ if File.exists?($options[:file])
153
+ $options[:current_value] = File.read($options[:file]).to_i
154
+ end
155
+
156
+ Thread.new do
157
+ loop do
158
+ update_file($options[:file], $options[:current_value])
159
+ sleep 0.5
160
+ break unless $options[:running]
161
+ end
162
+ end
163
+
164
+ loop do
165
+ char = readkey
166
+ if char == 'q'
167
+ puts 'bye.'
168
+ $options[:running] = false
169
+ break
170
+ end
171
+ if char == $options[:right_arrow]
172
+ if ($options[:current_value] + 1) <= $options[:maximum_value]
173
+ $options[:current_value] += 1
174
+ end
175
+ end
176
+ if char == $options[:left_arrow]
177
+ if ($options[:current_value] - 1) >= $options[:minimum_value]
178
+ $options[:current_value] -= 1
179
+ end
180
+ end
181
+ if char == $options[:up_arrow]
182
+ $options[:current_value] = $options[:maximum_value]
183
+ end
184
+ if char == $options[:down_arrow]
185
+ $options[:current_value] = $options[:minimum_value]
186
+ end
187
+
188
+ print "\b" * 5000
189
+
190
+ print_slider(
191
+ $options[:minimum_value],
192
+ $options[:maximum_value],
193
+ $options[:current_value],
194
+ '[',
195
+ ']',
196
+ ' ',
197
+ '|'
198
+ )
199
+
200
+ end
201
+
data/bin/ix-snake ADDED
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ WORDS_REGEX = /\w+/
4
+ UPPER_CASE_WORDS = /([A-Z])/
5
+ SPACE_PADDING = /^\s+/
6
+ STARTS_WITH_UPPERCASE = /\s*[A-Z]/
7
+
8
+ starts_with_uppercase = false
9
+
10
+ STDIN.each_line do |line|
11
+ line.chomp!
12
+ if line =~ STARTS_WITH_UPPERCASE
13
+ starts_with_uppercase = true
14
+ end
15
+ line.gsub!(UPPER_CASE_WORDS, ' \1')
16
+ padding = line.scan(SPACE_PADDING)[0].to_s
17
+ words = line.scan(WORDS_REGEX)
18
+
19
+ if starts_with_uppercase
20
+ padding = padding[1..(padding.size - 1)]
21
+ end
22
+
23
+ puts padding + words.map { |word| word.downcase } * '_'
24
+ end
25
+
data/bin/ix-split ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ STDIN.each_line do |line|
4
+ line.chomp.split(Regexp.new(ARGV[0])).each do |chunk|
5
+ puts chunk
6
+ end
7
+ end
8
+
9
+
data/bin/ix-stack ADDED
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ if ARGV[0]
4
+ Dir.chdir ARGV[0]
5
+ end
6
+
7
+ STDIN.each do |line|
8
+ chunks = line.split(':')
9
+ file = chunks[0]
10
+ line_number = chunks[1].to_i
11
+ spacer = file.scan(/^\s*/)[0]
12
+ file.gsub!(/^\s+/, '')
13
+ unless File.exists? file
14
+ puts line
15
+ next
16
+ end
17
+
18
+ if File.directory? file
19
+ puts line
20
+ next
21
+ end
22
+
23
+ puts ''
24
+ puts line.chomp
25
+ puts "#{spacer}vim +#{line_number} #{file}"
26
+ data = File.read(file)
27
+ counter = 0
28
+ data.each_line do |line|
29
+ counter += 1
30
+ if counter > line_number -10
31
+ if counter < line_number +10
32
+ if counter == line_number
33
+ puts "#{spacer}" + counter.to_s.rjust(8, ' ') + "| #{line.chomp}"
34
+ else
35
+ puts spacer +counter.to_s.rjust(8, ' ') + "| #{line}"
36
+ end
37
+ end
38
+ end
39
+ end
40
+
41
+ end
42
+
data/bin/ix-stack-2 ADDED
@@ -0,0 +1,31 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'isna'
4
+
5
+ STDIN.each_line do |stack_line|
6
+ filepath, line = stack_line.split(':')
7
+ puts ''
8
+ puts '-' * 80
9
+ puts "file: #{filepath}"
10
+ puts "line: #{line}"
11
+
12
+ line = line.to_i
13
+ range_left = ((line - 5)..line).to_a
14
+ range_right = (line..(line + 5)).to_a
15
+ full_range = (range_left + range_right).sort
16
+
17
+ if File.exists?(filepath)
18
+ file_line = 0
19
+ File.read(filepath).each_line do |fline|
20
+ file_line += 1
21
+ if full_range.include?(file_line)
22
+ if line == file_line
23
+ r = "%10.f | %s" % [file_line, fline]
24
+ puts r.chomp.to_ansi.red.to_s
25
+ else
26
+ puts "%10.f | %s" % [file_line, fline]
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
data/bin/ix-stamp ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ STDIN.each_line do |line|
4
+ puts "#{'%20.6f' % Time.now.to_f} #{line}"
5
+ end
data/bin/ix-stats ADDED
@@ -0,0 +1,11 @@
1
+ #!/bin/sh
2
+
3
+ echo "sum\tcount\taverage\tmedian\tmin\tmax"
4
+
5
+ sort -n |
6
+ awk 'BEGIN{c=0;sum=0;}\
7
+ /^[^#]/{a[c++]=$1;sum+=$1;}\
8
+ END{ave=sum/c;\
9
+ if((c%2)==1){median=a[int(c/2)];}\
10
+ else{median=(a[c/2]+a[c/2-1])/2;}\
11
+ print sum,"\t",c,"\t",ave,"\t",median,"\t",a[0],"\t",a[c-1]}'
data/bin/ix-stream ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ chunks = ARGV[0].to_i
4
+ interval = ARGV[1].to_i
5
+ counter = 0
6
+
7
+ STDIN.each_line do |line|
8
+ counter += 1
9
+ puts line.chomp
10
+
11
+ if counter == chunks
12
+ counter = 0
13
+ sleep interval
14
+ end
15
+ end
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'optparse'
4
+ require 'ostruct'
5
+
6
+ configuration = OpenStruct.new
7
+
8
+ OptionParser.new do |opts|
9
+
10
+ opts.banner = "Find similarity in a set of strings."
11
+ opts.separator ''
12
+ opts.separator "Usage: #{File.basename($0)} [OPTIONS]"
13
+ opts.separator ''
14
+
15
+ configuration.group = false
16
+ configuration.threshold = 50
17
+ configuration.summary = false
18
+
19
+ description = "Group input in batches and process each individually (faster)"
20
+ opts.on("-g", "--group", description) do |v|
21
+ configuration.group = v
22
+ end
23
+
24
+ description = "Limit the number of results by threshold, default is 50"
25
+ opts.on("-t", "--threshhold [NUMBER]", OptionParser::DecimalNumeric, description) do |v|
26
+ configuration.threshold = v
27
+ end
28
+
29
+ description = "Print a Summary of the groups found"
30
+ opts.on("-s", "--summary", description) do |v|
31
+ configuration.summary = v
32
+ end
33
+
34
+
35
+ opts.separator ''
36
+
37
+ end.parse!
38
+
39
+ # puts configuration.inspect
40
+
41
+ class Array
42
+ def product
43
+ inject do |cumulative, value|
44
+ cumulative += value
45
+ end
46
+ end
47
+ end
48
+
49
+ class String
50
+ def to_a
51
+ array = []
52
+ size.times do |n|
53
+ array << self[n]
54
+ end
55
+ array
56
+ end
57
+
58
+ def scores(other_string)
59
+ longest_string = nil
60
+ if other_string.size > self.size
61
+ longest_string = other_string
62
+ shortest_string = self
63
+ else
64
+ longest_string = self
65
+ shortest_string = other_string
66
+ end
67
+ scores = longest_string.to_a.map do |char|
68
+ 0
69
+ end
70
+ shortest_string.size.times do |index|
71
+ if shortest_string[index] == longest_string[index]
72
+ scores[index] = 1
73
+ end
74
+ end
75
+ scores
76
+ end
77
+
78
+ def similarity(other_string)
79
+ scores(other_string).product * 100.0 / size
80
+ end
81
+ end
82
+
83
+ class TargetString
84
+ attr_accessor :evaluated
85
+ attr_accessor :data
86
+ def to_s
87
+ data
88
+ end
89
+ end
90
+
91
+ # client
92
+
93
+ strings = []
94
+
95
+ STDIN.each_line do |line|
96
+ next if line.chomp == ''
97
+ strings << line.chomp
98
+ end
99
+
100
+ strings.sort! do |n1, n2|
101
+ n1.size <=> n2.size
102
+ end
103
+
104
+ strings.reverse!
105
+
106
+ strings.map! do |string|
107
+ target_string = TargetString.new
108
+ target_string.evaluated = false
109
+ target_string.data = string
110
+ target_string
111
+ end
112
+
113
+ if configuration.group
114
+ groups = strings.group_by do |string|
115
+ string.data.size
116
+ end
117
+ else
118
+ groups = { 0 => strings }
119
+ end
120
+
121
+ counter = 0
122
+ groups.each do |key, group|
123
+ group.each do |string_1|
124
+ counter = 0
125
+ unless string_1.evaluated
126
+ if configuration.summary
127
+ summary_string = string_1.to_s
128
+ else
129
+ puts "****>>" + string_1.to_s
130
+ end
131
+ end
132
+ string_1.evaluated = true
133
+ group.each do |string_2|
134
+ next if string_2.evaluated
135
+ similarity = string_1.to_s.similarity(string_2.to_s)
136
+ scores = string_1.to_s.scores(string_2.to_s).inspect
137
+ template = "%5.f %s"
138
+ bindings = [similarity, string_2, scores]
139
+ if similarity >= configuration.threshold
140
+ string_2.evaluated = true
141
+ counter += 1
142
+ unless configuration.summary
143
+ puts template % bindings
144
+ end
145
+ end
146
+ end
147
+ if counter > 0
148
+ puts "#{counter} #{summary_string}"
149
+ end
150
+ end
151
+ end
152
+
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # http://stackoverflow.com/questions/9822078/ruby-compare-two-strings-similarity-percentage
4
+
5
+ def string_difference_percent(a, b)
6
+ longer = [a.size, b.size].max
7
+ same = a.each_char.zip(b.each_char).select { |a,b| a == b }.size
8
+ (longer - same) / a.size.to_f
9
+ end
10
+
11
+ lines = []
12
+
13
+ STDIN.each_line do |line|
14
+ lines.push(line.chomp)
15
+ end
16
+
17
+ scores = {}
18
+
19
+ target_line = lines.shift
20
+
21
+ puts "00 - Comparing: #{target_line}"
22
+
23
+ lines.each do |line|
24
+ score = string_difference_percent(target_line, line)
25
+ scores[score] ||= []
26
+ scores[score].push(line)
27
+ end
28
+
29
+ scores.keys.sort.reverse.each do |score|
30
+ puts ''
31
+ scores[score].each do |line|
32
+ puts "\t#{score} #{line}"
33
+ end
34
+ end
35
+
data/bin/ix-strip ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ STDIN.each_line do |line|
4
+ puts line[0..(ARGV[0].to_i)]
5
+ end
6
+
data/bin/ix-substract ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ STDIN.each_line do |line|
4
+ puts line.to_f - ARGV[0].to_f
5
+ end
data/bin/ix-success ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env ruby
2
+ echo success
data/bin/ix-suffix ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ suffix = ARGV.join(' ')
4
+
5
+ STDIN.each_line do |line|
6
+ puts line.chomp + suffix
7
+ end
data/bin/ix-sum ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ total = 0
4
+
5
+ STDIN.each_line do |line|
6
+ total += line.to_f
7
+ end
8
+
9
+ puts total
10
+
data/bin/ix-swap ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ system "awk '{print $2, $1}'"
data/bin/ix-symlink ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ STDIN.each_line do |line|
4
+ path = ''
5
+ chunks = line.chomp.split('/')
6
+ chunks.each do |chunk|
7
+ path << '/' + chunk
8
+ if File.symlink?(path)
9
+ puts "Symlink found: #{path}"
10
+ system "ls -al #{path}"
11
+ end
12
+ end
13
+ end
data/bin/ix-tab ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ STDIN.each_line do |line|
4
+ puts "\t#{line}"
5
+ end
6
+
data/bin/ix-tabify ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ STDIN.each_line do |line|
4
+ chunks = line.chomp.split(/\s+/)
5
+ puts chunks * "\t"
6
+ end
7
+
data/bin/ix-tac ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ lines = []
4
+
5
+ STDIN.read.each_line do |line|
6
+ lines << line
7
+ end
8
+
9
+ lines.reverse.each do |line|
10
+ puts line
11
+ end
data/bin/ix-task ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ OK_REGEX = /\s*OK - .*/
4
+ NG_REGEX = /\s*-- - .*/
5
+ LEADING_SPACE = /(^\s*)([^\s].*$)/
6
+
7
+ STDIN.each_line do |line|
8
+ line.chomp!
9
+ if line =~ OK_REGEX
10
+ line.gsub!('OK - ', '-- - ')
11
+ puts line
12
+ next
13
+ end
14
+ if line =~ NG_REGEX
15
+ line.gsub!('-- - ', 'OK - ')
16
+ puts line
17
+ next
18
+ end
19
+ puts line.gsub(LEADING_SPACE, '\1-- - \2')
20
+ end
data/bin/ix-technical ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ STDIN.each_line do |line|
4
+ puts "[#{line.chomp}]"
5
+ puts " | 1. ."
6
+ puts " V"
7
+ end
data/bin/ix-template ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'fileutils'
4
+
5
+ INTERPOLATOR_TOKEN = /%\d+s/
6
+
7
+ # puts interpolate(['world', 'other world'], 'hello %1s')
8
+ def interpolate(values, template)
9
+ copy = "#{template}"
10
+ copy.scan(INTERPOLATOR_TOKEN).each do |interpolator|
11
+ needle = interpolator.scan(/\d+/).first.to_i
12
+ value = (values[needle - 1] || 'n/a')
13
+ copy.gsub!(interpolator, value)
14
+ end
15
+ copy
16
+ end
17
+
18
+ if ARGV[0]
19
+ template = "#{ARGV[0]}"
20
+ if File.exists?(template)
21
+ template = File.read(template)
22
+ end
23
+ end
24
+
25
+ STDIN.each_line do |line|
26
+
27
+ if line =~ /\t/
28
+ values = line.chomp.split(/\t/)
29
+ else
30
+ values = line.chomp.split(/\s+/)
31
+ end
32
+
33
+ unless ARGV[1]
34
+ STDOUT.puts interpolate(values, template)
35
+ next
36
+ end
37
+
38
+ fname = interpolate(values, ARGV[1])
39
+ dir = File.dirname(fname)
40
+ unless File.directory?(dir)
41
+ # puts "creating #{dir}"
42
+ FileUtils.mkdir_p(dir)
43
+ end
44
+ File.open(fname, 'w+') do |file|
45
+ file.puts interpolate(values, template)
46
+ end
47
+ end
48
+