Skip to content

Instantly share code, notes, and snippets.

@alandipert
Created March 28, 2010 22:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alandipert/347085 to your computer and use it in GitHub Desktop.
Save alandipert/347085 to your computer and use it in GitHub Desktop.
Imap.prototype.next: ((id, fmt) ->
prefix: (for i in [0...fmt.replace(/0/g, "").length]
(-> this.charAt(Math.random()*this.length))
.call("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
).join("")
fmt: fmt.replace(/X/g, "")
return ( ->
id: ++id % (parseInt(fmt.replace(/0/g, "9")) + 1)
ret: fmt + id
prefix + ret.substring(ret.length - fmt.length)
)
)(0, "XXXX0000")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment