shamazing 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,54 @@
1
+ # shamazing
2
+
3
+ A library to discover amazing things about a SHA1 hash (or MD5 or whatever).
4
+ It's **sha**-mazing. Almost as shamazing as that pun.
5
+
6
+ ## Areas of shamazingness
7
+
8
+ - Longest string (9c2**cddfaedaea**9689a22e376aa20191041554fe8)
9
+ - Longest integer (9c2cddfaedaea9689a22e376aa**20191041554**fe8)
10
+
11
+ ## Install
12
+
13
+ gem install shamazing
14
+
15
+ ## Usage
16
+
17
+ ### Command Line Interface
18
+
19
+ ```sh
20
+ $ shamazing 9c2cddfaedaea9689a22e376aa20191041554fe8
21
+ Longest string: cddfaedaea
22
+ Longest integer: 20191041554
23
+
24
+ $ shamazing 9c2cddfaedaea9689a22e376aa20191041554fe8 --string
25
+ cddfaedaea
26
+
27
+ $ shamazing 9c2cddfaedaea9689a22e376aa20191041554fe8 -s
28
+ cddfaedaea
29
+
30
+ $ shamazing 9c2cddfaedaea9689a22e376aa20191041554fe8 --integer
31
+ 20191041554
32
+
33
+ $ shamazing 9c2cddfaedaea9689a22e376aa20191041554fe8 -i
34
+ 20191041554
35
+ ```
36
+
37
+ ### Ruby Interface
38
+
39
+ ```ruby
40
+ require 'shamazing'
41
+
42
+ sha = '9c2cddfaedaea9689a22e376aa20191041554fe8'
43
+
44
+ Shamazing.string(sha)
45
+ # => cddfaedaea
46
+
47
+ Shamazing.integer(sha)
48
+ # => 20191041554
49
+ ```
50
+
51
+ ## An Holman Project
52
+
53
+ Just a little diddy for dicking around with all these hashes. Made by
54
+ [@holman](https://twitter.com/holman).
data/Rakefile ADDED
@@ -0,0 +1,134 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'date'
4
+
5
+ #############################################################################
6
+ #
7
+ # Helper functions
8
+ #
9
+ #############################################################################
10
+
11
+ def name
12
+ @name ||= Dir['*.gemspec'].first.split('.').first
13
+ end
14
+
15
+ def version
16
+ line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
17
+ line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
18
+ end
19
+
20
+ def date
21
+ Date.today.to_s
22
+ end
23
+
24
+ def rubyforge_project
25
+ name
26
+ end
27
+
28
+ def gemspec_file
29
+ "#{name}.gemspec"
30
+ end
31
+
32
+ def gem_file
33
+ "#{name}-#{version}.gem"
34
+ end
35
+
36
+ def replace_header(head, header_name)
37
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
38
+ end
39
+
40
+ #############################################################################
41
+ #
42
+ # Standard tasks
43
+ #
44
+ #############################################################################
45
+
46
+ task :default => :test
47
+
48
+ require 'rake/testtask'
49
+ Rake::TestTask.new(:test) do |test|
50
+ test.libs << 'lib' << 'test'
51
+ test.pattern = 'test/**/test_*.rb'
52
+ test.verbose = true
53
+ end
54
+
55
+ desc "Open an irb session preloaded with this library"
56
+ task :console do
57
+ sh "irb -rubygems -r ./lib/#{name}.rb"
58
+ end
59
+
60
+ #############################################################################
61
+ #
62
+ # Custom tasks (add your own tasks here)
63
+ #
64
+ #############################################################################
65
+
66
+
67
+
68
+ #############################################################################
69
+ #
70
+ # Packaging tasks
71
+ #
72
+ #############################################################################
73
+
74
+ desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
75
+ task :release => :build do
76
+ unless `git branch` =~ /^\* master$/
77
+ puts "You must be on the master branch to release!"
78
+ exit!
79
+ end
80
+ sh "git commit --allow-empty -a -m 'Release #{version}'"
81
+ sh "git tag v#{version}"
82
+ sh "git push origin master"
83
+ sh "git push origin v#{version}"
84
+ sh "gem push pkg/#{name}-#{version}.gem"
85
+ end
86
+
87
+ desc "Build #{gem_file} into the pkg directory"
88
+ task :build => :gemspec do
89
+ sh "mkdir -p pkg"
90
+ sh "gem build #{gemspec_file}"
91
+ sh "mv #{gem_file} pkg"
92
+ end
93
+
94
+ desc "Generate #{gemspec_file}"
95
+ task :gemspec => :validate do
96
+ # read spec file and split out manifest section
97
+ spec = File.read(gemspec_file)
98
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
99
+
100
+ # replace name version and date
101
+ replace_header(head, :name)
102
+ replace_header(head, :version)
103
+ replace_header(head, :date)
104
+ #comment this out if your rubyforge_project has a different name
105
+ replace_header(head, :rubyforge_project)
106
+
107
+ # determine file list from git ls-files
108
+ files = `git ls-files`.
109
+ split("\n").
110
+ sort.
111
+ reject { |file| file =~ /^\./ }.
112
+ reject { |file| file =~ /^(rdoc|pkg)/ }.
113
+ map { |file| " #{file}" }.
114
+ join("\n")
115
+
116
+ # piece file back together and write
117
+ manifest = " s.files = %w[\n#{files}\n ]\n"
118
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
119
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
120
+ puts "Updated #{gemspec_file}"
121
+ end
122
+
123
+ desc "Validate #{gemspec_file}"
124
+ task :validate do
125
+ libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
126
+ unless libfiles.empty?
127
+ puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
128
+ exit!
129
+ end
130
+ unless Dir['VERSION*'].empty?
131
+ puts "A `VERSION` file at root level violates Gem best practices."
132
+ exit!
133
+ end
134
+ end
data/bin/shamazing ADDED
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # USAGE
4
+ #
5
+ # $ shamazing 9c2cddfaedaea9689a22e376aa20191041554fe8
6
+ # Longest string: cddfaedaea
7
+ # Longest integer: 20191041554
8
+ #
9
+ # $ shamazing 9c2cddfaedaea9689a22e376aa20191041554fe8 --string
10
+ # cddfaedaea
11
+ #
12
+ # $ shamazing 9c2cddfaedaea9689a22e376aa20191041554fe8 -s
13
+ # cddfaedaea
14
+ #
15
+ # $ shamazing 9c2cddfaedaea9689a22e376aa20191041554fe8 --integer
16
+ # 20191041554
17
+ #
18
+ # $ shamazing 9c2cddfaedaea9689a22e376aa20191041554fe8 -i
19
+ # 20191041554
20
+
21
+ require 'optparse'
22
+ require 'lib/shamazing'
23
+
24
+ options = {
25
+ :string => false,
26
+ :integer => false
27
+ }
28
+
29
+ parser = OptionParser.new do |opts|
30
+ opts.banner = "Usage: shamazing SHA [options]"
31
+
32
+ opts.separator ""
33
+ opts.separator " SHA is a SHA1 hash (or other string to check)"
34
+
35
+ opts.separator ""
36
+ opts.separator "Options:"
37
+
38
+ opts.on("-s", "--string", "The longest String in this SHA") do
39
+ options[:string] = true
40
+ end
41
+
42
+ opts.on("-i", "--integer", "The longest Integer in this SHA") do
43
+ options[:integer] = true
44
+ end
45
+
46
+ opts.on("-h", "--help", "Show this message") do
47
+ puts opts
48
+ exit
49
+ end
50
+ end
51
+
52
+ parser.parse!
53
+ sha = *ARGV
54
+
55
+ if options[:string] && !options[:integer]
56
+ puts Shamazing.string(sha)
57
+ elsif options[:integer]
58
+ puts Shamazing.integer(sha)
59
+ else
60
+ puts "Longest string: #{Shamazing.string(sha)}"
61
+ puts "Longest integer: #{Shamazing.integer(sha)}"
62
+ end
data/lib/shamazing.rb ADDED
@@ -0,0 +1,24 @@
1
+ class Shamazing
2
+ VERSION = '0.0.1'
3
+
4
+ # Finds the longest continuous String in a sha.
5
+ #
6
+ # Returns a String.
7
+ def self.string(sha)
8
+ sha.
9
+ downcase.
10
+ scan(/[a-f]+/).
11
+ sort{|a,b| b.length <=> a.length}.
12
+ first
13
+ end
14
+
15
+ # Finds the longest continuous Integer in a sha.
16
+ #
17
+ # Returns an Integer.
18
+ def self.integer(sha)
19
+ sha.
20
+ scan(/[0-9]+/).
21
+ sort{|a,b| b.length <=> a.length}.
22
+ first.to_i
23
+ end
24
+ end
data/shamazing.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ Gem::Specification.new do |s|
2
+ s.specification_version = 2 if s.respond_to? :specification_version=
3
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
4
+ s.rubygems_version = '1.3.5'
5
+
6
+ s.name = 'shamazing'
7
+ s.version = '0.0.1'
8
+ s.date = '2012-03-27'
9
+ s.rubyforge_project = 'shamazing'
10
+
11
+ s.summary = "Short description used in Gem listings."
12
+ s.description = "A library to discover amazing things about a SHA1 hash "+
13
+ "(or MD5 or whatever). It's sha-mazing. Almost as shamazing "+
14
+ "as that pun."
15
+
16
+ s.authors = ["Zach Holman"]
17
+ s.email = 'zach@zachholman.com'
18
+ s.homepage = 'https://github.com/holman/shamazing'
19
+
20
+ s.require_paths = %w[lib]
21
+
22
+ s.executables = ["shamazing"]
23
+
24
+ # = MANIFEST =
25
+ s.files = %w[
26
+ README.md
27
+ Rakefile
28
+ bin/shamazing
29
+ lib/shamazing.rb
30
+ shamazing.gemspec
31
+ test/test_shamazing.rb
32
+ ]
33
+ # = MANIFEST =
34
+
35
+ s.test_files = s.files.select { |path| path =~ /^test\/test_.*\.rb/ }
36
+ end
@@ -0,0 +1,37 @@
1
+ require 'test/unit'
2
+ require 'lib/shamazing'
3
+
4
+ class TestShamazing < Test::Unit::TestCase
5
+ def setup
6
+ @sha = '9c2cddfaedaea9689a22e376aa20191041554fe8'
7
+ end
8
+
9
+ def test_string
10
+ assert_equal 'cddfaedaea', Shamazing.string(@sha)
11
+ end
12
+
13
+ def test_string_downcase
14
+ assert_equal 'cddfaedaea', Shamazing.string(@sha.upcase)
15
+ end
16
+
17
+ def test_integer
18
+ assert_equal 20191041554, Shamazing.integer(@sha)
19
+ end
20
+
21
+ def test_cli
22
+ output = `bin/shamazing #{@sha}`.chomp
23
+
24
+ assert_match /Longest string: cddfaedaea/, output
25
+ assert_match /Longest integer: 20191041554/, output
26
+ end
27
+
28
+ def test_cli_string
29
+ assert_equal 'cddfaedaea', `bin/shamazing #{@sha} -s`.chomp
30
+ assert_equal 'cddfaedaea', `bin/shamazing #{@sha} --string`.chomp
31
+ end
32
+
33
+ def test_cli_integer
34
+ assert_equal '20191041554', `bin/shamazing #{@sha} -i`.chomp
35
+ assert_equal '20191041554', `bin/shamazing #{@sha} --integer`.chomp
36
+ end
37
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shamazing
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Zach Holman
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-03-27 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: A library to discover amazing things about a SHA1 hash (or MD5 or whatever). It's sha-mazing. Almost as shamazing as that pun.
23
+ email: zach@zachholman.com
24
+ executables:
25
+ - shamazing
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - README.md
32
+ - Rakefile
33
+ - bin/shamazing
34
+ - lib/shamazing.rb
35
+ - shamazing.gemspec
36
+ - test/test_shamazing.rb
37
+ has_rdoc: true
38
+ homepage: https://github.com/holman/shamazing
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 3
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project: shamazing
67
+ rubygems_version: 1.5.2
68
+ signing_key:
69
+ specification_version: 2
70
+ summary: Short description used in Gem listings.
71
+ test_files:
72
+ - test/test_shamazing.rb