Giter VIP home page Giter VIP logo

perl6-cuid's Introduction

CUID

CUID generator for Perl 6.

Build Status

Description

Once CPU power and host machines are increased, UUIDs become prone to collisions. To avoid such collisions, developers often resort to database round trips just to check/detect a possible collision, and thus, perform a new ID generation which doesn't collide. But nowadays, databases are the major software bottleneck of our services, and that round trips are too expensive (we lost scalability a lot)!

CUIDs are a solution for that sort of problem. Due the monotonically increasing nature, we can also leverage that to improve database performance (most specifically, dealing with primary keys). CUIDs contain host machine fingerprints to avoid ID collision among the network nodes, and they could even work generating CUIDs offline without any problem.

For more information, see: http://usecuid.org

Important Notes

This library is thread-safe regarding internal state counter.

Installation

Inside this root directory project, just type:

$ zef --force install .

As an alternative, you could type as well:

$ make install

Usage

To generate full CUIDs, use the cuid function:

use CUID;

my $cuid = cuid( );

$cuid.say; # ===> c1xyr5kms0000qb8qtlakvjsj

For slugs (short and weak CUIDs), use the following cuid-slug function:

use CUID;

my $cuid-slug = cuid-slug( );

$cuid-slug.say; # ===> f900qqno

Final Notes

Happy hacking, kiddo!

perl6-cuid's People

Contributors

marcoonroad avatar

Stargazers

 avatar

Watchers

 avatar  avatar

perl6-cuid's Issues

Cuid standard is deprecated.

Due to security concerns (which also exist in database auto-increment ids, uuid/guid, and most other id standrads), the Cuid standard is now deprecated in favor of Cuid2.

Base-36 conversion rather than hexadecimal one (i.e, base-16).

The original CUID specification (at http://usecuid.org ๐Ÿ”—) uses base-36 conversions instead of the current base-16 (which we have implemented here).

The following lines of code describe our current state of affairs:

my $maximum = 16 ** 4;

And:

sub to-hexadecimal($number) { "%08x".sprintf($number) }

In Perl 6, it's quite trivial to enforce base-36 conversion, we just need to replace the latter piece of code above by the following below ๐Ÿ˜ƒ :

sub to-base36($number) { "%08s".sprintf($number.base(36)) }

And everything is fine! ๐Ÿ™ ๐Ÿ™ ๐Ÿ™ ๐Ÿ™

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.