• Stars
    star
    15
  • Rank 1,328,274 (Top 27 %)
  • Language
    Crystal
  • License
    Apache License 2.0
  • Created about 3 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This is a small UUID library that implements a chronologically sortable UUID.

CSUUID.cr CI CSUUID.cr Build Docs

GitHub release GitHub commits since latest release (by SemVer)

CSUUID

This struct wraps up a UUID that encodes a timestamp measured as seconds from the epoch (0001-01-01 00:00:00.0 UTC) observed at the location where the timestamp was generated, plus nanoseconds in the current second, plus 6 bytes for unique identification of the source -- this could be an IPV4 address with two null bytes, a MAC address, or some other sequence that will fit in 6 bytes.

Nanoseconds will fit in an Int32 (4 bytes), but seconds since the epoch will not. The current number of seconds leaks a short distance into a 5th byte, meaning that in this class, it has to be represented by an Int64. This is problematic because a UID allows for 16 bytes, so the use of 8 for seconds and 4 for nanoseconds leaves only 4 bytes for system identification. It also leaves three bytes in the UUID as zeros because 8 bytes for seconds is a lot of seconds.

One solution is to combine the seconds and the nanoseconds into a single Int64 number. This requires math operations to do efficiently:

(seconds * 1000000000) + nanoseconds

and then more math to extract the original numbers in order to reconstruct the original timestamp. This leaves 8 bytes for identification or other uniqueness information, which is lovely, but the math requirement is less lovely.

The other options is to truncate 2 bytes off of the seconds, storing 6 bytes of seconds data. This leaves 6 bytes for identification.

The current implementation chose option #2, as it is less work to generate a UUID if math is not involved.

The byte structure of the CSUUID is:

+-------------+-----------------+------------+
| nanoseconds |     seconds     | identifier |
|    0..3     |      4..10      |   11..15   |
+-------------+-----------------+------------+

The representational structure of the CSUUID, however, is itself sortable, as are the objects themselves.

.00.0e.d9.eb.-.7e.05.-.08.ae.-.f2.9c.-.df.18.10.1c.4a.dc.
^      seconds       ^  nanoseconds  ^identifier/entropy^

Installation

  1. Add the dependency to your shard.yml:

    dependencies:
      csuuid:
        github: wyhaines/csuuid.cr
  2. Run shards install

Usage

require "csuuid"

uuid = CSUUID.new

uuid = CSUUID.new(seconds: 9223372036, nanoseconds: 729262400)

uuid = CSUUID.new(identifier: Random.new.random_bytes(6))

dt = ParseDate.parse("2020/07/29 09:15:37")
uuid = CSUUID.new(dt)

API Docs

https://wyhaines.github.io/csuuid.cr/

Contributing

  1. Fork it (https://github.com/wyhaines/csuuid.cr/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

Contributors

GitHub code size in bytes GitHub issues

More Repositories

1

swiftiply

A high performance clustering proxy / web server for web applications.
Ruby
68
star
2

scrawls

A Simple Ruby Web Server
Ruby
37
star
3

analogger

A very fast distributed asynchronous logging service
Ruby
25
star
4

iowa

A fast, productive, component based web development framework for Ruby.
Ruby
21
star
5

defined.cr

This shard provides facilities for checking whether a constant exists at compile time, and for a variety of different conditional compilation options. Code can be conditionally compiled based on the existence of a constant, version number constraints, or whether an environment variable is set truthy or not.
Crystal
17
star
6

opentelemetry-instrumentation.cr

Bundled integrations for opentelemetry-api.cr (https://github.com/wyhaines/opentelemetry-api.cr).
Crystal
16
star
7

splay_tree_map.cr

This is a Crystal implementation of a Splay Tree; which is a type of binary search tree that is semi-balanced and that tends to self-optimize so that the most accessed items are the fastest to retrieve.
Crystal
14
star
8

datapack.cr

You are building an application, be it web or something else. It has data -- images, CSS, JS, CSV files, whatever -- and you want to be able to easily bundle those into your compiled executable. This shard gives you a simple utility to add this data to your executable, access it, and manage it.
Crystal
13
star
9

opentelemetry-api.cr

The core of open telemetry instrumentation is the OpenTelemetry API/SDK. The initial aim of this shard is to implement the OpenTelemetry specification for metrics, traces, and logs.
Crystal
12
star
10

Send.cr

This shard implements a usable dynamic dispatch function for Crystal code, modeled on the Ruby #send function of the same name.
Crystal
12
star
11

tracer.cr

This library implements a method call tracing facility that can be used to generate either summary or detailed logs of method calls, or to inject arbitrary code execution into method calls.
Crystal
10
star
12

rubyconfmini_2022_crystal_for_rubyists_workshop

HTML
8
star
13

base58.cr

This is a performance optimized implementation of base58 binary-to-text encoding algorithm.
Crystal
8
star
14

opentelemetry-sdk.cr

This repository contains an implementation of an OpenTelemetry SDK for Crystal
Crystal
7
star
15

git-index.cr

This tool makes a local database of git repositories, indexed by initial commit hashes.
Crystal
5
star
16

bus.cr

It is sometimes useful to have a pubsub type message bus inside your software. This library implements a bus to send messages to interested subscribers. Those subscribers can reply to those messages, and are guaranteed that the reply will be routed back to the sender.
Crystal
5
star
17

crypt-isaac

A Ruby implementation of the cryptographically secure ISAAC pseudorandom number generator, with both pure Ruby and C extension implementations.
Ruby
5
star
18

nbchannel.cr

A NBChannel is a non-blocking channel. Normal Crystal channels block on send and on receive. The NBChannel will never block on send, and there are both blocking and nonblocking receive calls available. The channel should work both for single producer, single consumer scenarios, and for scenarios with multiple producers or multiple consumers.
Crystal
5
star
19

ParseDate.cr

This is a small library that attempts to parse a wide variety of date formats with a single call.
Crystal
4
star
20

Chord

A Ruby implementation of the Chord protocol.
Ruby
4
star
21

ruby-gnome2

A mirror of the ruby-gnome2 project.
4
star
22

timeout.cr

This implements a very simple timeout method for Crystal. Use it to wrap code in a timeout, so that execution of that code can not continue forever.
Crystal
4
star
23

find.cr

Crystal
3
star
24

Floodgate

A fast, easy to use, customizeable caching reverse proxy implemented substantially in Ruby
3
star
25

for.cr

This tiny little shard implements a "for" loop for Crystal by leveraging macros.
Crystal
3
star
26

wisteria

An extremely fast event based microframework/webserver written with Ruby.
Ruby
3
star
27

apm.cr

This is an open source APM agent for Crystal. Initial development is targeting the OpenTelemetry spec for data exchange, but it may also support the New Relic specific protocol. It should, however, be usable with any provider that permits OpenTelementry ingest.
Crystal
3
star
28

shellac

Shellac is a very simple proof-of-concept caching reverse proxy. It is intended mostly to demonstrate a concept, though it could be refined into something more polished.
Ruby
3
star
29

hpack.cr

This shard is a standalone implementation of HPack, the HTTP2 header compression algorithm.
Crystal
3
star
30

advent-of-code-2022

Here are my Advent of Code solutions for 2022.
Rust
3
star
31

alias_method.cr

Crystal does not provide a ready-to-use mechanism for creating method aliases, and the general Crystal code style recommendation is that one should avoid having multiple names that invoke the same method. However, there are times where creating method aliases is useful. This shard creates an alias_method macro that can be used to easily create method aliases which are functionally identical to the original method.
Crystal
3
star
32

eaba2-tools

A small collection of tools for dice rolling, probability simulations, and similar things for use with my EABA2 games.
2
star
33

lockfile.cr

This shard implements a portable lockfile, for use with the Crystal Language.
Crystal
2
star
34

evita

A spike to play with some ideas surrounding a chat bot implementation.
Crystal
2
star
35

NewRelic.cr

This is a binding to the New Relic C SDK, so that Crystal programs can add observability features with New Relic.
Crystal
2
star
36

hash_serializable.cr

The module provides a Hash::Serializeable module which, like JSON::Serializeable and YAML::Serializeable, can be mixed into a class to allow the class's ivars to be serialized out to a hash, and to allow a hash to be instantiated as an instance of a class.
Crystal
2
star
37

learning-crystal-via-conways-game-of-life

This repository is to be used as a lesson or guided workshop to introduce Crystal to someone who already knows how to program, by building a Crystal implementation of Conway's game of life. It includes a codespace to facilitate this lesson.
Shell
2
star
38

time-ext.cr

This is a very small extension of the Time class for Crystal. It has been extracted from another project as it provides a small number of logical and useful extensions to Time.
Crystal
2
star
39

simple_irc.cr

This is a simple IRC protocol implementation. No bundled bot capabilities or anything fancy. Just the basics, made easy to use.
Crystal
2
star
40

git-index

This is a very simple little tool that creates an index of git repositories, keyed by the commit hash codes for the first and second commits in the repository.
Ruby
2
star
41

liquidcrystal

This is a port of the Liquid gem from Shopify, for the Crystal language. It aims to be as compatible as possible with the upstream source of truth that is the Shopify Ruby implementation of Liquid.
Crystal
2
star
42

jekyll-include-with-frontmatter

Implements a couple tags to include files that contain front matter. Inspired by a desire to be able to edit Includes with Netflify-CMS.
Ruby
2
star
43

content

My content workspace
1
star
44

SwiftRPC

An RPC library implementation.
Ruby
1
star
45

ey-cloud-recipes

A starter repo for custom chef recipes on EY's cloud platform
Ruby
1
star
46

crystal-conf-1.0-dynamic-crystal

Find ye herein all of the code examples that are used in my talk.
1
star
47

analogger.cr

This is a port of https://github.com/wyhaines/analogger using Crystal.
Crystal
1
star
48

crypt-xorshift

Implementation of a few variants of the Xorshift family of pseudo random number generators for Ruby, with both pure Ruby and C extension implementations.
Ruby
1
star
49

swiftcore-tasks

This little helper code for managing a queue of tasks to execute is used by multiple software packages, so I am packaging it for reuse.
Ruby
1
star
50

TwitchEventSub.cr

This shard encapsulates logic and handling for interacting with the Twitch EventSub API.
Crystal
1
star
51

simplereactor

A very, very barebones event reactor with timer support, implemented with Ruby, backed by either a Ruby/select() based IO system or a Nio4r based IO system.
Ruby
1
star
52

scrawls-ioengine-multithread

A multithreaded io engine for Scrawls.
Ruby
1
star
53

serf-handler

A simple little library that provides a basic framework for Ruby powered Serf handlers.
Ruby
1
star
54

apm-therelicans

This code is the code that was used for an article on how to build an APM system, written for therelicans.com.
Crystal
1
star
55

ridgepole-executor

This is a script intended to be ran by ridgepole as an external script for performing database changes. It will vector blocking alters through a tool to perform them without full table locks, like pt-osc, while sending the safe SQL to the database more directly.
Ruby
1
star
56

serf-handler.cr

This implements a port of the Ruby Serf Handler gem -- https://github.com/wyhaines/serf-handler -- as a library that can be used to easily build compiled, distributable handler binaries using the Crystal language.
Crystal
1
star