Security News
Highlights from the 2024 Rails Community Survey
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
io.github.bcarter97:id-generator_2.13
Advanced tools
Generate reproducible UUIDs based of a sequence of numbers, with the possibility of generating sub UUIDs from the parent UUID.
Generate reproducible UUIDs based of a sequence of numbers, with the possibility of generating sub UUIDs from the parent UUID.
In your build.sbt
add:
libraryDependencies += "io.github.bcarter97" %% "id-generator" % "x.x.x"
Then you can use the Generator
like so:
import io.github.bcarter97.Generator
val generator = Generator()
generator.primaryId(5)
// PrimaryId(index=5, uuid=e4da3b7f-bbce-3345-9777-2b0674a318d5, numSubIds=1)
As well as using generator.id(n)
as above, there are a number of ways to generate a PrimaryId.
To sample a random PrimaryId (starting from the first index), use sample
. This will automatically increment the sample index until the specified maxIndex
is reached, at which point it will loop back around.
val generator = Generator(2)
val id1 = generator.sample()
// PrimaryId(index=1, uuid=c4ca4238-a0b9-3382-8dcc-509a6f75849b, numSubIds=9)
val id2 = generator.sample()
// PrimaryId(index=2, uuid=c81e728d-9d4c-3f63-af06-7f89cc14862c, numSubIds=9)
val id3 = generator.sample()
// PrimaryId(index=1, uuid=c4ca4238-a0b9-3382-8dcc-509a6f75849b, numSubIds=9) <-- same as id1
:bulb: Using
id()
without an index will call the underlyingsample
method.
You can sample a range of PrimaryIds by passing a number to sample
:
val ids = generator.sample(2)
// Vector(PrimaryId(index=0, uuid=cfcd2084-95d5-35ef-a6e7-dff9f98764da, numSubIds=9), PrimaryId(index=1, uuid=c4ca4238-a0b9-3382-8dcc-509a6f75849b, numSubIds=9))
Similarly, you can specify the range of UUIDs to generate, to make the list reproducible:
val ids = generator.ids(5, 8)
// Vector(PrimaryId(index=5, uuid=e4da3b7f-bbce-3345-9777-2b0674a318d5, numSubIds=1), PrimaryId(index=6, uuid=1679091c-5a88-3faf-afb5-e6087eb1b2dc, numSubIds=9), PrimaryId(index=7, uuid=8f14e45f-ceea-367a-9a36-dedd4bea2543, numSubIds=6))
SubIds are derived from a PrimaryId. Each PrimaryId has a random, reproducible number of SubIds. Every generated SubId contains the PrimaryId that generated it.
To get a list of subIds from a parentId:
val id = generator.sample()
val subIds = id.subIds
// Vector(SubId(index=1, uuid=6512bd43-d9ca-36e0-ac99-0b0a82652dca, primaryId=PrimaryId(index=1, uuid=c4ca4238-a0b9-3382-8dcc-509a6f75849b, numSubIds=9)) ... )
Any one of these subIds
can find its parentId
.
val id = generator.sample()
// PrimaryId(index=1, uuid=c4ca4238-a0b9-3382-8dcc-509a6f75849b, numSubIds=9)
val subId = id.subIds.head
// SubId(index=1, uuid=6512bd43-d9ca-36e0-ac99-0b0a82652dca, primaryId=PrimaryId(index=1, uuid=c4ca4238-a0b9-3382-8dcc-509a6f75849b, numSubIds=9))
val originalId = generator.subIdFromUuid(subId.uuid)
// Some(SubId(index=1, uuid=6512bd43-d9ca-36e0-ac99-0b0a82652dca, primaryId=PrimaryId(index=1, uuid=c4ca4238-a0b9-3382-8dcc-509a6f75849b, numSubIds=9)))
FAQs
Generate reproducible UUIDs based of a sequence of numbers, with the possibility of generating sub UUIDs from the parent UUID.
We found that io.github.bcarter97:id-generator_2.13 demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A record 2,709 developers participated in the 2024 Ruby on Rails Community Survey, revealing key tools, practices, and trends shaping the Rails ecosystem.
Security News
In 2023, data breaches surged 78% from zero-day and supply chain attacks, but developers are still buried under alerts that are unable to prevent these threats.
Security News
Solo open source maintainers face burnout and security challenges, with 60% unpaid and 60% considering quitting.