<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Secret Advent</title>
    <description>The latest articles on DEV Community by Secret Advent (@secretadvent).</description>
    <link>https://dev.to/secretadvent</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4281148%2F9a3382e1-9589-4930-8600-02b30659ba97.png</url>
      <title>DEV Community: Secret Advent</title>
      <link>https://dev.to/secretadvent</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/secretadvent"/>
    <language>en</language>
    <item>
      <title>A digital advent calendar for someone far away: making each door open at their midnight</title>
      <dc:creator>Secret Advent</dc:creator>
      <pubDate>Sat, 05 Dec 2026 02:27:53 +0000</pubDate>
      <link>https://dev.to/secretadvent/a-digital-advent-calendar-for-someone-far-away-making-each-door-open-at-their-midnight-2g8f</link>
      <guid>https://dev.to/secretadvent/a-digital-advent-calendar-for-someone-far-away-making-each-door-open-at-their-midnight-2g8f</guid>
      <description>&lt;p&gt;If you make an advent calendar for someone in another country, a long-distance partner or a sister abroad, "door 5 opens on December 5" stops being a simple rule. December 5 starts at a different moment for you and for them.&lt;/p&gt;

&lt;p&gt;I built a free digital advent calendar where you can fill all 24 doors yourself and send one link. Here's how I handled time zones, and the trade-off I accepted.&lt;/p&gt;

&lt;h3&gt;
  
  
  The goal
&lt;/h3&gt;

&lt;p&gt;The person receiving the calendar should find a new note waiting when they wake up, in their own time zone, without anyone setting a time zone anywhere. No accounts, no settings page.&lt;/p&gt;

&lt;h3&gt;
  
  
  Two checks: one on the server, one in the browser
&lt;/h3&gt;

&lt;p&gt;The server decides when a door's text is allowed to leave the database. It uses the earliest time zone on Earth (UTC+14), so nobody anywhere is ever kept waiting past their own midnight:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// A door unlocks when its day has started anywhere on Earth (UTC+14).&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;unlockAt&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;door&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;UTC&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;door&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;14&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3600&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the calendar is loaded, the server only includes a note's text if &lt;code&gt;now &amp;gt;= unlockAt(year, n)&lt;/code&gt;. Locked doors come back as filled, without the note text.&lt;/p&gt;

&lt;p&gt;The browser then adds the second check, using the device's own clock and time zone:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Open only once it's that day where the reader is.&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;localOpen&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;
  &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;now&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nb"&gt;Date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getTime&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;new Date(year, 11, n)&lt;/code&gt; is local midnight on December n for whoever is reading. A door shows as ready only when both checks pass. So someone in Tokyo and someone in Los Angeles each get door 5 at their own midnight, and neither has to tell the site where they live.&lt;/p&gt;

&lt;h3&gt;
  
  
  The trade-off
&lt;/h3&gt;

&lt;p&gt;Because the server releases a door when the first time zone reaches that day, a determined recipient who already has the owner link could read the API response and see a note up to about 26 hours before their own midnight. I decided that was fine for a gift between people who trust each other. The alternative, asking for a time zone, adds a setting most people would get wrong or skip, and a sign-up I didn't want at all.&lt;/p&gt;

&lt;h3&gt;
  
  
  Gift mode: two links, two roles
&lt;/h3&gt;

&lt;p&gt;When you fill the calendar yourself, the server creates two secrets:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;an &lt;strong&gt;edit key&lt;/strong&gt; that stays with you, so you can keep adding notes to all 24 doors;&lt;/li&gt;
&lt;li&gt;an &lt;strong&gt;owner key&lt;/strong&gt; that you send to the recipient, which is the link they open each day.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Only SHA-256 hashes of both keys are stored, never the keys themselves. Without the gift mode, friends fill doors through a shared link and each person can fill up to 3 doors; with it, you are the only writer by default, unless you also send friends the shared link.&lt;/p&gt;

&lt;h3&gt;
  
  
  What goes behind each door
&lt;/h3&gt;

&lt;p&gt;Each door holds one text note of up to 280 characters plus a sticker. No photos or links, which keeps the stored data small and the privacy promise simple: everything is deleted on February 1.&lt;/p&gt;

&lt;p&gt;That limit turned out to shape the content in a nice way. Instead of "here's a playlist", you write the song title and why it reminds you of them. Instead of a photo, one line describing it, to show them when you meet.&lt;/p&gt;

&lt;h3&gt;
  
  
  Wrapping up
&lt;/h3&gt;

&lt;p&gt;The whole thing is two date comparisons and a choice about what "on time" means. If you're making one for someone far away this year, it's free and doesn't need an account: &lt;a href="https://secretadvent.com/digital-advent-calendar?utm_source=devto" rel="noopener noreferrer"&gt;secretadvent.com&lt;/a&gt;. I'd be curious how others have handled "local midnight" without asking users for their time zone.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>cloudflare</category>
      <category>showdev</category>
    </item>
    <item>
      <title>The math behind a fair Secret Santa draw (and why "no couples" can make it impossible)</title>
      <dc:creator>Secret Advent</dc:creator>
      <pubDate>Fri, 04 Dec 2026 09:34:37 +0000</pubDate>
      <link>https://dev.to/secretadvent/the-math-behind-a-fair-secret-santa-draw-and-why-no-couples-can-make-it-impossible-3kgf</link>
      <guid>https://dev.to/secretadvent/the-math-behind-a-fair-secret-santa-draw-and-why-no-couples-can-make-it-impossible-3kgf</guid>
      <description>&lt;p&gt;Every Secret Santa draw has two rules: nobody draws themselves, and nobody knows anyone else's pair. When I built a free Secret Santa generator with no email and no sign-up, I added a third rule the generator supports: "don't let couples draw each other." That third rule turned out to be the interesting part.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rule 1: nobody draws themselves
&lt;/h3&gt;

&lt;p&gt;A draw is a permutation where person &lt;em&gt;i&lt;/em&gt; gives to person &lt;em&gt;p(i)&lt;/em&gt;. "Nobody draws themselves" means no fixed points, which mathematicians call a &lt;strong&gt;derangement&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you shuffle at random, the chance that you get a derangement is close to &lt;strong&gt;1/e ≈ 37%&lt;/strong&gt;, almost no matter how many people there are. So "shuffle until it works" needs about 2.7 tries on average. Cheap.&lt;/p&gt;

&lt;p&gt;Without extra rules I use Sattolo's algorithm instead, which produces a single cycle (A gives to B, B to C, ... back to A) and is a derangement by construction:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;derange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Uint32Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getRandomValues&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;j&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;j&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// person i gives to a[i]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note &lt;code&gt;r[i] % i&lt;/code&gt;, not &lt;code&gt;% (i + 1)&lt;/code&gt;. That one character is the difference between Sattolo and Fisher–Yates.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rule 2: nobody knows the pairs
&lt;/h3&gt;

&lt;p&gt;Each person gets their own private link. Opening it shows only who &lt;em&gt;they&lt;/em&gt; give to. The organizer's view shows names and whether each link has been opened, but never the pairs. Nothing needs an email address because the organizer shares the links themselves, usually in a WhatsApp chat, one by one.&lt;/p&gt;

&lt;h3&gt;
  
  
  Rule 3: "don't let couples draw each other"
&lt;/h3&gt;

&lt;p&gt;Exclusions are just banned edges: if Ana and Ben are a couple, then Ana→Ben and Ben→Ana are both off limits. With a handful of banned pairs, plain rejection sampling is still fast:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;derangeExcept&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;banned&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;20000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;shuffle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// Fisher–Yates with crypto.getRandomValues&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;every&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;banned&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;"&amp;gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// tell the user this combination can't be drawn&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exclusions are used only to make that one draw. They are never stored.&lt;/p&gt;

&lt;h3&gt;
  
  
  When "no couples" makes a draw impossible
&lt;/h3&gt;

&lt;p&gt;Here's the case that surprised me. Three people, one couple:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ana and Ben can't draw each other, and nobody draws themselves.&lt;/li&gt;
&lt;li&gt;So Ana must give to Chloe, and Ben must also give to Chloe.&lt;/li&gt;
&lt;li&gt;Chloe can only receive one gift. There's no valid draw.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The same thing happens in bigger groups when one person is excluded from almost everyone. So the generator has to notice and say so ("remove a pair or add a name") instead of looping forever. Capping the attempts and returning &lt;code&gt;null&lt;/code&gt; does that. For up to 40 names and realistic exclusion lists, a valid draw is found in a few tries, and when there's none, the cap is hit in a few milliseconds.&lt;/p&gt;

&lt;h3&gt;
  
  
  Small things that mattered
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Duplicate names&lt;/strong&gt; are rejected up front ("Sam" and "sam" are the same person in a group chat).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Names in the exclusion list must match the list of people&lt;/strong&gt;, otherwise the form tells you which name it doesn't recognize.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Budget and exchange date&lt;/strong&gt; are optional and shown on every person's page, so nobody has to scroll back through the chat.&lt;/li&gt;
&lt;li&gt;Everything is deleted on February 1.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you're organizing one this year, it's free: &lt;a href="https://secretadvent.com/secret-santa-generator?utm_source=devto" rel="noopener noreferrer"&gt;secretadvent.com/secret-santa-generator&lt;/a&gt;. And if you know a nicer way to pick a uniformly random derangement under exclusions than rejection sampling, I'd love to hear it in the comments.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>algorithms</category>
      <category>webdev</category>
      <category>showdev</category>
    </item>
    <item>
      <title>I built a free "guess who" advent calendar your friends fill (Cloudflare Workers + Durable Objects)</title>
      <dc:creator>Secret Advent</dc:creator>
      <pubDate>Thu, 03 Dec 2026 17:45:08 +0000</pubDate>
      <link>https://dev.to/secretadvent/i-built-a-free-guess-who-advent-calendar-your-friends-fill-cloudflare-workers-durable-objects-3f20</link>
      <guid>https://dev.to/secretadvent/i-built-a-free-guess-who-advent-calendar-your-friends-fill-cloudflare-workers-durable-objects-3f20</guid>
      <description>&lt;p&gt;An advent calendar for each other sounds good, and then it stalls, because somebody would have to collect 24 messages and put them together.&lt;/p&gt;

&lt;p&gt;I built &lt;a href="https://secretadvent.com/?utm_source=devto" rel="noopener noreferrer"&gt;Secret Advent&lt;/a&gt;, a free online advent calendar your friends fill. You make a calendar, post one link in the group chat, and each friend picks an empty door and leaves a short note. You open one door a day from December 1 to 24.&lt;/p&gt;

&lt;p&gt;The twist I cared about most is &lt;strong&gt;Guess who mode&lt;/strong&gt;: names stay hidden until Christmas Eve, you guess who wrote each note, and on the 24th you get a score card.&lt;/p&gt;

&lt;p&gt;No accounts, no app, no email. Here's how it works under the hood.&lt;/p&gt;

&lt;h3&gt;
  
  
  One Durable Object per calendar
&lt;/h3&gt;

&lt;p&gt;Each calendar is its own Durable Object, addressed by the calendar's id:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;cal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;CALENDAR&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;env&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="no"&gt;CALENDAR&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;idFromName&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That gives every calendar its own little SQLite database and serializes writes for free. Two friends grabbing the same door at the same moment can't both win, because the object handles one request at a time. The notes table is just door → note:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="k"&gt;IF&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;EXISTS&lt;/span&gt; &lt;span class="n"&gt;notes&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;door&lt;/span&gt; &lt;span class="kt"&gt;INTEGER&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;KEY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;-- 1..24, so a door can only be taken once&lt;/span&gt;
  &lt;span class="n"&gt;writer&lt;/span&gt; &lt;span class="kt"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;      &lt;span class="c1"&gt;-- random id kept in the friend's browser&lt;/span&gt;
  &lt;span class="n"&gt;body&lt;/span&gt; &lt;span class="kt"&gt;TEXT&lt;/span&gt; &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="kc"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Tables are only created when a calendar is actually made, so requests for random ids store nothing.&lt;/p&gt;

&lt;h3&gt;
  
  
  No accounts: links are the keys
&lt;/h3&gt;

&lt;p&gt;When you create a calendar you get two links: a friends link and a private owner link. The owner link carries a random key; the server only stores its SHA-256 hash and compares hashes on each request. Lose the link and nobody (including me) can open the calendar as owner, which is a trade-off I'm fine with for a 24-day toy.&lt;/p&gt;

&lt;p&gt;Friends get a random writer id saved in their browser. That's how the calendar knows which doors are "yours" (you can edit or remove your own note) and how it limits each friend to 3 doors, so one enthusiastic friend can't fill all 24.&lt;/p&gt;

&lt;h3&gt;
  
  
  Guess who: hiding names until the 24th
&lt;/h3&gt;

&lt;p&gt;In Guess who mode the server simply doesn't send names before Christmas Eve. When the owner opens a door, the response has the note but &lt;code&gt;from: null&lt;/code&gt;, unless the viewer wrote that note themselves. The owner types a guess per door; on the 24th the names come back and the page compares them.&lt;/p&gt;

&lt;p&gt;Doing it server-side matters: if names were in the JSON and hidden with CSS, anyone could open DevTools and spoil the game.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deleting everything on February 1
&lt;/h3&gt;

&lt;p&gt;I didn't want to keep people's notes forever. Each calendar sets a Durable Object alarm when it's created:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="kc"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ctx&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;storage&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setAlarm&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;deleteAt&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;year&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// February 1 of next year&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the alarm fires, the object deletes its storage. There's no cleanup cron and no database of old calendars.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bonus: a Secret Santa draw without emails
&lt;/h3&gt;

&lt;p&gt;There is also a Secret Santa generator, with no email and no sign-up. You type the names, it draws, and the organizer gets one private link per person to send on WhatsApp or anywhere. Each link shows only that person's giftee; the organizer only sees who has opened theirs.&lt;/p&gt;

&lt;p&gt;The draw is a random derangement (nobody gets themselves). Couples can be excluded from drawing each other; with a few banned pairs, simply reshuffling until the result is valid is fast enough for up to 40 names:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;20000&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;shuffle&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;keys&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// crypto.getRandomValues inside&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;every&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="n"&gt;banned&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;"&amp;gt;"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// impossible with these exclusions: tell the user&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exclusion pairs are used for that one draw and never stored.&lt;/p&gt;

&lt;h3&gt;
  
  
  Small things that mattered
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Server-rendered pages.&lt;/strong&gt; Landing pages are plain HTML rendered by the Worker, with a little JS for the calendar itself. The Worker's median wall time is about a millisecond.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Five languages&lt;/strong&gt; (English, Japanese, German, Spanish, Portuguese). LINE matters in Japan, WhatsApp almost everywhere else, so the share buttons follow that.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rate limits&lt;/strong&gt; on creating calendars and filling doors, and no links allowed inside notes or names, to keep shared calendars free of spam.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Try it
&lt;/h3&gt;

&lt;p&gt;It's free and there's nothing to sign up for. Feedback on the Durable Objects setup is very welcome too.&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>webdev</category>
      <category>cloudflare</category>
      <category>javascript</category>
    </item>
  </channel>
</rss>
