<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="198493" data-post-id="198493">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="hauleth" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hauleth/120/18942_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  hauleth
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>My problem with ULID is that it is only length-compatible with UUID, not format-compatible, so it cannot be added to the UUID specs as a new version to the IETF RFC. That is why I prefer UUIDv6 proposal, which could be handled in PostgreSQL and any other implementation with almost no changes to the code.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="198493" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/generate-timebased-uuid-in-elixir/36398/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-198493" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="198493"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="199345" data-post-id="199345">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="jc00ke" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/jc00ke/120/18365_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  jc00ke
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="hauleth" data-post="12" data-topic="36398">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hauleth/48/18942_2.png" class="avatar"> hauleth:</div>
<blockquote>
<p>My problem with ULID is that it is only length-compatible with UUID, not format-compatible</p>
</blockquote>
</aside>
<p>Exactly. That was the most annoying part for me: having to convert from one format to another. I didn’t really need ULID anyway, but it was nice to get some experience with it.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="199345" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/generate-timebased-uuid-in-elixir/36398/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-199345" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="199345"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="199353" data-post-id="199353">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="hauleth" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/hauleth/120/18942_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  hauleth
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>By format I do not mean hexadecimal representation, but binary representation. Just to make it clear. <a href="https://hauleth.dev/post/treachery-of-representation/" rel="noopener nofollow ugc">String <code>46529a99-5727-4655-b1e9-58ebb8d90c6f</code> is <strong>NOT</strong> UUID</a>.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="199353" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/generate-timebased-uuid-in-elixir/36398/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-199353" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="199353"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="203353" data-post-id="203353">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="RodolfoSilva" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/RodolfoSilva/120/39258_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  RodolfoSilva
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Snowflake IDs, <a href="https://github.com/pggalaviz/exnowflake" class="inline-onebox" rel="noopener nofollow ugc">GitHub - pggalaviz/exnowflake: A decentralized, unique, time based ID generator. · GitHub</a> .</p>
<p>Docs:</p>
<aside class="onebox allowlistedgeneric" data-onebox-src="https://exnowflake.hexdocs.pm/readme.html">
  <header class="source">

      <a href="https://exnowflake.hexdocs.pm/readme.html" target="_blank" rel="noopener nofollow ugc">exnowflake.hexdocs.pm</a>
  </header>

  <article class="onebox-body">
    

<h3><a href="https://exnowflake.hexdocs.pm/readme.html" target="_blank" rel="noopener nofollow ugc">Exnowflake — exnowflake v0.1.1</a></h3>



  </article>

  <div class="onebox-metadata">
    
    
  </div>

  <div style="clear: both"></div>
</aside>
 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="203353" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/generate-timebased-uuid-in-elixir/36398/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-203353" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="203353"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="205413" data-post-id="205413">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="cjbottaro" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cjbottaro/120/1469_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  cjbottaro
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<aside class="quote no-group" data-username="sahilpaudel" data-post="7" data-topic="36398" data-full="true">
<div class="title">
<div class="quote-controls"></div>
<img alt="" width="24" height="24" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/sahilpaudel/48/18807_2.png" class="avatar"> sahilpaudel:</div>
<blockquote>
<p>Actually if the type is timebased uuid then I can insert <code>now()</code> which it converts to uuid internally.</p>
</blockquote>
</aside>
<p>Can you explain how to do this? I just get…</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">** (ArgumentError) Invalid argument; Expected: &lt;&lt;clock_seq::14&gt;&gt;, &lt;&lt;node::48&gt;&gt;
    (uuid 1.1.8) lib/uuid.ex:250: UUID.uuid1/3
</code></pre>
<p>Thanks.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="205413" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/generate-timebased-uuid-in-elixir/36398/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-205413" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="205413"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #15"></div>
  </section>
</div>
    <div class="postbit" id="205544" data-post-id="205544">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="cjbottaro" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/cjbottaro/120/1469_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  cjbottaro
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I just ported the <code>Cassandra::Uuid::Generator</code> code from the official Cassandra Ruby gem:<br>
<a href="https://github.com/datastax/ruby-driver/blob/master/lib/cassandra/uuid/generator.rb#L157" class="onebox" target="_blank" rel="noopener nofollow ugc">https://github.com/datastax/ruby-driver/blob/master/lib/cassandra/uuid/generator.rb#L157</a></p>
<pre data-code-wrap="elixir"><code class="lang-elixir">defmodule TimeUuid do
  use Bitwise, only_operators: true

  @gregorian_offset 122192928000000000

  def new(date_time, jitter \\ nil) do
    jitter = jitter || :rand.uniform(65536)
    clock_id = :rand.uniform(65536)
    node_id = generate_node_id()
    usecs = DateTime.to_unix(date_time, :microsecond) + jitter

    t = @gregorian_offset + usecs * 10
    time_hi  = t &amp;&amp;&amp; 0x0fff000000000000
    time_mid = t &amp;&amp;&amp; 0x0000ffff00000000
    time_low = t &amp;&amp;&amp; 0x00000000ffffffff
    version = 1
    clock_id = clock_id &amp;&amp;&amp; 0x3fff
    node_id = node_id &amp;&amp;&amp; 0xffffffffffff
    variant = 0x8000

    n = (time_low &lt;&lt;&lt; 96) ||| (time_mid &lt;&lt;&lt; 48) ||| (time_hi &lt;&lt;&lt; 16)
    n = n ||| (version &lt;&lt;&lt; 76)
    n = n ||| ((clock_id ||| variant) &lt;&lt;&lt; 48)
    n = n ||| node_id

    &lt;&lt;n::integer-size(128)&gt;&gt;
    |&gt; UUID.binary_to_string!()
  end

  def generate_node_id do
    :math.pow(2, 47)
    |&gt; trunc()
    |&gt; :rand.uniform()
    |&gt; Bitwise.bor(0x010000000000)
  end

end
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="205544" data-batch-url="/posts/batch_likers">
                        2
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/generate-timebased-uuid-in-elixir/36398/17">Post #16</a>
	                </div>
	            </div>
              <div id="likers-container-205544" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="205544"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>