{"id":30195468,"url":"https://github.com/matic-insurance/id_generator","last_synced_at":"2025-08-25T01:07:06.055Z","repository":{"id":56877265,"uuid":"153614932","full_name":"matic-insurance/id_generator","owner":"matic-insurance","description":"Ruby Gem to generate random but at the same time timestamped and system identifiable ids","archived":false,"fork":false,"pushed_at":"2024-01-29T13:24:51.000Z","size":28,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-08-13T20:17:19.477Z","etag":null,"topics":["gem","id","ruby","snowflake-twitter"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/matic-insurance.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-18T11:45:21.000Z","updated_at":"2020-06-18T23:58:26.000Z","dependencies_parsed_at":"2022-08-20T11:30:36.293Z","dependency_job_id":null,"html_url":"https://github.com/matic-insurance/id_generator","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/matic-insurance/id_generator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matic-insurance%2Fid_generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matic-insurance%2Fid_generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matic-insurance%2Fid_generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matic-insurance%2Fid_generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/matic-insurance","download_url":"https://codeload.github.com/matic-insurance/id_generator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/matic-insurance%2Fid_generator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271989816,"owners_count":24854702,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-24T02:00:11.135Z","response_time":111,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gem","id","ruby","snowflake-twitter"],"created_at":"2025-08-13T04:18:22.055Z","updated_at":"2025-08-25T01:07:06.042Z","avatar_url":"https://github.com/matic-insurance.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# IdGenerator\n\n[![Build Status](https://travis-ci.org/matic-insurance/id_generator.svg?branch=master)](https://travis-ci.org/matic-insurance/id_generator)\n[![Codacy Badge](https://api.codacy.com/project/badge/Grade/ff827f62fb034d3b8ff71d69a9f0e233)](https://www.codacy.com/app/Matic/id_generator?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=matic-insurance/id_generator\u0026amp;utm_campaign=Badge_Grade)\n\nThis gem provides uniq and random ids generation in distributed services \nbut at the same time gives some ordering (timestamp) and debug (context) information\n\nThe gem is inspired by [Twitter Snowflake](https://github.com/twitter-archive/snowflake/tree/snowflake-2010) and other algorithms.\n\nThe main difference is that ids generated by gem are not fully sequenced. \nWe want to have large random part that can be used as a simple guard against enumeration attack.\n\n## Goals \u0026 Assumptions\n\nWhile we designed format and gem we used these as requirements:\n\n-   Every system should be able to independently (without coordination) generate id that will never (with reasonable chances) be duplicated\n-   ID allows partial time ordering (timestamp in seconds)\n-   ID has easy system identifier (context)\n-   ID is human readable \n-   ID size is not a concern\n-   ID format should not be used for business/application logic - thus it remains flexible for future changes\n\n## ID Format\n\nSuggested algorithm is based on the Twitter snowflake and other similar alghorithms:\n\n`TTTTTTTT-II-RRRRRRRRRRRRRRRRRRRRRR`\n\n-   `TTTTTTTT` - time in seconds since 2000 (just cool number) represented as hex - Gives us ~150 years of uniq sequences\n-   `II` - 1 byte for System Identification in hex\n-   `RRRRRRRRRRRRRRRRRRRRRR` - 11 bytes secure random number as hex\n\nCode to generate is pretty straightforward: \n\n```ruby\ntime = format('%08x', Time.now.to_i - Time.new(2000).to_i)\nid = '6a'\nrandom = SecureRandom.hex(11)\nid = \"#{time}-#{id}-#{random}\" # \"21dc3680-6a-910df0665e5e29b9f89e21\"\n```\n\n## Installation\n\nAdd gem to your application's Gemfile:\n\n```ruby\ngem 'id_generator'\n```\n\n## Usage\n\n```ruby\n# Somewhere during project start\ncontext_id = 165 # value from 0 to 255\nIdGenerator.configuration.context_id = context_id\n# Or using block\nIdGenerator.configure { |config| config.context_id = context_id } \n\n#Inside of the actual code\nIdGenerator.generate\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at [https://github.com/matic-insurance/id_generator]().\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatic-insurance%2Fid_generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatic-insurance%2Fid_generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatic-insurance%2Fid_generator/lists"}