sazid
sazid
MModular
Created by sazid on 9/29/2024 in #community-showcase
Fireflake: A snowflake id generator in Mojo
Hi all! I've written a new library that generates Snowflake IDs. Quoting Wikipedia: Snowflake ID:
Snowflake IDs, or snowflakes, are a form of unique identifier used in distributed computing. The format was created by Twitter (now X) and is used for the IDs of tweets.[1] It is popularly believed that every snowflake has a unique structure, so they took the name "snowflake ID". The format has been adopted by other companies, including Discord and Instagram. The Mastodon social network uses a modified version.
:github: Repository - https://github.com/sazid/fireflake I've yet to write tests for this, any suggestions or improvements are welcome!
1 replies
MModular
Created by sazid on 9/28/2024 in #questions
How to prevent compilation when parametric conditions fail?
struct Test[bits_count: Int64 = 10]:
@parameter
if bits_count < 0 or bits_count > 10:
raise Error("Invalid number of bits count.")
struct Test[bits_count: Int64 = 10]:
@parameter
if bits_count < 0 or bits_count > 10:
raise Error("Invalid number of bits count.")
With the above code, I can see that the error is being raised at runtime. Is it possible to stop the compilation with an error message when the parametric condition fails?
4 replies
MModular
Created by sazid on 9/28/2024 in #questions
Is there any mutex available in the stdlibs?
Searched for mutex in the docs and it looks like it's not available yet. Is there a way I can atomically perform multiple ops or do the following with the atomic package? I want to perform an increment on an int, followed by a modulo which should round the number back to 0 after a certain limit and return the value.
66 replies
MModular
Created by sazid on 9/28/2024 in #questions
How to get unix timestamp?
Hi, is there currently currently any API to get the unix timestamp (since unix epoch)? I read the docs for time.now() and it seems it only measures the time from the system boot.
23 replies