Skip to content

Conversation

@vinc
Copy link

@vinc vinc commented Jun 15, 2014

I wanted to generate lowercase alphanumeric tokens so I modified the Generator module to do that and the same for uppercase. I added %a and %A quite arbitrary, maybe there's a better letter.

I'm using the mongoid-4 branch and the code contains a new helper function rand_string_from_chars so my PR is based on this branch instead of master.

@thetron
Copy link
Owner

thetron commented Jul 12, 2014

@vinc Thanks for this - I hadn't considered that this might be a use case. The current master branch also resolves the build error you're having on Travis, with your branch.

The one thing I will note with your commits is that you transitioned some of the generator methods to rand_string_from_chars. Whilst this seems sensible, the less attractive methods for generating the tokens (which came out of an older pull request by another user) are significantly faster. This is the result of a quick benchmark comparing the 'ugly' version, with the rand_string_from_chars version (50,000 tokens of length 100):

ugly (50000)                    0.230000   0.000000   0.230000 (  0.227429)
rand_string_from_chars (50000)  1.360000   0.000000   1.360000 (  1.359790)

I've actually been meaning to migrate some of the other generator methods to the more optimal style.

If you don't mind rolling back some of those bigger changes, I'd be more than happy to include your upper and lower alphanumeric token!

Thanks again for your contribution! 🍰

williamatodd added a commit to williamatodd/mongoid_token that referenced this pull request Apr 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants