mharris_ext 1.5.0
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/.gitignore +3 -0
- data/LICENSE +20 -0
- data/README +7 -0
- data/Rakefile +56 -0
- data/VERSION.yml +4 -0
- data/features/mharris_ext.feature +9 -0
- data/features/steps/mharris_ext_steps.rb +0 -0
- data/features/support/env.rb +13 -0
- data/lib/mharris_ext.rb +2 -0
- data/lib/mharris_ext/accessor.rb +13 -0
- data/lib/mharris_ext/benchmark.rb +17 -0
- data/lib/mharris_ext/cmd.rb +6 -0
- data/lib/mharris_ext/enumerable.rb +111 -0
- data/lib/mharris_ext/fileutils.rb +52 -0
- data/lib/mharris_ext/from_hash.rb +19 -0
- data/lib/mharris_ext/gems.rb +2 -0
- data/lib/mharris_ext/methods.rb +6 -0
- data/lib/mharris_ext/object.rb +6 -0
- data/lib/mharris_ext/regexp.rb +5 -0
- data/lib/mharris_ext/time.rb +5 -0
- data/mharris_ext.gemspec +69 -0
- data/test/mharris_ext_test.rb +7 -0
- data/test/test_helper.rb +10 -0
- metadata +98 -0
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 Mike Harris
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rake'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'jeweler'
|
5
|
+
Jeweler::Tasks.new do |s|
|
6
|
+
s.name = "mharris_ext"
|
7
|
+
s.summary = %Q{mharris717 utility methods}
|
8
|
+
s.email = "mharris717@gmail.com"
|
9
|
+
s.homepage = "http://github.com/GFunk911/mharris_ext"
|
10
|
+
s.description = "mharris717 utlity methods"
|
11
|
+
s.authors = ["Mike Harris"]
|
12
|
+
s.add_dependency 'fattr'
|
13
|
+
s.add_dependency 'facets'
|
14
|
+
end
|
15
|
+
rescue LoadError
|
16
|
+
puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rake/rdoctask'
|
20
|
+
Rake::RDocTask.new do |rdoc|
|
21
|
+
rdoc.rdoc_dir = 'rdoc'
|
22
|
+
rdoc.title = 'mharris_ext'
|
23
|
+
rdoc.options << '--line-numbers' << '--inline-source'
|
24
|
+
rdoc.rdoc_files.include('README*')
|
25
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'rake/testtask'
|
29
|
+
Rake::TestTask.new(:test) do |t|
|
30
|
+
t.libs << 'lib' << 'test'
|
31
|
+
t.pattern = 'test/**/*_test.rb'
|
32
|
+
t.verbose = false
|
33
|
+
end
|
34
|
+
|
35
|
+
begin
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |t|
|
38
|
+
t.libs << 'test'
|
39
|
+
t.test_files = FileList['test/**/*_test.rb']
|
40
|
+
t.verbose = true
|
41
|
+
end
|
42
|
+
rescue LoadError
|
43
|
+
puts "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
44
|
+
end
|
45
|
+
|
46
|
+
begin
|
47
|
+
require 'cucumber/rake/task'
|
48
|
+
Cucumber::Rake::Task.new(:features)
|
49
|
+
rescue LoadError
|
50
|
+
puts "Cucumber is not available. In order to run features, you must: sudo gem install cucumber"
|
51
|
+
end
|
52
|
+
|
53
|
+
task :default => :test
|
54
|
+
|
55
|
+
Jeweler::GemcutterTasks.new
|
56
|
+
|
data/VERSION.yml
ADDED
File without changes
|
data/lib/mharris_ext.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
class Object
|
2
|
+
def attr_accessor_nn_one(sym)
|
3
|
+
define_method(sym) do
|
4
|
+
res = instance_variable_get("@#{sym}")
|
5
|
+
raise "method #{sym} cannot return nil value" unless res
|
6
|
+
res
|
7
|
+
end
|
8
|
+
attr_writer(sym)
|
9
|
+
end
|
10
|
+
def attr_accessor_nn(*args)
|
11
|
+
args.flatten.each { |x| attr_accessor_nn_one(x) }
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
def tm(msg="Thing")
|
2
|
+
t = Time.now
|
3
|
+
res = yield
|
4
|
+
seconds = Time.now - t
|
5
|
+
puts "#{msg} took #{seconds} seconds"
|
6
|
+
res
|
7
|
+
end
|
8
|
+
|
9
|
+
def print_memory_usage!
|
10
|
+
Thread.new do
|
11
|
+
loop do
|
12
|
+
mem = `ps -l #{Process.pid}`.to_a[1].split[8]
|
13
|
+
puts "Memory: #{mem} #{Time.now}"
|
14
|
+
sleep(10)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
class Fixnum
|
2
|
+
def of
|
3
|
+
res = []
|
4
|
+
self.times { res << yield }
|
5
|
+
res
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
module Enumerable
|
10
|
+
def sumx
|
11
|
+
res = 0
|
12
|
+
each { |x| res += x }
|
13
|
+
res
|
14
|
+
end
|
15
|
+
def sum_b
|
16
|
+
map { |x| yield(x) }.sum
|
17
|
+
end
|
18
|
+
def avg_b(&b)
|
19
|
+
sum_b(&b).to_f / size.to_f
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
module Enumerable
|
24
|
+
def nths_hashx(num)
|
25
|
+
res = {}
|
26
|
+
s = e_f = e_i = 0
|
27
|
+
n_size = size.to_f / num.to_f
|
28
|
+
total_segment_size = 0
|
29
|
+
(0...num).each do |n|
|
30
|
+
s = e_i
|
31
|
+
e_f = e_f + n_size
|
32
|
+
e_i = (e_f+0.5).to_i
|
33
|
+
seg = self[s...e_i]
|
34
|
+
# puts %w(s e_f e_i seg).map { |x| "#{x}: #{send(x)}" }.join("\n")
|
35
|
+
#puts "s: #{s}, e_f: #{e_f}, e_i: #{e_i}, seg: #{seg.inspect}"
|
36
|
+
res[n] = seg
|
37
|
+
total_segment_size += res[n].size
|
38
|
+
end
|
39
|
+
unless total_segment_size == size
|
40
|
+
puts inspect
|
41
|
+
puts res.inspect
|
42
|
+
raise "nths_hash is bad"
|
43
|
+
end
|
44
|
+
res
|
45
|
+
end
|
46
|
+
def nths(num)
|
47
|
+
res = []
|
48
|
+
s = e_f = e_i = 0
|
49
|
+
n_size = size.to_f / num.to_f
|
50
|
+
total_segment_size = 0
|
51
|
+
(0...num).each do |n|
|
52
|
+
s = e_i
|
53
|
+
e_f = e_f + n_size
|
54
|
+
e_i = (e_f+0.5).to_i
|
55
|
+
seg = self[s...e_i]
|
56
|
+
# puts %w(s e_f e_i seg).map { |x| "#{x}: #{send(x)}" }.join("\n")
|
57
|
+
#puts "s: #{s}, e_f: #{e_f}, e_i: #{e_i}, seg: #{seg.inspect}"
|
58
|
+
res << seg
|
59
|
+
total_segment_size += res[n].size
|
60
|
+
end
|
61
|
+
unless total_segment_size == size
|
62
|
+
puts inspect
|
63
|
+
puts res.inspect
|
64
|
+
raise "nths_hash is bad"
|
65
|
+
end
|
66
|
+
res
|
67
|
+
end
|
68
|
+
def nths_hash(num)
|
69
|
+
res = {}
|
70
|
+
nths(num).each_with_index { |x,i| res[i] = x }
|
71
|
+
res
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
res = [1,2,3,4,5,6].nths_hash(3)
|
76
|
+
exp = {0 => [1,2], 1 => [3,4], 2 => [5,6]}
|
77
|
+
unless res == exp
|
78
|
+
puts res.inspect
|
79
|
+
puts exp.inspect
|
80
|
+
raise "nths_hash doesn't work"
|
81
|
+
end
|
82
|
+
|
83
|
+
res = [1,2,3,4,5,6,7].nths_hash(3)
|
84
|
+
exp = {0 => [1,2], 1 => [3,4,5], 2 => [6,7]}
|
85
|
+
unless res == exp
|
86
|
+
puts res.inspect
|
87
|
+
puts exp.inspect
|
88
|
+
raise "nths_hash doesn't work"
|
89
|
+
end
|
90
|
+
|
91
|
+
class Hash
|
92
|
+
def map_value
|
93
|
+
res = {}
|
94
|
+
each { |k,v| res[k] = yield(v) }
|
95
|
+
res
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class Numeric
|
100
|
+
def commify
|
101
|
+
to_s.commify
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
class String
|
106
|
+
def commify
|
107
|
+
return self if length <= 3
|
108
|
+
self[0...-3].commify + "," + self[-3..-1]
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
def all_dirs_recursive(dir)
|
2
|
+
raise "null dir" unless dir
|
3
|
+
init_slash = (dir[0..0] == '/')
|
4
|
+
#raise "can't handle initial slash" if dir[0..0] == '/'
|
5
|
+
#puts "all_dirs_recursive #{dir}"
|
6
|
+
dir.split("/")[0..-1].inject([]) do |paths,dir|
|
7
|
+
last_path = (paths.empty? ? "" : "#{paths[-1]}/")
|
8
|
+
paths + ["#{last_path}#{dir}"]
|
9
|
+
end.select { |x| x != '' }
|
10
|
+
end
|
11
|
+
|
12
|
+
def mkdir_if(dir)
|
13
|
+
if FileTest.exists?(dir)
|
14
|
+
#puts "not making #{dir}"
|
15
|
+
else
|
16
|
+
#puts "making #{dir}"
|
17
|
+
FileUtils.mkdir(dir)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def mkdir_recursive(ops)
|
22
|
+
dir = ops.is_a?(Hash) ? ops[:dir] : ops
|
23
|
+
#puts "mkdir_recursive #{dir}"
|
24
|
+
all_dirs_recursive(dir).each do |dir|
|
25
|
+
mkdir_if(dir)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def mv_making_dir(f,new_dir)
|
30
|
+
#puts "mv_making_dir #{f} #{new_dir}"
|
31
|
+
mkdir_recursive(new_dir)
|
32
|
+
FileUtils.mv(f,new_dir)
|
33
|
+
end
|
34
|
+
|
35
|
+
unless all_dirs_recursive("a/b/c") == ["a","a/b","a/b/c"]
|
36
|
+
res = all_dirs_recursive("a/b/c")
|
37
|
+
raise "all_dirs_recursive doesn't work #{res.inspect}"
|
38
|
+
end
|
39
|
+
|
40
|
+
unless all_dirs_recursive("/a/b/c") == ["/a","/a/b","/a/b/c"]
|
41
|
+
res = all_dirs_recursive("/a/b/c")
|
42
|
+
raise "all_dirs_recursive doesn't work #{res.inspect}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def rm_r_if(dir)
|
46
|
+
FileUtils.rm_r(dir) if FileTest.exists?(dir)
|
47
|
+
end
|
48
|
+
|
49
|
+
def eat_exceptions
|
50
|
+
yield
|
51
|
+
rescue
|
52
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module FromHash
|
2
|
+
def from_hash(ops)
|
3
|
+
ops.each do |k,v|
|
4
|
+
send("#{k}=",v)
|
5
|
+
end
|
6
|
+
self
|
7
|
+
end
|
8
|
+
def initialize(ops={})
|
9
|
+
from_hash(ops)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Class
|
14
|
+
def self.from_hash(ops={})
|
15
|
+
res = new
|
16
|
+
res.from_hash(ops)
|
17
|
+
res
|
18
|
+
end
|
19
|
+
end
|
data/mharris_ext.gemspec
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{mharris_ext}
|
8
|
+
s.version = "1.5.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Mike Harris"]
|
12
|
+
s.date = %q{2009-12-17}
|
13
|
+
s.description = %q{mharris717 utlity methods}
|
14
|
+
s.email = %q{mharris717@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE",
|
17
|
+
"README"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".gitignore",
|
21
|
+
"LICENSE",
|
22
|
+
"README",
|
23
|
+
"Rakefile",
|
24
|
+
"VERSION.yml",
|
25
|
+
"features/mharris_ext.feature",
|
26
|
+
"features/steps/mharris_ext_steps.rb",
|
27
|
+
"features/support/env.rb",
|
28
|
+
"lib/mharris_ext.rb",
|
29
|
+
"lib/mharris_ext/accessor.rb",
|
30
|
+
"lib/mharris_ext/benchmark.rb",
|
31
|
+
"lib/mharris_ext/cmd.rb",
|
32
|
+
"lib/mharris_ext/enumerable.rb",
|
33
|
+
"lib/mharris_ext/fileutils.rb",
|
34
|
+
"lib/mharris_ext/from_hash.rb",
|
35
|
+
"lib/mharris_ext/gems.rb",
|
36
|
+
"lib/mharris_ext/methods.rb",
|
37
|
+
"lib/mharris_ext/object.rb",
|
38
|
+
"lib/mharris_ext/regexp.rb",
|
39
|
+
"lib/mharris_ext/time.rb",
|
40
|
+
"mharris_ext.gemspec",
|
41
|
+
"test/mharris_ext_test.rb",
|
42
|
+
"test/test_helper.rb"
|
43
|
+
]
|
44
|
+
s.homepage = %q{http://github.com/GFunk911/mharris_ext}
|
45
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
46
|
+
s.require_paths = ["lib"]
|
47
|
+
s.rubygems_version = %q{1.3.5}
|
48
|
+
s.summary = %q{mharris717 utility methods}
|
49
|
+
s.test_files = [
|
50
|
+
"test/mharris_ext_test.rb",
|
51
|
+
"test/test_helper.rb"
|
52
|
+
]
|
53
|
+
|
54
|
+
if s.respond_to? :specification_version then
|
55
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
56
|
+
s.specification_version = 3
|
57
|
+
|
58
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
59
|
+
s.add_runtime_dependency(%q<fattr>, [">= 0"])
|
60
|
+
s.add_runtime_dependency(%q<facets>, [">= 0"])
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<fattr>, [">= 0"])
|
63
|
+
s.add_dependency(%q<facets>, [">= 0"])
|
64
|
+
end
|
65
|
+
else
|
66
|
+
s.add_dependency(%q<fattr>, [">= 0"])
|
67
|
+
s.add_dependency(%q<facets>, [">= 0"])
|
68
|
+
end
|
69
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mharris_ext
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.5.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mike Harris
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-12-17 00:00:00 -05:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: fattr
|
17
|
+
type: :runtime
|
18
|
+
version_requirement:
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
version:
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: facets
|
27
|
+
type: :runtime
|
28
|
+
version_requirement:
|
29
|
+
version_requirements: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: "0"
|
34
|
+
version:
|
35
|
+
description: mharris717 utlity methods
|
36
|
+
email: mharris717@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files:
|
42
|
+
- LICENSE
|
43
|
+
- README
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- LICENSE
|
47
|
+
- README
|
48
|
+
- Rakefile
|
49
|
+
- VERSION.yml
|
50
|
+
- features/mharris_ext.feature
|
51
|
+
- features/steps/mharris_ext_steps.rb
|
52
|
+
- features/support/env.rb
|
53
|
+
- lib/mharris_ext.rb
|
54
|
+
- lib/mharris_ext/accessor.rb
|
55
|
+
- lib/mharris_ext/benchmark.rb
|
56
|
+
- lib/mharris_ext/cmd.rb
|
57
|
+
- lib/mharris_ext/enumerable.rb
|
58
|
+
- lib/mharris_ext/fileutils.rb
|
59
|
+
- lib/mharris_ext/from_hash.rb
|
60
|
+
- lib/mharris_ext/gems.rb
|
61
|
+
- lib/mharris_ext/methods.rb
|
62
|
+
- lib/mharris_ext/object.rb
|
63
|
+
- lib/mharris_ext/regexp.rb
|
64
|
+
- lib/mharris_ext/time.rb
|
65
|
+
- mharris_ext.gemspec
|
66
|
+
- test/mharris_ext_test.rb
|
67
|
+
- test/test_helper.rb
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: http://github.com/GFunk911/mharris_ext
|
70
|
+
licenses: []
|
71
|
+
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options:
|
74
|
+
- --charset=UTF-8
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: "0"
|
82
|
+
version:
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: "0"
|
88
|
+
version:
|
89
|
+
requirements: []
|
90
|
+
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 1.3.5
|
93
|
+
signing_key:
|
94
|
+
specification_version: 3
|
95
|
+
summary: mharris717 utility methods
|
96
|
+
test_files:
|
97
|
+
- test/mharris_ext_test.rb
|
98
|
+
- test/test_helper.rb
|