epitools 0.5.103 → 0.5.105
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/README.rdoc +1 -1
- data/Rakefile +2 -2
- data/TODO +1 -1
- data/VERSION +1 -1
- data/lib/epitools.rb +1 -1
- data/lib/epitools/colored.rb +25 -25
- data/lib/epitools/core_ext/enumerable.rb +1 -1
- data/lib/epitools/core_ext/file.rb +6 -2
- data/lib/epitools/core_ext/hash.rb +43 -29
- data/lib/epitools/core_ext/misc.rb +21 -1
- data/lib/epitools/core_ext/object.rb +19 -19
- data/lib/epitools/core_ext/truthiness.rb +5 -5
- data/lib/epitools/daemonize.rb +1 -1
- data/lib/epitools/hexdump.rb +1 -1
- data/lib/epitools/iter.rb +26 -26
- data/lib/epitools/lcs.rb +3 -3
- data/lib/epitools/mimemagic.rb +7 -7
- data/lib/epitools/niceprint.rb +18 -18
- data/lib/epitools/numwords.rb +34 -34
- data/lib/epitools/path.rb +7 -0
- data/lib/epitools/permutations.rb +9 -9
- data/lib/epitools/pretty_backtrace.rb +11 -11
- data/lib/epitools/progressbar.rb +7 -7
- data/lib/epitools/rails.rb +2 -2
- data/lib/epitools/rash.rb +16 -16
- data/lib/epitools/ratio.rb +1 -1
- data/lib/epitools/sys.rb +47 -47
- data/lib/epitools/trie.rb +4 -4
- data/lib/epitools/typed_struct.rb +5 -5
- data/lib/epitools/wm.rb +6 -6
- data/lib/epitools/zopen.rb +2 -2
- data/spec/autoreq_spec.rb +5 -5
- data/spec/browser_spec.rb +1 -1
- data/spec/colored_spec.rb +5 -5
- data/spec/core_ext_spec.rb +1 -1
- data/spec/histogram_spec.rb +3 -3
- data/spec/iter_spec.rb +16 -16
- data/spec/lcs_spec.rb +5 -5
- data/spec/numwords_spec.rb +8 -8
- data/spec/permutations_spec.rb +9 -9
- data/spec/rash_spec.rb +7 -7
- data/spec/ratio_spec.rb +5 -5
- data/spec/sys_spec.rb +6 -6
- data/spec/term_spec.rb +7 -7
- data/spec/typed_struct_spec.rb +5 -5
- data/spec/wm_spec.rb +4 -4
- data/spec/zopen_spec.rb +11 -11
- metadata +2 -2
data/lib/epitools/wm.rb
CHANGED
@@ -18,7 +18,7 @@ module WM
|
|
18
18
|
# check the children
|
19
19
|
results = windows.select { |w| w.process.children.any? {|pr| pr.pid == pid } }
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
results
|
23
23
|
end
|
24
24
|
|
@@ -39,11 +39,11 @@ module WM
|
|
39
39
|
fields = line.split
|
40
40
|
fields[1] = (fields[1] == "*") # cast to boolean
|
41
41
|
fields[5] = nil if fields[5] == "N/A" # N/A becomes nil
|
42
|
-
|
42
|
+
|
43
43
|
name = fields[9..-1].join(" ")
|
44
|
-
|
44
|
+
|
45
45
|
new *(fields.values_at(0,1,3,5,8) + [name])
|
46
|
-
end
|
46
|
+
end
|
47
47
|
|
48
48
|
def current?
|
49
49
|
current
|
@@ -70,7 +70,7 @@ module WM
|
|
70
70
|
# 0x048001f8 5 4080 311 186 1316 835 fizz Gorillaz - Highway (Under Construction)
|
71
71
|
# 0x02c28577 4 3012 66 461 1143 548 fizz Terminal
|
72
72
|
# 0x07c00003 0 14117 12 73 1298 948 fizz tr1984001_comp_soft.pdf
|
73
|
-
# 0x02d767d8 2 3012 520 470 1143 548 fizz Terminal
|
73
|
+
# 0x02d767d8 2 3012 520 470 1143 548 fizz Terminal
|
74
74
|
|
75
75
|
fields = line.split
|
76
76
|
title = fields[8..-1].join ' '
|
@@ -371,7 +371,7 @@ module WM
|
|
371
371
|
# p events
|
372
372
|
eventstring = events.map { |e| e + "\n" }.join("")
|
373
373
|
|
374
|
-
temp.write eventstring
|
374
|
+
temp.write eventstring
|
375
375
|
temp.flush
|
376
376
|
temp.seek 0
|
377
377
|
# p [:temp, temp.read]
|
data/lib/epitools/zopen.rb
CHANGED
data/spec/autoreq_spec.rb
CHANGED
@@ -15,24 +15,24 @@ describe "autoreq" do
|
|
15
15
|
# !!defined?(Haml).should == false
|
16
16
|
# lambda { Haml }.should_not raise_error
|
17
17
|
# end
|
18
|
-
|
18
|
+
|
19
19
|
# it "autoreqs a regular ruby file" do
|
20
20
|
# defined?(Net).should == nil
|
21
|
-
|
21
|
+
|
22
22
|
# module Net
|
23
23
|
# autoreq :HTTP, 'net/http'
|
24
24
|
# end
|
25
25
|
# lambda { Net::HTTP }.should_not raise_error
|
26
26
|
# end
|
27
|
-
|
27
|
+
|
28
28
|
# it "autoreqs a gem with a block" do
|
29
29
|
# defined?(Units).should == nil
|
30
|
-
|
30
|
+
|
31
31
|
# autoreq :Units do
|
32
32
|
# gem 'units', '~> 1.0'
|
33
33
|
# require 'units'
|
34
34
|
# end
|
35
35
|
# lambda { Units }.should_not raise_error
|
36
36
|
# end
|
37
|
-
|
37
|
+
|
38
38
|
end
|
data/spec/browser_spec.rb
CHANGED
data/spec/colored_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'epitools'
|
2
2
|
|
3
3
|
describe "Colored strings" do
|
4
|
-
|
4
|
+
|
5
5
|
it "has string methods" do
|
6
6
|
s = "string"
|
7
7
|
s.should respond_to(:blue)
|
@@ -12,12 +12,12 @@ describe "Colored strings" do
|
|
12
12
|
s.should respond_to(:purple)
|
13
13
|
s.should respond_to(:magenta)
|
14
14
|
lambda { s.light_blue }.should_not raise_error
|
15
|
-
end
|
16
|
-
|
15
|
+
end
|
16
|
+
|
17
17
|
it "can do bbs colors" do
|
18
18
|
"<5>yay".colorize.should == "yay".magenta
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it "can do tagged colors" do
|
22
22
|
"<blue>hello".colorize.should == "hello".blue
|
23
23
|
"<magenta>hello".colorize.should == "<purple>hello".colorize
|
@@ -25,6 +25,6 @@ describe "Colored strings" do
|
|
25
25
|
lambda { "</blue>".colorize }.should raise_error
|
26
26
|
"<black_on_yellow>hello".colorize.should == "hello".black_on_yellow
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
end
|
30
30
|
|
data/spec/core_ext_spec.rb
CHANGED
data/spec/histogram_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'epitools/core_ext/array'
|
2
2
|
|
3
3
|
describe "Array#histogram" do
|
4
|
-
|
4
|
+
|
5
5
|
it "does 1..10" do
|
6
6
|
nums = (1..10).to_a
|
7
7
|
nums.histogram(2).should == [ 5, 5 ]
|
@@ -17,7 +17,7 @@ describe "Array#histogram" do
|
|
17
17
|
nums = [0.12, 1.0, 2.2, 3.5, 4.7, 5.9, 6.6, 7.777, 8.898]
|
18
18
|
nums.histogram(3).should == [3,3,3]
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
it "does ranges" do
|
22
22
|
nums = (0..9).to_a
|
23
23
|
nums.histogram(2, ranges: true).should == {
|
@@ -25,5 +25,5 @@ describe "Array#histogram" do
|
|
25
25
|
4.5...9.0 => 5
|
26
26
|
}
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
end
|
data/spec/iter_spec.rb
CHANGED
@@ -12,17 +12,17 @@ describe Iter do
|
|
12
12
|
i.should_not == j
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
it "to_a's" do
|
17
17
|
@i.to_a.should == [1,2,3,4,5]
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
|
21
21
|
it "reverses" do
|
22
22
|
@i.iterate(2) do |a, b|
|
23
23
|
b.move_before(a)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
@i.to_a.should == [5,4,3,2,1]
|
27
27
|
end
|
28
28
|
|
@@ -32,40 +32,40 @@ describe Iter do
|
|
32
32
|
b.prev.should == a
|
33
33
|
end
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "removes" do
|
37
37
|
@i.iterate {|x| x.remove if x % 2 == 1 }
|
38
|
-
@i.to_a.should == [2,4]
|
38
|
+
@i.to_a.should == [2,4]
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it "replaces" do
|
42
42
|
@i.first.replace_with(-1)
|
43
|
-
@i.to_a.should == [-1,2,3,4,5]
|
43
|
+
@i.to_a.should == [-1,2,3,4,5]
|
44
44
|
@i.last.replace_with(8)
|
45
45
|
@i.to_a.should == [-1,2,3,4,8]
|
46
46
|
end
|
47
|
-
|
47
|
+
|
48
48
|
it "slices, values, indexes, etc." do
|
49
49
|
# todo: slice should return an iter
|
50
50
|
@i.first.should == 1
|
51
|
-
@i[0..1].should == @i.values_at(0,1)
|
52
|
-
@i[0..-1].should == @i
|
51
|
+
@i[0..1].should == @i.values_at(0,1)
|
52
|
+
@i[0..-1].should == @i
|
53
53
|
@i[-1].should == @i.last
|
54
54
|
@i[-2..-1].should == @i.values_at(-2,-1)
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
it "move_first/last" do
|
58
58
|
@i.first.move_last
|
59
59
|
@i.to_a.should == [2,3,4,5,1]
|
60
|
-
|
60
|
+
|
61
61
|
@i.last.move_first
|
62
62
|
@i.should == [1,2,3,4,5]
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
it "sorts an array" do
|
66
66
|
i = Iter.new [3,7,3,1,3]
|
67
67
|
i.each { |a|
|
68
|
-
|
68
|
+
|
69
69
|
}
|
70
|
-
end
|
71
|
-
end
|
70
|
+
end
|
71
|
+
end
|
data/spec/lcs_spec.rb
CHANGED
@@ -1,23 +1,23 @@
|
|
1
1
|
require 'epitools/lcs'
|
2
2
|
|
3
3
|
describe "Longest common subsequence" do
|
4
|
-
|
4
|
+
|
5
5
|
it "works!" do
|
6
6
|
prefix_strings = [
|
7
7
|
"shenanigans, gentlemen!",
|
8
8
|
"shenanigans has been called",
|
9
9
|
"shenanigans: a great restaurant."
|
10
10
|
]
|
11
|
-
|
11
|
+
|
12
12
|
subsequence_strings = [
|
13
13
|
"i call shenanigans on you!",
|
14
14
|
"shenanigans is a great restaurant.",
|
15
15
|
"you like this? shenanigans!"
|
16
16
|
]
|
17
|
-
|
17
|
+
|
18
18
|
longest_common_prefix(prefix_strings).should == "shenanigans"
|
19
19
|
longest_common_subsequence(*subsequence_strings[0..1]).should == 12
|
20
|
-
end
|
21
|
-
|
20
|
+
end
|
21
|
+
|
22
22
|
end
|
23
23
|
|
data/spec/numwords_spec.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
require 'epitools'
|
2
2
|
|
3
3
|
describe Numeric do
|
4
|
-
|
4
|
+
|
5
5
|
it "to_wordses" do
|
6
6
|
{
|
7
7
|
10 => "ten",
|
8
8
|
3_123 => "three thousand, one-hundred and twenty-three",
|
9
9
|
123_124 => "one-hundred and twenty-three thousand, one-hundred and twenty-four",
|
10
|
-
|
10
|
+
|
11
11
|
8_128_937_981_273_987_129_837_174_612_897_638_613 => "eight undecillion, one-hundred and twenty-eight decillion, nine-hundred and thirty-seven nonillion, nine-hundred and eighty-one octillion, two-hundred and seventy-three septillion, nine-hundred and eighty-seven sextillion, one-hundred and twenty-nine quintillion, eight-hundred and thirty-seven quadrillion, one-hundred and seventy-four trillion, six-hundred and twelve billion, eight-hundred and ninety-seven million, six-hundred and thirty-eight thousand, six-hundred and thirteen",
|
12
|
-
|
12
|
+
|
13
13
|
3_486_597_230_495_871_304_981_320_498_123_498_263_984_739_841_834_091_823_094_812_039_481_231_623_987_461_293_874_698_123_649_817_236 => "three duotrigintillion, four-hundred and eighty-six untrigintillion, five-hundred and ninety-seven trigintillion, two-hundred and thirty novemvigintillion, four-hundred and ninety-five octovigintillion, eight-hundred and seventy-one septenvigintillion, three-hundred and four sexvigintillion, nine-hundred and eighty-one quinvigintillion, three-hundred and twenty quattuorvigintillion, four-hundred and ninety-eight trevigintillion, one-hundred and twenty-three duovigintillion, four-hundred and ninety-eight unvigintillion, two-hundred and sixty-three vigintillion, nine-hundred and eighty-four novemdecillion, seven-hundred and thirty-nine octodecillion, eight-hundred and fourty-one septendecillion, eight-hundred and thirty-four sexdecillion, ninety-one quindecillion, eight-hundred and twenty-three quattuordecillion, ninety-four tredecillion, eight-hundred and twelve duodecillion, thirty-nine undecillion, four-hundred and eighty-one decillion, two-hundred and thirty-one nonillion, six-hundred and twenty-three octillion, nine-hundred and eighty-seven septillion, four-hundred and sixty-one sextillion, two-hundred and ninety-three quintillion, eight-hundred and seventy-four quadrillion, six-hundred and ninety-eight trillion, one-hundred and twenty-three billion, six-hundred and fourty-nine million, eight-hundred and seventeen thousand, two-hundred and thirty-six",
|
14
|
-
|
15
|
-
1763241823498172490817349807213409238409123409128340981234781236487126348791263847961238794612839468917236489712364987162398746129834698172364987123 => "more than a googol! (148 digits)"
|
14
|
+
|
15
|
+
1763241823498172490817349807213409238409123409128340981234781236487126348791263847961238794612839468917236489712364987162398746129834698172364987123 => "more than a googol! (148 digits)"
|
16
16
|
}.each do |num, result|
|
17
17
|
num.to_words.should == result
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
lambda{ 1.523.million.billion.to_words }.should_not raise_error
|
21
21
|
end
|
22
22
|
|
@@ -27,7 +27,7 @@ describe Numeric do
|
|
27
27
|
37.2872.duotrigintillion.should == 37287200000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
|
28
28
|
lambda { 10.googol }.should raise_error
|
29
29
|
end
|
30
|
-
|
30
|
+
|
31
31
|
it "handles 1.thousand.to_words properly" do
|
32
32
|
1.thousand.to_words.should == "one thousand"
|
33
33
|
end
|
@@ -35,5 +35,5 @@ describe Numeric do
|
|
35
35
|
it "handles 1.quadrillion.to_words properly" do
|
36
36
|
1.quadrillion.to_words.should == "one quadrillion"
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
end
|
data/spec/permutations_spec.rb
CHANGED
@@ -4,26 +4,26 @@ require 'epitools'
|
|
4
4
|
require 'epitools/permutations'
|
5
5
|
|
6
6
|
describe "Permutations" do
|
7
|
-
|
7
|
+
|
8
8
|
it "a*b" do
|
9
9
|
([1,2] * [3,4]).should == [ [1,3], [1,4], [2,3], [2,4] ]
|
10
|
-
end
|
10
|
+
end
|
11
11
|
|
12
12
|
it "a**2" do
|
13
13
|
([1,2] ** 2).should == [ [1,1], [1,2], [2,1], [2,2] ]
|
14
|
-
end
|
15
|
-
|
14
|
+
end
|
15
|
+
|
16
16
|
it "all_pairses" do
|
17
|
-
[1,2,3,4].all_pairs.to_a.should == [
|
18
|
-
[1,2],
|
19
|
-
[1,3],
|
20
|
-
[1,4],
|
17
|
+
[1,2,3,4].all_pairs.to_a.should == [
|
18
|
+
[1,2],
|
19
|
+
[1,3],
|
20
|
+
[1,4],
|
21
21
|
[2,3],
|
22
22
|
[2,4],
|
23
23
|
[3,4],
|
24
24
|
]
|
25
25
|
|
26
|
-
# reflexive
|
26
|
+
# reflexive
|
27
27
|
[1,2,3].all_pairs(true).to_a.should == [
|
28
28
|
[1,1],
|
29
29
|
[1,2],
|
data/spec/rash_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'epitools'
|
|
3
3
|
describe Rash do
|
4
4
|
|
5
5
|
attr_accessor :r
|
6
|
-
|
6
|
+
|
7
7
|
before :each do
|
8
8
|
@r = Rash.new(
|
9
9
|
/hello/ => "hello",
|
@@ -15,7 +15,7 @@ describe Rash do
|
|
15
15
|
#/.+/ => "EVERYTHING"
|
16
16
|
)
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
it "string lookups" do
|
20
20
|
r["other"].should == "whee"
|
21
21
|
r["well hello there"].should == "hello"
|
@@ -27,22 +27,22 @@ describe Rash do
|
|
27
27
|
r[/other/].should == "whee"
|
28
28
|
end
|
29
29
|
|
30
|
-
it "other objects" do
|
30
|
+
it "other objects" do
|
31
31
|
r[true].should == false
|
32
32
|
r[1].should == "awesome"
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
it "does ranges" do
|
36
36
|
@r[250].should == "rangey"
|
37
37
|
@r[999].should == "rangey"
|
38
38
|
@r[1000].should == "rangey"
|
39
39
|
@r[1001].should == nil
|
40
40
|
end
|
41
|
-
|
41
|
+
|
42
42
|
it "calls procs on matches when they're values" do
|
43
43
|
r = Rash.new( /(ello)/ => proc { |m| m[1] } )
|
44
44
|
r["hello"].should == "ello"
|
45
45
|
r["ffffff"].should == nil
|
46
46
|
end
|
47
|
-
|
48
|
-
end
|
47
|
+
|
48
|
+
end
|
data/spec/ratio_spec.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'epitools/ratio'
|
2
2
|
|
3
3
|
describe Ratio do
|
4
|
-
|
4
|
+
|
5
5
|
before :each do
|
6
6
|
@a = Ratio[1,1]
|
7
7
|
@b = Ratio[1,2]
|
@@ -10,12 +10,12 @@ describe Ratio do
|
|
10
10
|
it "adds" do
|
11
11
|
( @a + @b ).should == Ratio[2,3]
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
it "floats" do
|
15
15
|
@a.to_f.should == 1.0
|
16
16
|
@b.to_f.should == 0.5
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
it "percents" do
|
20
20
|
@a.percent.should == "100.0%"
|
21
21
|
@b.percent.should == "50.0%"
|
@@ -25,5 +25,5 @@ describe Ratio do
|
|
25
25
|
Ratio(1,2).should == Ratio[1,2]
|
26
26
|
Ratio(1,2).should == Ratio.new(1,2)
|
27
27
|
end
|
28
|
-
|
29
|
-
end
|
28
|
+
|
29
|
+
end
|
data/spec/sys_spec.rb
CHANGED
@@ -11,11 +11,11 @@ describe Sys::ProcessInfo do
|
|
11
11
|
proc { Sys.windows? }.should_not raise_error
|
12
12
|
|
13
13
|
%w[Linux Windows Darwin BSD].include?(Sys.os).should == true
|
14
|
-
|
14
|
+
|
15
15
|
[:linux?, :mac?, :windows?, :bsd?].any?{|os| Sys.send(os)}.should == true
|
16
16
|
end
|
17
|
-
|
18
|
-
|
17
|
+
|
18
|
+
|
19
19
|
specify "list all processes" do
|
20
20
|
# procs = Sys.ps
|
21
21
|
#
|
@@ -35,7 +35,7 @@ describe Sys::ProcessInfo do
|
|
35
35
|
# matches.should > 1
|
36
36
|
end
|
37
37
|
|
38
|
-
|
38
|
+
|
39
39
|
specify "refresh processes" do
|
40
40
|
|
41
41
|
# STDOUT.sync = true
|
@@ -61,9 +61,9 @@ describe Sys::ProcessInfo do
|
|
61
61
|
Sys.cross_platform_method(:cross_platform_test)
|
62
62
|
proc{ Sys.cross_platform_test }.should raise_error
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
specify "interfaces" do
|
66
66
|
Sys.interfaces.should_not be_blank
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
end
|