armoredcode-misc 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.swp
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/.rvmrc ADDED
@@ -0,0 +1,48 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional,
7
+ # Only full ruby name is supported here, for short names use:
8
+ # echo "rvm use 1.9.3" > .rvmrc
9
+ environment_id="ruby-1.9.3-p194@armored-misc"
10
+
11
+ # Uncomment the following lines if you want to verify rvm version per project
12
+ # rvmrc_rvm_version="1.14.2 ()" # 1.10.1 seams as a safe start
13
+ # eval "$(echo ${rvm_version}.${rvmrc_rvm_version} | awk -F. '{print "[[ "$1*65536+$2*256+$3" -ge "$4*65536+$5*256+$6" ]]"}' )" || {
14
+ # echo "This .rvmrc file requires at least RVM ${rvmrc_rvm_version}, aborting loading."
15
+ # return 1
16
+ # }
17
+
18
+ # First we attempt to load the desired environment directly from the environment
19
+ # file. This is very fast and efficient compared to running through the entire
20
+ # CLI and selector. If you want feedback on which environment was used then
21
+ # insert the word 'use' after --create as this triggers verbose mode.
22
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments"
23
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
24
+ then
25
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
26
+ [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]] &&
27
+ \. "${rvm_path:-$HOME/.rvm}/hooks/after_use" || true
28
+ else
29
+ # If the environment file has not yet been created, use the RVM CLI to select.
30
+ rvm --create "$environment_id" || {
31
+ echo "Failed to create RVM environment '${environment_id}'."
32
+ return 1
33
+ }
34
+ fi
35
+
36
+ # If you use bundler, this might be useful to you:
37
+ # if [[ -s Gemfile ]] && {
38
+ # ! builtin command -v bundle >/dev/null ||
39
+ # builtin command -v bundle | GREP_OPTIONS= \grep $rvm_path/bin/bundle >/dev/null
40
+ # }
41
+ # then
42
+ # printf "%b" "The rubygem 'bundler' is not installed. Installing it now.\n"
43
+ # gem install bundler
44
+ # fi
45
+ # if [[ -s Gemfile ]] && builtin command -v bundle >/dev/null
46
+ # then
47
+ # bundle install | GREP_OPTIONS= \grep -vE '^Using|Your bundle is complete'
48
+ # fi
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in armoredcode-misc.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Paolo Perego
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,38 @@
1
+ # Armoredcode Miscellaneous utilities
2
+
3
+ This is just a set of miscellaneous utilities I wrote to speed up some annoying
4
+ tasks for security tools (and not) I'm writing.
5
+
6
+ ## API
7
+
8
+ Just start requiring the gem
9
+
10
+ require 'armoredcode-misc'
11
+
12
+ And the following APIs will be available:
13
+
14
+ * Fixnum.duration: it prints out in a human readable way a numeric value understood as time duration interval
15
+ * String.starts_with?(pattern): it says if a string it is starting with a given pattern
16
+
17
+
18
+ ## Installation
19
+
20
+ Add this line to your application's Gemfile:
21
+
22
+ gem 'armoredcode-misc'
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install armoredcode-misc
31
+
32
+ ## Contributing
33
+
34
+ 1. Fork it
35
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
36
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
37
+ 4. Push to the branch (`git push origin my-new-feature`)
38
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new
7
+
8
+ task :default => :spec
9
+ task :test => :spec
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/armoredcode-misc/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Paolo Perego"]
6
+ gem.email = ["paolo@armoredcode.com"]
7
+ gem.description = %q{This gem contains some miscellaneous utilities for armoredcode security tools}
8
+ gem.summary = %q{This gem contains some miscellaneous utilities for armoredcode security tools}
9
+ gem.homepage = "http://armoredcode.com"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "armoredcode-misc"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Armoredcode::Misc::VERSION
17
+
18
+
19
+ gem.add_development_dependency 'rake'
20
+ gem.add_development_dependency 'rspec'
21
+ end
@@ -0,0 +1,4 @@
1
+ require "armoredcode-misc/version"
2
+ require "armoredcode-misc/numeric"
3
+ require "armoredcode-misc/string"
4
+
@@ -0,0 +1,13 @@
1
+ class Numeric
2
+ def duration
3
+ secs = self.to_int
4
+ mins = secs / 60
5
+ hours = mins / 60
6
+ days = hours / 24
7
+
8
+ return "#{days} days and #{hours % 24} hours" if days > 0
9
+ return "#{hours} hours and #{mins % 60} minutes" if days == 0 and hours > 0
10
+ return "#{mins} minutes and #{secs % 60} seconds" if days == 0 and hours == 0 and mins > 0
11
+ return "#{secs} seconds" if days == 0 and hours == 0 and mins == 0
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ class String
2
+ def starts_with?(pattern)
3
+ ! self.match(/^#{pattern}/).nil?
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Armoredcode
2
+ module Misc
3
+ VERSION = "0.10.0"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Numeric do
4
+ it "should say just a second it has been elapsed" do
5
+ 1.duration.should == "1 seconds"
6
+ end
7
+
8
+ it "should say 59 seconds they have been elapsed" do
9
+ 59.duration.should == "59 seconds"
10
+ end
11
+
12
+ it "should say 3 minutes and something they have been elapsed" do
13
+ 183.duration.should == "3 minutes and 3 seconds"
14
+ end
15
+
16
+ it "should say 1 hour and something they have been elapsed" do
17
+ 3601.duration.should == "1 hours and 0 minutes"
18
+ end
19
+
20
+ it "should say 1 hour and something they have been elapsed" do
21
+ 3720.duration.should == "1 hours and 2 minutes"
22
+ end
23
+
24
+ it "should say 3 days and something" do
25
+ 259320.duration.should == "3 days and 0 hours"
26
+ end
27
+
28
+ end
@@ -0,0 +1 @@
1
+ require 'armoredcode-misc'
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe String do
4
+
5
+ it "should understand if a string is starting with a pattern" do
6
+ "testthisyes".starts_with?("test").should be_true
7
+ "testthisyes".starts_with?("te").should be_true
8
+ "testthisyes".starts_with?("testthi").should be_true
9
+ "testthisyes".starts_with?("testthisyes").should be_true
10
+ end
11
+
12
+ it "should understand if a string is not starting with a pattern" do
13
+ "testthisyes".starts_with?("foobar").should be_false
14
+ end
15
+
16
+ it "should handle special cases with a true value" do
17
+ "testthisyes".starts_with?("").should be_true
18
+ "testthisyes".starts_with?(nil).should be_true
19
+ end
20
+
21
+ end
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: armoredcode-misc
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.10.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Paolo Perego
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rspec
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: This gem contains some miscellaneous utilities for armoredcode security
47
+ tools
48
+ email:
49
+ - paolo@armoredcode.com
50
+ executables: []
51
+ extensions: []
52
+ extra_rdoc_files: []
53
+ files:
54
+ - .gitignore
55
+ - .rvmrc
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - armoredcode-misc.gemspec
61
+ - lib/armoredcode-misc.rb
62
+ - lib/armoredcode-misc/numeric.rb
63
+ - lib/armoredcode-misc/string.rb
64
+ - lib/armoredcode-misc/version.rb
65
+ - spec/numeric_spec.rb
66
+ - spec/spec_helper.rb
67
+ - spec/string_spec.rb
68
+ homepage: http://armoredcode.com
69
+ licenses: []
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ segments:
81
+ - 0
82
+ hash: -1174476621528986780
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ none: false
85
+ requirements:
86
+ - - ! '>='
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ segments:
90
+ - 0
91
+ hash: -1174476621528986780
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 1.8.24
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: This gem contains some miscellaneous utilities for armoredcode security tools
98
+ test_files:
99
+ - spec/numeric_spec.rb
100
+ - spec/spec_helper.rb
101
+ - spec/string_spec.rb