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
@@ -0,0 +1,267 @@
1
+ #!/usr/bin/env ruby
2
+
3
+
4
+ # frozen_string_literal: true
5
+ # from rails implementation.
6
+
7
+ class Hash
8
+ # Returns a new hash with all keys converted using the +block+ operation.
9
+ #
10
+ # hash = { name: 'Rob', age: '28' }
11
+ #
12
+ # hash.transform_keys { |key| key.to_s.upcase } # => {"NAME"=>"Rob", "AGE"=>"28"}
13
+ #
14
+ # If you do not provide a +block+, it will return an Enumerator
15
+ # for chaining with other methods:
16
+ #
17
+ # hash.transform_keys.with_index { |k, i| [k, i].join } # => {"name0"=>"Rob", "age1"=>"28"}
18
+ def transform_keys
19
+ return enum_for(:transform_keys) { size } unless block_given?
20
+ result = {}
21
+ each_key do |key|
22
+ result[yield(key)] = self[key]
23
+ end
24
+ result
25
+ end unless method_defined? :transform_keys
26
+
27
+ # Destructively converts all keys using the +block+ operations.
28
+ # Same as +transform_keys+ but modifies +self+.
29
+ def transform_keys!
30
+ return enum_for(:transform_keys!) { size } unless block_given?
31
+ keys.each do |key|
32
+ self[yield(key)] = delete(key)
33
+ end
34
+ self
35
+ end unless method_defined? :transform_keys!
36
+
37
+ # Returns a new hash with all keys converted to strings.
38
+ #
39
+ # hash = { name: 'Rob', age: '28' }
40
+ #
41
+ # hash.stringify_keys
42
+ # # => {"name"=>"Rob", "age"=>"28"}
43
+ def stringify_keys
44
+ transform_keys(&:to_s)
45
+ end
46
+
47
+ # Destructively converts all keys to strings. Same as
48
+ # +stringify_keys+, but modifies +self+.
49
+ def stringify_keys!
50
+ transform_keys!(&:to_s)
51
+ end
52
+
53
+ # Returns a new hash with all keys converted to symbols, as long as
54
+ # they respond to +to_sym+.
55
+ #
56
+ # hash = { 'name' => 'Rob', 'age' => '28' }
57
+ #
58
+ # hash.symbolize_keys
59
+ # # => {:name=>"Rob", :age=>"28"}
60
+ def symbolize_keys
61
+ transform_keys { |key| key.to_sym rescue key }
62
+ end
63
+ alias_method :to_options, :symbolize_keys
64
+
65
+ # Destructively converts all keys to symbols, as long as they respond
66
+ # to +to_sym+. Same as +symbolize_keys+, but modifies +self+.
67
+ def symbolize_keys!
68
+ transform_keys! { |key| key.to_sym rescue key }
69
+ end
70
+ alias_method :to_options!, :symbolize_keys!
71
+
72
+ # Validates all keys in a hash match <tt>*valid_keys</tt>, raising
73
+ # +ArgumentError+ on a mismatch.
74
+ #
75
+ # Note that keys are treated differently than HashWithIndifferentAccess,
76
+ # meaning that string and symbol keys will not match.
77
+ #
78
+ # { name: 'Rob', years: '28' }.assert_valid_keys(:name, :age) # => raises "ArgumentError: Unknown key: :years. Valid keys are: :name, :age"
79
+ # { name: 'Rob', age: '28' }.assert_valid_keys('name', 'age') # => raises "ArgumentError: Unknown key: :name. Valid keys are: 'name', 'age'"
80
+ # { name: 'Rob', age: '28' }.assert_valid_keys(:name, :age) # => passes, raises nothing
81
+ def assert_valid_keys(*valid_keys)
82
+ valid_keys.flatten!
83
+ each_key do |k|
84
+ unless valid_keys.include?(k)
85
+ raise ArgumentError.new("Unknown key: #{k.inspect}. Valid keys are: #{valid_keys.map(&:inspect).join(', ')}")
86
+ end
87
+ end
88
+ end
89
+
90
+ # Returns a new hash with all keys converted by the block operation.
91
+ # This includes the keys from the root hash and from all
92
+ # nested hashes and arrays.
93
+ #
94
+ # hash = { person: { name: 'Rob', age: '28' } }
95
+ #
96
+ # hash.deep_transform_keys{ |key| key.to_s.upcase }
97
+ # # => {"PERSON"=>{"NAME"=>"Rob", "AGE"=>"28"}}
98
+ def deep_transform_keys(&block)
99
+ _deep_transform_keys_in_object(self, &block)
100
+ end
101
+
102
+ # Destructively converts all keys by using the block operation.
103
+ # This includes the keys from the root hash and from all
104
+ # nested hashes and arrays.
105
+ def deep_transform_keys!(&block)
106
+ _deep_transform_keys_in_object!(self, &block)
107
+ end
108
+
109
+ # Returns a new hash with all keys converted to strings.
110
+ # This includes the keys from the root hash and from all
111
+ # nested hashes and arrays.
112
+ #
113
+ # hash = { person: { name: 'Rob', age: '28' } }
114
+ #
115
+ # hash.deep_stringify_keys
116
+ # # => {"person"=>{"name"=>"Rob", "age"=>"28"}}
117
+ def deep_stringify_keys
118
+ deep_transform_keys(&:to_s)
119
+ end
120
+
121
+ # Destructively converts all keys to strings.
122
+ # This includes the keys from the root hash and from all
123
+ # nested hashes and arrays.
124
+ def deep_stringify_keys!
125
+ deep_transform_keys!(&:to_s)
126
+ end
127
+
128
+ # Returns a new hash with all keys converted to symbols, as long as
129
+ # they respond to +to_sym+. This includes the keys from the root hash
130
+ # and from all nested hashes and arrays.
131
+ #
132
+ # hash = { 'person' => { 'name' => 'Rob', 'age' => '28' } }
133
+ #
134
+ # hash.deep_symbolize_keys
135
+ # # => {:person=>{:name=>"Rob", :age=>"28"}}
136
+ def deep_symbolize_keys
137
+ deep_transform_keys { |key| key.to_sym rescue key }
138
+ end
139
+
140
+ # Destructively converts all keys to symbols, as long as they respond
141
+ # to +to_sym+. This includes the keys from the root hash and from all
142
+ # nested hashes and arrays.
143
+ def deep_symbolize_keys!
144
+ deep_transform_keys! { |key| key.to_sym rescue key }
145
+ end
146
+
147
+ private
148
+ # support methods for deep transforming nested hashes and arrays
149
+ def _deep_transform_keys_in_object(object, &block)
150
+ case object
151
+ when Hash
152
+ object.each_with_object({}) do |(key, value), result|
153
+ result[yield(key)] = _deep_transform_keys_in_object(value, &block)
154
+ end
155
+ when Array
156
+ object.map { |e| _deep_transform_keys_in_object(e, &block) }
157
+ else
158
+ object
159
+ end
160
+ end
161
+
162
+ def _deep_transform_keys_in_object!(object, &block)
163
+ case object
164
+ when Hash
165
+ object.keys.each do |key|
166
+ value = object.delete(key)
167
+ object[yield(key)] = _deep_transform_keys_in_object!(value, &block)
168
+ end
169
+ object
170
+ when Array
171
+ object.map! { |e| _deep_transform_keys_in_object!(e, &block) }
172
+ else
173
+ object
174
+ end
175
+ end
176
+
177
+ end
178
+
179
+ # frozen_string_literal: true
180
+
181
+ class Hash
182
+ # Returns a new hash with the results of running +block+ once for every value.
183
+ # The keys are unchanged.
184
+ #
185
+ # { a: 1, b: 2, c: 3 }.transform_values { |x| x * 2 } # => { a: 2, b: 4, c: 6 }
186
+ #
187
+ # If you do not provide a +block+, it will return an Enumerator
188
+ # for chaining with other methods:
189
+ #
190
+ # { a: 1, b: 2 }.transform_values.with_index { |v, i| [v, i].join.to_i } # => { a: 10, b: 21 }
191
+ def transform_values
192
+ return enum_for(:transform_values) { size } unless block_given?
193
+ return {} if empty?
194
+ result = self.class.new
195
+ each do |key, value|
196
+ result[key] = yield(value)
197
+ end
198
+ result
199
+ end unless method_defined? :transform_values
200
+
201
+ # Destructively converts all values using the +block+ operations.
202
+ # Same as +transform_values+ but modifies +self+.
203
+ def transform_values!
204
+ return enum_for(:transform_values!) { size } unless block_given?
205
+ each do |key, value|
206
+ self[key] = yield(value)
207
+ end
208
+ end unless method_defined? :transform_values!
209
+ # TODO: Remove this file when supporting only Ruby 2.4+.
210
+ end
211
+
212
+ class Hash
213
+ # personal implementation of slice.
214
+ # TODO: remove once upgraded to newer ruby 2.5 and use the native implementation of slice instead.
215
+ def slice(*keys)
216
+ select { |k, v| keys.include?(k) }
217
+ end
218
+ end
219
+
220
+
221
+ class Hash
222
+ def walk(&block)
223
+ each do |k, v|
224
+ if v.is_a?(Hash)
225
+ v = v.walk(&block)
226
+ next
227
+ end
228
+ yield(self, k, v)
229
+ end
230
+ end
231
+ end
232
+
233
+
234
+
235
+ require 'json'
236
+ require 'erb'
237
+ require 'ostruct'
238
+ require 'digest/md5'
239
+
240
+ source = ARGV[0]
241
+ target = ARGV[1]
242
+
243
+ unless File.exists?(source)
244
+ $stderr.puts "File not found: #{source}"
245
+ exit 0
246
+ end
247
+
248
+ data = File.read(source)
249
+ template = ERB.new(data)
250
+
251
+ STDIN.each do |line|
252
+ begin
253
+ object = JSON.parse(line)
254
+ object.symbolize_keys!
255
+ rescue => error
256
+ next
257
+ end
258
+ # target = format(target, object)
259
+ target = object[:confidence].downcase.gsub(' ', '_') + '__' +
260
+ object[:warning_type].downcase.gsub(' ', '_') + '__' +
261
+ Digest::MD5.hexdigest(object.inspect) + '.html'
262
+ puts "generating: #{target}"
263
+ File.open(target, 'w+') do |file|
264
+ file.puts template.result(binding)
265
+ end
266
+ end
267
+
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'json'
4
+
5
+ headers = []
6
+
7
+ STDIN.each_line do |line|
8
+ begin
9
+ hash = JSON.parse(line)
10
+ if hash.keys != headers
11
+ puts ''
12
+ puts hash.keys * "\t"
13
+ headers = hash.keys
14
+ end
15
+ puts hash.values * "\t"
16
+ rescue => error
17
+ end
18
+ end
19
+
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env bash
2
+ echo '# http://www.webgraphviz.com/'
3
+ echo 'digraph json {'
4
+ ix json-paths-pretty | awk '{print $2}' | ix prefix ' root.' | sed 's/\./ -> /g' | ix suffix ';'
5
+ echo '}'
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'json'
5
+ require 'cgi'
6
+
7
+ def html_list(array)
8
+ output = []
9
+ output.push('<ol>')
10
+ array.each do |item|
11
+ output.push('<li>')
12
+ if item.is_a?(Hash)
13
+ output.push(html_table(item))
14
+ else
15
+ output.push(CGI::escapeHTML(item.to_s))
16
+ end
17
+ output.push('</li>')
18
+ end
19
+ output.push('</ol>')
20
+ (output * "\n")
21
+ end
22
+
23
+ def flip_flop(values)
24
+ raise 'hell: values is not an array' unless values.is_a?(Array)
25
+ @index = 0 unless @index
26
+ if @index < (values.size - 1)
27
+ @index += 1
28
+ else
29
+ @index = 0
30
+ end
31
+ # puts "#{@index} -> #{values[@index]}"
32
+ values[@index]
33
+ end
34
+
35
+ def html_table(hash)
36
+ output = []
37
+ output.push('<table>')
38
+ hash.keys.each do |key|
39
+ value = hash[key]
40
+ output.push('<tr>')
41
+ output.push('<td class="zebra_header">')
42
+ output.push("#{key} (#{value.class})")
43
+ output.push('</td>')
44
+ output.push('<td class="' + flip_flop(['zebra_light', 'zebra_dark']) + '">')
45
+ if value.is_a?(Hash)
46
+ output.push(html_table(value))
47
+ elsif value.is_a?(Array)
48
+ output.push(html_list(value))
49
+ else
50
+ output.push(CGI::escapeHTML(value.to_s))
51
+ end
52
+ output.push('</td>')
53
+ output.push('</tr>')
54
+ end
55
+ output.push('</table>')
56
+ output.push('<br />')
57
+ (output * "\n")
58
+ end
59
+
60
+ puts '
61
+ <style>
62
+ .zebra_dark {
63
+ background: whitesmoke;
64
+ }
65
+ .zebra_light {
66
+ background: white;
67
+ }
68
+ .zebra_header {
69
+ background: darkgray;
70
+ font-color: white;
71
+ }
72
+ td {
73
+ padding: 1mm;
74
+ }
75
+ </style>
76
+ '
77
+
78
+ STDIN.each do |line|
79
+ begin
80
+ hash = JSON.parse(line)
81
+ puts html_table(hash)
82
+ rescue => error
83
+ end
84
+ end
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'json'
5
+
6
+ STDIN.each_line do |line|
7
+ begin
8
+ hash = JSON.parse(line)
9
+ puts hash.inspect
10
+ rescue => error
11
+ end
12
+ end
13
+
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'json'
5
+ require 'hirb'
6
+
7
+ hashes = []
8
+
9
+ STDIN.each_line do |line|
10
+ if line.include? '}'
11
+ hash = JSON.parse(line)
12
+ hashes.push(hash)
13
+ end
14
+ end
15
+
16
+ vertical = false
17
+ if ARGV[0] == '-v'
18
+ vertical = true
19
+ end
20
+
21
+ puts Hirb::Helpers::Table.render(hashes, :resize => false, :vertical => vertical)
@@ -0,0 +1,22 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'json'
5
+ require 'hirb'
6
+
7
+ hashes = []
8
+
9
+ STDIN.each_line do |line|
10
+ if line.include? '}'
11
+ hash = JSON.parse(line)
12
+ puts ''
13
+ puts Hirb::Helpers::Table.render([hash], :resize => false)
14
+ end
15
+ end
16
+
17
+ vertical = false
18
+ if ARGV[0] == '-v'
19
+ vertical = true
20
+ end
21
+
22
+ # puts Hirb::Helpers::Table.render(hashes, :resize => false, :vertical => vertical)
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'json'
4
+
5
+ STDIN.each_line do |line|
6
+ begin
7
+ hash = JSON.parse(line.chomp)
8
+ puts hash.values * "\t"
9
+ rescue => error
10
+ end
11
+ end
12
+
13
+
data/bin/ix-jsonpp ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'tmpdir'
4
+
5
+ Dir.mktmpdir do |dir|
6
+ STDIN.each_line do |line|
7
+ filepath = "#{dir}/file.txt"
8
+ File.open(filepath, 'w+') do |file|
9
+ file.write line
10
+ end
11
+ system "cat #{filepath} | json_pp"
12
+ end
13
+ end
14
+
data/bin/ix-lake ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+
3
+ cat > /tmp/lake
4
+ cat /tmp/lake | ix right | ix transpose
5
+ cat /tmp/lake | ix transpose
6
+ rm /tmp/lake
data/bin/ix-lemmatize ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'lemmatizer'
5
+
6
+ lemmatizer = Lemmatizer.new
7
+
8
+ STDIN.each_line do |line|
9
+ words = line.scan(/\w+/)
10
+ words.each do |word|
11
+ lemma = lemmatizer.lemma(word)
12
+ # puts "#{word} => #{lemma}"
13
+ puts lemma
14
+ end
15
+ end
16
+
17
+
data/bin/ix-length ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ STDIN.each_line do |line|
4
+ puts line.size
5
+ end
6
+
data/bin/ix-linkify ADDED
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'net/http'
4
+ require 'nokogiri'
5
+ require 'open-uri'
6
+
7
+ class Mock
8
+ attr_accessor :title
9
+ end
10
+
11
+ counter = 0
12
+
13
+ STDIN.each_line do |line|
14
+ next if line.chomp == ''
15
+ counter += 1
16
+ url = line.chomp
17
+ begin
18
+ doc = Nokogiri::HTML(open(url))
19
+ rescue => e
20
+ doc = Mock.new
21
+ doc.title = url
22
+ end
23
+ unless doc.title
24
+ doc = Mock.new
25
+ doc.title = url
26
+ end
27
+ template = "%s - %s\n%s\n\n"
28
+ title = doc.title
29
+ title.chomp!
30
+ title.gsub!(/\n/, '')
31
+ title.gsub!(/^\s+/, '')
32
+ title.gsub!(/\s+$/, '')
33
+ bindings = [counter, title, url]
34
+ puts template % bindings
35
+ end
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'net/http'
4
+ require 'nokogiri'
5
+ require 'open-uri'
6
+
7
+ class Mock
8
+ attr_accessor :title
9
+ end
10
+
11
+ counter = 0
12
+
13
+ template = '
14
+ <tr>
15
+ <td>
16
+ <a href="%s">
17
+ <img src="%s" width="200" />
18
+ </a>
19
+ </td>
20
+ <td style="">
21
+ <div>
22
+ %s - <a href="%s"> %s </a>
23
+ </div>
24
+ </td>
25
+ </tr>
26
+ '
27
+
28
+ puts '
29
+ <style>
30
+ td {
31
+ border:solid 1px whitesmoke;
32
+ }
33
+ </style>
34
+ '
35
+ puts '<table>'
36
+ STDIN.each_line do |line|
37
+ next if line.chomp == ''
38
+ counter += 1
39
+ url = line.chomp
40
+ begin
41
+ doc = Nokogiri::HTML(open(url))
42
+ rescue => e
43
+ doc = Mock.new
44
+ doc.title = url
45
+ end
46
+ unless doc.title
47
+ doc = Mock.new
48
+ doc.title = url
49
+ end
50
+
51
+ begin
52
+
53
+ image_source = ''
54
+ doc.traverse do |element|
55
+ break if image_source != ''
56
+ if element.name == 'img'
57
+ image_source = element['src']
58
+ end
59
+ end
60
+
61
+ rescue => error
62
+ $stderr.puts error.message
63
+ end
64
+
65
+ bindings = [url, image_source, counter, url, doc.title]
66
+ puts template % bindings
67
+
68
+ end
69
+ puts '</table>'
70
+
data/bin/ix-links ADDED
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ system 'pbpaste | ix linkify | pbcopy'