nkpart-dget 0.3.0 → 0.3.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.
- data/VERSION +1 -1
- data/dget.gemspec +2 -1
- data/lib/dget.rb +1 -0
- data/lib/dget/github.rb +5 -3
- data/lib/peach.rb +111 -0
- metadata +2 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/dget.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{dget}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Nick Partridge"]
|
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
"lib/dget/googlecode.rb",
|
32
32
|
"lib/dget/utils.rb",
|
33
33
|
"lib/googlecode.html",
|
34
|
+
"lib/peach.rb",
|
34
35
|
"spec/dget_spec.rb",
|
35
36
|
"spec/spec_helper.rb",
|
36
37
|
"test/test_gh-wiki.rb",
|
data/lib/dget.rb
CHANGED
data/lib/dget/github.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
$:.unshift(File.dirname(__FILE__)) unless
|
2
2
|
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
3
|
|
4
|
+
|
4
5
|
require 'dget'
|
5
6
|
module DGet
|
6
7
|
|
@@ -82,9 +83,10 @@ module DGet
|
|
82
83
|
main_content = root.css('.main').first.fmap(&:inner_html)
|
83
84
|
page_list = sidebar(pages)
|
84
85
|
i = 0 #todo better way to trace this?
|
85
|
-
|
86
|
-
|
87
|
-
|
86
|
+
puts "Getting #{pages.size} pages."
|
87
|
+
page_content = pages.pmap(5) { |title, id, content_f|
|
88
|
+
# i += 1
|
89
|
+
# puts " * [#{i}/#{pages.size}] #{title}"
|
88
90
|
"<div id=\"#{id}\">#{content_f[]}</div>"
|
89
91
|
}.join
|
90
92
|
|
data/lib/peach.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# Copyright (c) 2008 Ben Hughes
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person
|
4
|
+
# obtaining a copy of this software and associated documentation
|
5
|
+
# files (the "Software"), to deal in the Software without
|
6
|
+
# restriction, including without limitation the rights to use,
|
7
|
+
# copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the
|
9
|
+
# Software is furnished to do so, subject to the following
|
10
|
+
# conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
# OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
24
|
+
|
25
|
+
module Peach
|
26
|
+
def peach(n = nil, &b)
|
27
|
+
return [] if n == 0 or size == 0
|
28
|
+
|
29
|
+
result = Array.new(size)
|
30
|
+
|
31
|
+
n ||= $peach_default_threads || size
|
32
|
+
div = (size.to_f/n).ceil
|
33
|
+
|
34
|
+
return [] if div == 0
|
35
|
+
|
36
|
+
threads = []
|
37
|
+
max = size - 1
|
38
|
+
offset = 0
|
39
|
+
for i in (0..n-1)
|
40
|
+
threads << Thread.new(offset - div, offset > max ? max : offset) do |lower, upper|
|
41
|
+
for j in lower..upper
|
42
|
+
yield(slice(j))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
offset += div
|
46
|
+
end
|
47
|
+
threads.each { |t| t.join }
|
48
|
+
self
|
49
|
+
end
|
50
|
+
|
51
|
+
def pmap(n = nil, &b)
|
52
|
+
return [] if n == 0
|
53
|
+
|
54
|
+
n ||= $peach_default_threads || size
|
55
|
+
div = (size.to_f/n).ceil
|
56
|
+
|
57
|
+
return [] if div == 0
|
58
|
+
|
59
|
+
result = Array.new(size)
|
60
|
+
|
61
|
+
threads = []
|
62
|
+
max = size - 1
|
63
|
+
offset = div
|
64
|
+
for i in (0..n-1)
|
65
|
+
threads << Thread.new(offset - div, offset > max ? max : offset) do |lower, upper|
|
66
|
+
for j in lower..upper
|
67
|
+
result[j] = yield(slice(j))
|
68
|
+
end
|
69
|
+
end
|
70
|
+
offset += div
|
71
|
+
end
|
72
|
+
threads.each { |t| t.join }
|
73
|
+
|
74
|
+
result
|
75
|
+
end
|
76
|
+
|
77
|
+
def pselect(n = nil, &b)
|
78
|
+
peach_run(:select, b, n)
|
79
|
+
end
|
80
|
+
|
81
|
+
protected
|
82
|
+
def peach_run(meth, b, n = nil)
|
83
|
+
threads, results, result = [],[],[]
|
84
|
+
peach_divvy(n).each_with_index do |x,i|
|
85
|
+
threads << Thread.new { results[i] = x.send(meth, &b)}
|
86
|
+
end
|
87
|
+
threads.each {|t| t.join }
|
88
|
+
results.each {|x| result += x if x}
|
89
|
+
result
|
90
|
+
end
|
91
|
+
|
92
|
+
def peach_divvy(n = nil)
|
93
|
+
return [] if size == 0
|
94
|
+
|
95
|
+
n ||= $peach_default_threads || size
|
96
|
+
n = size if n > size
|
97
|
+
|
98
|
+
lists = []
|
99
|
+
|
100
|
+
div = (size/n).floor
|
101
|
+
offset = 0
|
102
|
+
for i in (0...n-1)
|
103
|
+
lists << slice(offset, div)
|
104
|
+
offset += div
|
105
|
+
end
|
106
|
+
lists << slice(offset...size)
|
107
|
+
lists
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
Array.send(:include, Peach)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nkpart-dget
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nick Partridge
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/dget/googlecode.rb
|
45
45
|
- lib/dget/utils.rb
|
46
46
|
- lib/googlecode.html
|
47
|
+
- lib/peach.rb
|
47
48
|
- spec/dget_spec.rb
|
48
49
|
- spec/spec_helper.rb
|
49
50
|
- test/test_gh-wiki.rb
|