suid 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +33 -0
- data/spec/suid_spec.rb +21 -0
- metadata +55 -0
data/README.markdown
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
## SUID : A gem to generate sorta unique IDs
|
2
|
+
|
3
|
+
github: http://github.com/dburkes/suid
|
4
|
+
|
5
|
+
## Intro
|
6
|
+
|
7
|
+
SUIDs are sorta unique IDs. A SUID is similar to a UUID, except that SUIDs
|
8
|
+
|
9
|
+
* Are only 11 characters long
|
10
|
+
|
11
|
+
* Are semi human-readable
|
12
|
+
|
13
|
+
* Don't make URLs look ridiculous
|
14
|
+
|
15
|
+
A SUID consists of 11 characters from the set [A-Za-z0-9], so the resulting namespace can hold 62^11 unique values. That's a lot smaller
|
16
|
+
namespace than UUIDs, but, if it's good enough for YouTube URLs, I'm willing to bet it's good enough for a lot of other things too.
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
|
20
|
+
gem install suid
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
SUID.generate => "bEsrB0H2yw1"
|
25
|
+
|
26
|
+
suid = SUID.new
|
27
|
+
suid.to_s => "kwNr8FMYAaO"
|
28
|
+
suit.to_i => 17229968328302299310
|
29
|
+
|
30
|
+
## Notes
|
31
|
+
|
32
|
+
* You can seed the random number generator if you want with `srand`, but ruby does that automatically when it starts up, so, unless
|
33
|
+
you purposefully want to create duplicate SUIDs, don't bother.
|
data/spec/suid_spec.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'lib/suid'
|
2
|
+
|
3
|
+
describe SUID do
|
4
|
+
it "should generate sorta unique ids" do
|
5
|
+
lambda { SUID.generate }.should_not raise_error
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should not generate duplicates in a decent size set" do
|
9
|
+
suids = []
|
10
|
+
1000.times { suids << SUID.generate }
|
11
|
+
suids.size.should == suids.uniq.size
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should generate duplicate suids if instructed to do so" do
|
15
|
+
srand(0xf00)
|
16
|
+
s1 = SUID.generate
|
17
|
+
srand(0xf00)
|
18
|
+
s2 = SUID.generate
|
19
|
+
s1.should == s1
|
20
|
+
end
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: suid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Danny Burkes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-11-20 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: Sorta Unique ID
|
17
|
+
email: dburkes@netable.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.markdown
|
24
|
+
files:
|
25
|
+
- README.markdown
|
26
|
+
has_rdoc: true
|
27
|
+
homepage: http://github.com/dburkes/suid
|
28
|
+
licenses: []
|
29
|
+
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options:
|
32
|
+
- --charset=UTF-8
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: "0"
|
40
|
+
version:
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
requirements: []
|
48
|
+
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.3.5
|
51
|
+
signing_key:
|
52
|
+
specification_version: 3
|
53
|
+
summary: Sorta Unique ID
|
54
|
+
test_files:
|
55
|
+
- spec/suid_spec.rb
|