Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Ind.ie Projects
h2c2
Commits
ab7a51f4
Commit
ab7a51f4
authored
Oct 30, 2014
by
Aral Balkan
Browse files
Added an optional secret to the code generation and regenerated the first batch of invite codes.
parent
21749620
Changes
2
Hide whitespace changes
Inline
Side-by-side
.gitignore
View file @
ab7a51f4
node_modules
.DS_Store
\ No newline at end of file
.DS_Store
secret.txt
\ No newline at end of file
CodeGenerator.coffee
View file @
ab7a51f4
shorthash
=
require
'shorthash'
uuid
=
require
'uuid'
fs
=
require
'fs'
assert
=
require
'assert'
#
# Implementation of hash sieve algorithm that I read
# about at http://www.shamasis.net/2009/09/fast-algorithm-to-find-unique-items-in-javascript-array/
# in CoffeeScript with slightly more literate code :)
#
Array
.
prototype
.
unique
=
->
hashSieve
=
{}
arrayOfUniqueValues
=
[];
for
item
in
@
hashSieve
[
item
]
=
item
for
item
of
hashSieve
arrayOfUniqueValues
.
push
item
return
arrayOfUniqueValues
class
CodeGenerator
secret
:
''
folder
:
null
folderExists
:
false
...
...
@@ -12,18 +32,28 @@ class CodeGenerator
# do not accidentally overwrite earlier ones
@
folder
=
'codes/'
+
Date
.
now
()
if
fs
.
existsSync
(
'secret.txt'
)
@
secret
=
fs
.
readFileSync
'secret.txt'
generateUniqueCodes
:
(
numCodes
)
=>
codes
=
[]
i
=
numCodes
while
numCodes
uniqueCode
=
uuid
.
v4
()
+
'-'
+
Date
.
now
()
while
i
uniqueCode
=
uuid
.
v4
()
+
@
secret
+
'-'
+
Date
.
now
()
shortUniqueCode
=
shorthash
.
unique
(
uniqueCode
)
codes
.
push
shortUniqueCode
numCodes
--
i
--
codes
=
codes
.
unique
()
# Just to make sure.
assert
.
equal
codes
.
length
,
numCodes
,
'All codes must be unique.'
return
codes
generateUniqueCodesAndSaveToFile
:
(
numCodes
,
fileNameToSaveTo
)
=>
codes
=
@
generateUniqueCodes
(
numCodes
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment