strandom 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +20 -0
- data/README.md +50 -0
- data/bin/strandom +106 -0
- data/lib/strandom.rb +47 -0
- metadata +48 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0b5a22e7e57c0a87c41790a298e1e6cf706fae8b
|
4
|
+
data.tar.gz: 9eae36ae5b22ff3eeb1b450848d5cd5bd7ec5321
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 68c9c5a5830cca554c554382a138bd59393a71c41e75b824fcc57da328e64f70ce16a23606ca5bd080f8b1eb497ff5b9e4cb23aeb482ab1372f010b4895700ff
|
7
|
+
data.tar.gz: 87b60ab5dac3a7b368f2de1853a3b4f5208f7dcbd2161df81f594c32319747fc76bb902a84fca7b6851d726869d7d3d9f9566d3d5afa90ab3c2b52b079cda607
|
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Z. D. Peacock
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Thoom::Strandom
|
2
|
+
Random string command line script
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
gem install strandom
|
7
|
+
|
8
|
+
## CLI HELP
|
9
|
+
|
10
|
+
Usage: strandom [options]
|
11
|
+
|
12
|
+
Specific options:
|
13
|
+
--alnum [length] Characters a-z, A-Z, 0-9
|
14
|
+
--alpha [length] Characters a-z, A-Z
|
15
|
+
--custom values,[length],[delimiter]
|
16
|
+
Provide a custom set of values to build the string
|
17
|
+
--lower [length] Characters a-z
|
18
|
+
--lownum [length] Characters a-z, 0-9
|
19
|
+
--hex [length] Characters a-f, 0-9
|
20
|
+
--num [length] Characters 0-9
|
21
|
+
--uuid UUID v4 string
|
22
|
+
--upper [length] Characters A-Z
|
23
|
+
--upnum [length] Characters A-Z, 0-9
|
24
|
+
|
25
|
+
Common options:
|
26
|
+
--help Shows this message
|
27
|
+
--version Current version
|
28
|
+
|
29
|
+
### Examples
|
30
|
+
#### Basic
|
31
|
+
|
32
|
+
$ strandom --lownum 10
|
33
|
+
=> eh8zuzk71s
|
34
|
+
|
35
|
+
#### UUID
|
36
|
+
|
37
|
+
$ strandom --uuid
|
38
|
+
=> 89657eaf-4e07-43a7-b3de-b7d1f3c26940
|
39
|
+
|
40
|
+
#### Custom
|
41
|
+
|
42
|
+
strandom --custom [String of values to randomize],[length of string],[String delimiter, defaults to single character]
|
43
|
+
|
44
|
+
Examples:
|
45
|
+
|
46
|
+
$ strandom --custom "%4*?",10
|
47
|
+
=> *%44*?%4**
|
48
|
+
|
49
|
+
$ strandom --custom "%|4|*|,|?",10,"|"
|
50
|
+
=> ??4,%%,*%4
|
data/bin/strandom
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'strandom'
|
5
|
+
|
6
|
+
type = :alnum
|
7
|
+
len = 32
|
8
|
+
cust_vals = ''
|
9
|
+
cust_delimiter = ''
|
10
|
+
|
11
|
+
parser = OptionParser.new do |o|
|
12
|
+
o.banner = 'Usage: strandom [options]'
|
13
|
+
o.separator ""
|
14
|
+
o.separator "Specific options:"
|
15
|
+
|
16
|
+
o.on('--alnum [length]', 'Characters a-z, A-Z, 0-9') do |length|
|
17
|
+
type = :alnum
|
18
|
+
len = length if length
|
19
|
+
end
|
20
|
+
|
21
|
+
o.on('--alpha [length]', 'Characters a-z, A-Z') do |length|
|
22
|
+
type = :alpha
|
23
|
+
len = length if length
|
24
|
+
end
|
25
|
+
|
26
|
+
o.on('--custom values,[length],[delimiter]', Array, 'Provide a custom set of values to build the string') do |custom|
|
27
|
+
values, length, delimiter = custom
|
28
|
+
# puts "len #{length}\nvalues #{values}\ndelimiter #{delimiter}"
|
29
|
+
|
30
|
+
type = :custom
|
31
|
+
len = length if length
|
32
|
+
cust_vals = values if values
|
33
|
+
cust_delimiter = delimiter if delimiter
|
34
|
+
end
|
35
|
+
|
36
|
+
o.on('--lower [length]', 'Characters a-z') do |length|
|
37
|
+
type = :lower
|
38
|
+
len = length if length
|
39
|
+
end
|
40
|
+
|
41
|
+
o.on('--lownum [length]', 'Characters a-z, 0-9') do |length|
|
42
|
+
type = :lownum
|
43
|
+
len = length if length
|
44
|
+
end
|
45
|
+
|
46
|
+
o.on('--hex [length]', 'Characters a-f, 0-9') do |length|
|
47
|
+
type = :hex
|
48
|
+
len = length if length
|
49
|
+
end
|
50
|
+
|
51
|
+
o.on('--num [length]', 'Characters 0-9') do |length|
|
52
|
+
type = :num
|
53
|
+
len = length if length
|
54
|
+
end
|
55
|
+
|
56
|
+
o.on('--uuid', 'UUID v4 string') do
|
57
|
+
type = :uuid
|
58
|
+
end
|
59
|
+
|
60
|
+
o.on('--upper [length]', 'Characters A-Z') do |length|
|
61
|
+
type = :upper
|
62
|
+
len = length if length
|
63
|
+
end
|
64
|
+
|
65
|
+
o.on('--upnum [length]', 'Characters A-Z, 0-9') do |length|
|
66
|
+
type = :upnum
|
67
|
+
len = length if length
|
68
|
+
end
|
69
|
+
|
70
|
+
o.separator ""
|
71
|
+
o.separator "Common options:"
|
72
|
+
|
73
|
+
o.on_tail('--help', 'Shows this message') do
|
74
|
+
puts o
|
75
|
+
exit
|
76
|
+
end
|
77
|
+
|
78
|
+
o.on_tail('--version', 'Current version') do
|
79
|
+
puts <<TXT
|
80
|
+
|
81
|
+
Thoom Strandom v.1.0
|
82
|
+
--------------------
|
83
|
+
e: zdp@thoomtech.com
|
84
|
+
w: https://github.com/thoom/randstr
|
85
|
+
|
86
|
+
TXT
|
87
|
+
exit
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
parser.parse! ARGV
|
92
|
+
|
93
|
+
len = len.to_i
|
94
|
+
if type == :hex
|
95
|
+
result = Thoom::Strandom.hex(len: len)
|
96
|
+
elsif type == :uuid
|
97
|
+
result = Thoom::Strandom.uuid()
|
98
|
+
elsif type == :custom
|
99
|
+
cust = cust_vals.split(cust_delimiter)
|
100
|
+
result = Thoom::Strandom.rand(len: len, type: type, cust: cust)
|
101
|
+
else
|
102
|
+
result = Thoom::Strandom.rand(len: len, type: type)
|
103
|
+
end
|
104
|
+
|
105
|
+
puts result
|
106
|
+
|
data/lib/strandom.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'securerandom'
|
2
|
+
|
3
|
+
module Thoom
|
4
|
+
class Strandom
|
5
|
+
class << self
|
6
|
+
def hex(len: 2)
|
7
|
+
SecureRandom.hex(len / 2)
|
8
|
+
end
|
9
|
+
|
10
|
+
def rand(len: 0, type: :alnum, cust: [])
|
11
|
+
num = (48..57).to_a
|
12
|
+
upper = (65..90).to_a
|
13
|
+
lower = (97..122).to_a
|
14
|
+
|
15
|
+
case type
|
16
|
+
when :alpha
|
17
|
+
range = upper + lower
|
18
|
+
when :upper
|
19
|
+
range = upper
|
20
|
+
when :upnum
|
21
|
+
range = num + upper
|
22
|
+
when :lower
|
23
|
+
range = lower
|
24
|
+
when :lownum
|
25
|
+
range = num + lower
|
26
|
+
when :num
|
27
|
+
range = num
|
28
|
+
when :custom
|
29
|
+
range = cust
|
30
|
+
else
|
31
|
+
range = num + upper + lower
|
32
|
+
end
|
33
|
+
|
34
|
+
# pulled from http://codereview.stackexchange.com/questions/15958
|
35
|
+
if type == :cust
|
36
|
+
([nil] * len).map { range.sample }.join
|
37
|
+
else
|
38
|
+
([nil] * len).map { range.sample.chr }.join
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def uuid()
|
43
|
+
SecureRandom.uuid
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: strandom
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Z.d. Peacock
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: An executable for generating a random string
|
14
|
+
email: zdp@thoomtech.com
|
15
|
+
executables:
|
16
|
+
- strandom
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- LICENSE
|
21
|
+
- README.md
|
22
|
+
- bin/strandom
|
23
|
+
- lib/strandom.rb
|
24
|
+
homepage: http://github.com/thoom/strandom
|
25
|
+
licenses:
|
26
|
+
- MIT
|
27
|
+
metadata: {}
|
28
|
+
post_install_message:
|
29
|
+
rdoc_options: []
|
30
|
+
require_paths:
|
31
|
+
- lib
|
32
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
requirements: []
|
43
|
+
rubyforge_project:
|
44
|
+
rubygems_version: 2.4.7
|
45
|
+
signing_key:
|
46
|
+
specification_version: 4
|
47
|
+
summary: 'Thoom Strandom: A random string generator'
|
48
|
+
test_files: []
|