Giter Club home page Giter Club logo

puid's Introduction

GoDoc Build Status

puid, like cuid (Collision-Resistant IDs)

Please refer to the main project site for the full rationale behind CUIDs.

Almost all of the rationale stands except than with an puid, you can vary the initial character (or prefix) -- it's not just a fixed c.

My use case is that I want to use that character as a type hint. Purely a visual thing.

NB You can easily break the URL-Safety that CUIDs guarrantee by using stupid prefixes. I define this as user error, the puid library makes no attempt to stop you from doing this.

Otherwise the library and implementation is compliant and marginally faster than the main Go implementation (lucsky/cuid). Thats probably because I don't use exactly the same alogorithm for generating the fingerprint and random data. Now the random data is fine - as long as it is random enough, I cannot see how it matters. The fingerprint bit is different though, because maybe we want the hostname portion of the default fingerprint to match across languages? Personally, I don't really care about that.

subjective `go test -bench=.` output

Run on my laptop, pinch of salt necessary

Benchmark_LucskyCuid* imports lucsky/cuid from "github.com/lucsky/cuid" for the tip and "gopkg.in/lucsky/cuid.v1" for v1.

$  go test -run=XXX -bench=.
Benchmark_PuidString         3000000           417 ns/op
Benchmark_PuidBytes          5000000           367 ns/op
Benchmark_PuidAppendBytes    5000000           354 ns/op
Benchmark_PuidInCuidMode     3000000           413 ns/op
Benchmark_LucskyCuidV1       3000000           559 ns/op
Benchmark_LucskyCuidTip      3000000           562 ns/op
PASS
ok      github.com/thechriswalker/puid  12.193s

Event more reason to question this is that technically Benchmark_PuidString and Benchmark_PuidInCuidMode are doing exactly the same work...

Also, ~500ns is not very long.

install

$ go get github.com/thechriswalker/puid/...

use as a tool

If your $GOPATH/$GOBIN is all setup, then you should be able to run

$ puid
pj34aln7t0000cars6wqeent6
$ puid d
dj34alh5d0000carshj2ctw8e
$ puid foo: bar:
foo:j34al93s0000carskgw1gt3q
bar:j34al93s0001carskzagqwy2
$ puid -count=10
pj34am4tg0000carsa3zp2gqh
pj34am4th0001cars809dw0k0
pj34am4th0002carsgh2xlo91
pj34am4th0003carsnrt75ob7
pj34am4th0004cars9v53axm5
pj34am4th0005carsnmzjbaoj
pj34am4ti0006carsd2wxrfks
pj34am4ti0007cars32qh9yq9
pj34am4ti0008carsezmwei9e
pj34am4ti0009carsm5pziq9m

use as a lib

docs on godoc.org

or see cmd/puid/main.go

or run puid -example

customization the generator

More customization can be made to the id generator, you can supply a custom fingerprint, random data source, or counter as well as the prefix. see the docs for info

acknowledgements

Firstly, ericelliott for CUIDs which are awesome. Secondly, lucsky for his implementation of CUID in golang which inspired this.

puid's People

Contributors

thechriswalker avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.