<?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: gaven yang</title>
    <description>The latest articles on DEV Community by gaven yang (@gaven_yang_438e60f53e6ff2).</description>
    <link>https://dev.to/gaven_yang_438e60f53e6ff2</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%2F3717324%2Ffaf8d467-12f0-4221-8391-20a41b787232.jpg</url>
      <title>DEV Community: gaven yang</title>
      <link>https://dev.to/gaven_yang_438e60f53e6ff2</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gaven_yang_438e60f53e6ff2"/>
    <language>en</language>
    <item>
      <title>Minting Free Official DOIs via REST API on Zenodo and Harvard Dataverse (5 Real Gotchas)</title>
      <dc:creator>gaven yang</dc:creator>
      <pubDate>Wed, 25 Nov 2026 10:25:17 +0000</pubDate>
      <link>https://dev.to/gaven_yang_438e60f53e6ff2/minting-free-official-dois-via-rest-api-on-zenodo-and-harvard-dataverse-5-real-gotchas-33ob</link>
      <guid>https://dev.to/gaven_yang_438e60f53e6ff2/minting-free-official-dois-via-rest-api-on-zenodo-and-harvard-dataverse-5-real-gotchas-33ob</guid>
      <description>&lt;p&gt;If you publish open telemetry snapshots, public benchmarks, or reproducible CSV datasets on GitHub, archiving a versioned release on &lt;strong&gt;Zenodo (CERN)&lt;/strong&gt; and &lt;strong&gt;Harvard Dataverse&lt;/strong&gt; gives you two permanent, citable DOIs (&lt;code&gt;10.5281/zenodo.*&lt;/code&gt; and &lt;code&gt;10.7910/DVN/*&lt;/code&gt;) plus Schema.org &lt;code&gt;Dataset&lt;/code&gt; JSON-LD for Google Dataset Search—at &lt;code&gt;$0&lt;/code&gt; cost.&lt;/p&gt;

&lt;p&gt;We just automated a dual-archive pipeline for an open CC BY 4.0 retail availability snapshot (31 monitored stores, 818 timestamped restock transitions, and 5,259,265 polling checks). Along the way, we hit five API and permission gotchas that are not obvious from the quickstart docs. Here is what broke and the exact fixes that worked.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Zenodo: Pass an Explicit &lt;code&gt;User-Agent&lt;/code&gt; Header
&lt;/h2&gt;

&lt;p&gt;Zenodo's REST API (&lt;code&gt;/api/deposit/depositions&lt;/code&gt;) sits behind WAF rules that return an HTML 403 page to Node's default &lt;code&gt;undici&lt;/code&gt; &lt;code&gt;fetch&lt;/code&gt; client. Switching to an explicit &lt;code&gt;User-Agent&lt;/code&gt; (and &lt;code&gt;curl&lt;/code&gt; for binary bucket uploads) solved it immediately:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nv"&gt;UA&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"OpenTelemetryArchiver/1.0"&lt;/span&gt;

&lt;span class="c"&gt;# 1. Create empty draft deposition&lt;/span&gt;
&lt;span class="nv"&gt;DEP&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;curl -sS -X POST -A &lt;span class="s2"&gt;"$UA"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"Authorization: Bearer $ZENODO_TOKEN"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{}'&lt;/span&gt; \
  https://zenodo.org/api/deposit/depositions&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="nv"&gt;DEP_ID&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"$DEP"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; jq -r &lt;span class="s1"&gt;'.id'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;
&lt;span class="nv"&gt;BUCKET&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"$DEP"&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; jq -r &lt;span class="s1"&gt;'.links.bucket'&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt;

&lt;span class="c"&gt;# 2. Upload files directly to the deposition bucket&lt;/span&gt;
curl -sS -X PUT -A &lt;span class="s2"&gt;"$UA"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"Authorization: Bearer $ZENODO_TOKEN"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"Content-Type: application/octet-stream"&lt;/span&gt; \
  --data-binary @DATA_DESCRIPTOR.pdf \
  &lt;span class="s2"&gt;"$BUCKET/DATA_DESCRIPTOR.pdf"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After updating metadata via &lt;code&gt;PUT /api/deposit/depositions/$DEP_ID&lt;/code&gt; (&lt;code&gt;upload_type: "dataset"&lt;/code&gt;, &lt;code&gt;license: "cc-by-4.0"&lt;/code&gt;, &lt;code&gt;related_identifiers&lt;/code&gt;), a single &lt;code&gt;POST .../actions/publish&lt;/code&gt; mints the live DOI immediately.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Harvard Dataverse: Don't Deposit Directly Into the Root &lt;code&gt;harvard&lt;/code&gt; Collection
&lt;/h2&gt;

&lt;p&gt;If you create a dataset directly under &lt;code&gt;/api/dataverses/harvard/datasets&lt;/code&gt;, Harvard Dataverse assigns your account a restricted &lt;code&gt;Root Dataset Editor&lt;/code&gt; role (&lt;code&gt;canPublishDataset: false&lt;/code&gt;). Calling &lt;code&gt;:publish&lt;/code&gt; returns:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"status"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"ERROR"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nl"&gt;"message"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"User is not permitted to perform requested action."&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Fix:&lt;/strong&gt; First create and publish your own sub-collection under &lt;code&gt;harvard&lt;/code&gt;. As the owner of your own Dataverse collection, you receive full Admin permissions (&lt;code&gt;canPublishDataverse: true&lt;/code&gt;, &lt;code&gt;canPublishDataset: true&lt;/code&gt;) and can mint DOIs without waiting in a root review queue:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Create your own research collection under root harvard&lt;/span&gt;
curl -sS -X POST \
  -H &lt;span class="s2"&gt;"X-Dataverse-key: $DV_TOKEN"&lt;/span&gt; \
  -H &lt;span class="s2"&gt;"Content-Type: application/json"&lt;/span&gt; \
  -d &lt;span class="s1"&gt;'{
    "name": "Open Telemetry Data",
    "alias": "my-telemetry-collection",
    "dataverseContacts": [{"contactEmail": "you@example.com"}],
    "dataverseType": "RESEARCH_PROJECT"
  }'&lt;/span&gt; \
  https://dataverse.harvard.edu/api/dataverses/harvard

&lt;span class="c"&gt;# Publish the collection before publishing datasets inside it&lt;/span&gt;
curl -sS -X POST \
  -H &lt;span class="s2"&gt;"X-Dataverse-key: $DV_TOKEN"&lt;/span&gt; \
  https://dataverse.harvard.edu/api/dataverses/my-telemetry-collection/actions/:publish
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  3. Harvard Dataverse: Use &lt;code&gt;curl -F&lt;/code&gt; Instead of Streaming Node &lt;code&gt;FormData&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;Uploading multi-file CSVs and PDFs to &lt;code&gt;/api/datasets/:persistentId/add&lt;/code&gt; using Node's built-in &lt;code&gt;FormData&lt;/code&gt; + &lt;code&gt;fetch&lt;/code&gt; stalled indefinitely on the first file. Using &lt;code&gt;curl -F&lt;/code&gt; (which sends standard multipart boundaries and explicit &lt;code&gt;Content-Length&lt;/code&gt;) uploaded all 7 files in a few seconds:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl -sS -X POST \
  -H &lt;span class="s2"&gt;"X-Dataverse-key: $DV_TOKEN"&lt;/span&gt; \
  -F &lt;span class="s2"&gt;"file=@data/restock_events.csv"&lt;/span&gt; \
  -F &lt;span class="s1"&gt;'jsonData={"description":"818 timestamped restock transitions","categories":["Data"]}'&lt;/span&gt; \
  &lt;span class="s2"&gt;"https://dataverse.harvard.edu/api/datasets/:persistentId/add?persistentId=doi:10.7910/DVN/EXAMPLE"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  4. Poll &lt;code&gt;/locks&lt;/code&gt; Before Publishing Tabular CSVs
&lt;/h2&gt;

&lt;p&gt;Harvard Dataverse automatically runs tabular ingest and Universal Numeric Fingerprint (UNF) calculation on uploaded &lt;code&gt;.csv&lt;/code&gt; files. If you call &lt;code&gt;:publish&lt;/code&gt; immediately after upload, it can reject due to an active &lt;code&gt;Ingest&lt;/code&gt; lock. Poll &lt;code&gt;GET /api/datasets/:persistentId/locks?persistentId=...&lt;/code&gt; until the &lt;code&gt;data&lt;/code&gt; array is empty, then call &lt;code&gt;:publish?type=major&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Put Attribution URLs in Structured Citation Fields, Not Only HTML Descriptions
&lt;/h2&gt;

&lt;p&gt;Harvard Dataverse sanitizes &lt;code&gt;&amp;lt;a&amp;gt;&lt;/code&gt; tags inside the free-text &lt;code&gt;dsDescription&lt;/code&gt; block, whereas structured Citation Metadata fields (&lt;code&gt;publication&lt;/code&gt; → &lt;code&gt;publicationURL&lt;/code&gt; / &lt;code&gt;publicationIDNumber&lt;/code&gt;, and &lt;code&gt;producer&lt;/code&gt; → &lt;code&gt;producerURL&lt;/code&gt;) render cleanly in the canonical metadata panel and Schema.org &lt;code&gt;sc:Dataset&lt;/code&gt; export.&lt;/p&gt;




&lt;h2&gt;
  
  
  Live Archival Outputs &amp;amp; Ecosystem Reference
&lt;/h2&gt;

&lt;p&gt;Here is the finished v1.0.0 CC BY 4.0 release archived with this exact workflow, along with its source repository, public MCP server, and independent directory/sustainability pages:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Zenodo Archival Record (&lt;code&gt;10.5281/zenodo.24523167&lt;/code&gt;)&lt;/strong&gt;: &lt;a href="https://zenodo.org/records/24523167" rel="noopener noreferrer"&gt;Apple Store In-Store Pickup Restock &amp;amp; Telemetry Dataset v1.0.0 on Zenodo&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Harvard Dataverse Record (&lt;code&gt;10.7910/DVN/MZFTCB&lt;/code&gt;)&lt;/strong&gt;: &lt;a href="https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/MZFTCB" rel="noopener noreferrer"&gt;Apple Store In-Store Pickup Restock &amp;amp; Telemetry Dataset on Harvard Dataverse&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Harvard Dataverse Collection&lt;/strong&gt;: &lt;a href="https://dataverse.harvard.edu/dataverse/restockcheck-telemetry" rel="noopener noreferrer"&gt;RestockCheck Open Telemetry Data Collection&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Reproducible Source &amp;amp; Snapshot Script&lt;/strong&gt;: &lt;a href="https://github.com/yangjwlove-dev/apple-store-pickup-restock-dataset" rel="noopener noreferrer"&gt;apple-store-pickup-restock-dataset on GitHub&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Read-Only Public Telemetry MCP Server&lt;/strong&gt;: &lt;a href="https://glama.ai/mcp/servers/yangjwlove-dev/restockcheck-mcp" rel="noopener noreferrer"&gt;RestockCheck Public Telemetry MCP on Glama&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Independent Listings &amp;amp; Carbon Footprint Audit&lt;/strong&gt;: &lt;a href="https://www.saashub.com/restockcheck" rel="noopener noreferrer"&gt;SaaSHub Profile&lt;/a&gt; · &lt;a href="https://www.saashub.com/restockcheck-alternatives" rel="noopener noreferrer"&gt;SaaSHub Alternatives&lt;/a&gt; · &lt;a href="https://thesaasdir.com/product/restockcheck/" rel="noopener noreferrer"&gt;TheSaaSDir Listing&lt;/a&gt; · &lt;a href="https://twelve.tools/restockcheck" rel="noopener noreferrer"&gt;Twelve.tools Listing&lt;/a&gt; · &lt;a href="https://www.websitecarbon.com/website/restockcheck-com/" rel="noopener noreferrer"&gt;WebsiteCarbon Grade A Audit (0.08g CO2/visit)&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>datascience</category>
    </item>
    <item>
      <title>Why Phone-Scanning Old Family Prints Ruins Restoration (And the 5 Capture Rules That Fix It)</title>
      <dc:creator>gaven yang</dc:creator>
      <pubDate>Tue, 24 Nov 2026 09:10:50 +0000</pubDate>
      <link>https://dev.to/gaven_yang_438e60f53e6ff2/why-phone-scanning-old-family-prints-ruins-restoration-and-the-5-capture-rules-that-fix-it-16i9</link>
      <guid>https://dev.to/gaven_yang_438e60f53e6ff2/why-phone-scanning-old-family-prints-ruins-restoration-and-the-5-capture-rules-that-fix-it-16i9</guid>
      <description>&lt;p&gt;&lt;em&gt;Most "AI restoration failures" happen before a single neural network runs—during the 10 seconds you hold a phone over a glossy print.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When someone sends a blurry, sun-faded 1968 wedding print through a restoration tool and gets back plastic cheeks or smeared eyes, the natural assumption is that the AI model isn't strong enough yet.&lt;/p&gt;

&lt;p&gt;After troubleshooting hundreds of real family photo uploads while building &lt;a href="https://enhancephoto.org/" rel="noopener noreferrer"&gt;EnhancePhoto&lt;/a&gt;, we found a much less glamorous culprit: &lt;strong&gt;capture damage&lt;/strong&gt;. Over half of the worst outputs didn't fail because the print was too old. They failed because the person digitized the print under kitchen ceiling lights with a smartphone held at a 15-degree tilt.&lt;/p&gt;

&lt;p&gt;A restoration model cannot tell the difference between a real 1970s silver-halide crease and a ceiling-bulb glare streak reflecting off glossy photo paper. Once glare wipes out the highlight channel across someone's forehead or glasses, pixel values clip to pure white (&lt;code&gt;255, 255, 255&lt;/code&gt;). Every algorithm after that point is forced to guess.&lt;/p&gt;

&lt;p&gt;If you are digitizing shoebox prints for a family archive—or preparing prints for digital repair—these five capture rules fix more facial distortion than any prompt tweak or upscale slider.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Never Shoot Glossy Prints Under Overhead Lights
&lt;/h2&gt;

&lt;p&gt;Glossy and semi-gloss prints from the 1960s through 1990s behave like weak mirrors. Standing directly over a print on a dining table puts your phone shadow on one half of the photo and a bright ceiling reflection on the other.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What works instead:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tape or lay the print near a north-facing window with indirect daylight (never direct sun).&lt;/li&gt;
&lt;li&gt;Turn off overhead LEDs and desk lamps completely so there is only one soft directional light source.&lt;/li&gt;
&lt;li&gt;If a print is trapped behind glass in a frame you cannot open, place a large piece of black matte poster board directly in front of the camera lens with a hole cut for the lens—that eliminates 90% of room reflections immediately.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  2. Lock the Phone Parallel—Skip "Auto Perspective Crop"
&lt;/h2&gt;

&lt;p&gt;Document scanner apps love letting you shoot at a lazy 30-degree angle and then stretching the trapezoid back into a rectangle. That works fine for tax receipts. For portraits, perspective warping stretches facial proportions unevenly across the frame and introduces anisotropic blur—one eye stays sharp while the far ear smears across multiple pixels.&lt;/p&gt;

&lt;p&gt;Turn on the built-in &lt;strong&gt;crosshair level&lt;/strong&gt; in your phone camera settings (iOS Settings → Camera → Level; Android Camera → Framing Hints). Hold the phone flat until both crosshairs align dead center, then step slightly closer rather than using digital pinch-zoom.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Disable Live Photos, HDR Stacking, and Beauty Filters
&lt;/h2&gt;

&lt;p&gt;Modern smartphone cameras run aggressive multi-frame sharpening and skin-smoothing by default. When you photograph an already grainy physical print, the phone's ISP mistakes film grain for high-ISO digital noise, smears it flat, and then draws artificial dark outlines around the remaining edges.&lt;/p&gt;

&lt;p&gt;Before a scanning session:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Switch off &lt;strong&gt;Auto HDR&lt;/strong&gt; and &lt;strong&gt;Macro Auto-Switching&lt;/strong&gt; (macro ultra-wide lenses have noticeably softer corners than the main 1x sensor).&lt;/li&gt;
&lt;li&gt;Keep the main &lt;strong&gt;1x wide lens&lt;/strong&gt; active, hold 20–30 cm away, and tap directly on the subject's eyes to lock focus and exposure (&lt;code&gt;AE/AF Lock&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;Export or transfer the original JPEG/HEIC/PNG—never send it to yourself over WhatsApp, WeChat, or SMS first, which silently crushes resolution down to ~1200px and adds heavy 8×8 compression blocks.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  4. Don't Pre-Edit Contrast or "Auto-Enhance" Before Restoration
&lt;/h2&gt;

&lt;p&gt;A common habit is opening the phone gallery, hitting the magic wand "Auto Enhance" button to boost faded contrast, and &lt;em&gt;then&lt;/em&gt; uploading the edited copy for AI restoration.&lt;/p&gt;

&lt;p&gt;That order throws away recoverable shadow and highlight data. Faded 1970s Kodak prints often shift toward magenta or yellow because cyan dye degrades fastest over time. When a phone's auto-contrast curve clips the remaining weak channel to zero or 255, downstream color recovery loses the subtle tonal gradients needed to reconstruct natural skin undertones and period clothing colors.&lt;/p&gt;

&lt;p&gt;Keep the raw, flat, slightly washed-out scan untouched until the restoration pass itself handles color-cast normalization. (We wrote up the exact sequence we use for preserving natural skin and archival accuracy on our &lt;a href="https://enhancephoto.org/photo-restoration" rel="noopener noreferrer"&gt;photo restoration workflow&lt;/a&gt; page.)&lt;/p&gt;




&lt;h2&gt;
  
  
  5. When a $60 Flatbed Scanner Beats Every Phone
&lt;/h2&gt;

&lt;p&gt;If a print is smaller than 3×5 inches (wallet photos, passport portraits, contact-sheet frames) or suffers from heavy silvering and deep creases, smartphone sensors run out of optical resolving power fast.&lt;/p&gt;

&lt;p&gt;A basic flatbed scanner set to &lt;strong&gt;600 DPI (or 1200 DPI for wallet-sized prints)&lt;/strong&gt; in uncompressed TIFF or lossless PNG—with the scanner software's "Auto Dust Removal" and "Unsharp Mask" turned &lt;strong&gt;OFF&lt;/strong&gt;—gives you a flat, distortion-free illumination field that no handheld phone can match.&lt;/p&gt;




&lt;h2&gt;
  
  
  Quick Pre-Upload Checklist (Save Before Your Next Family Archive Session)
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Lighting:&lt;/strong&gt; Indirect window light, overhead lights OFF, zero specular glare on eyes or glasses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Geometry:&lt;/strong&gt; Main 1x lens only, crosshair level centered, no digital zoom.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;File hygiene:&lt;/strong&gt; Original camera file transferred via AirDrop / USB / cloud drive (never messaging-app compressed).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Color preservation:&lt;/strong&gt; Zero phone "Auto Enhance" or sharpening filters applied before restoration.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Garbage in still means hallucinated faces out. Spend three extra minutes getting a glare-free, uncompressed capture, and even modest restoration tools will recover expressions you thought were lost decades ago.&lt;/p&gt;

</description>
      <category>photography</category>
      <category>ai</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Stop Using `Math.random()` for Raffles: Building a Truly Fair Wheel with React &amp; Web Crypto API</title>
      <dc:creator>gaven yang</dc:creator>
      <pubDate>Sun, 18 Jan 2026 03:59:19 +0000</pubDate>
      <link>https://dev.to/gaven_yang_438e60f53e6ff2/stop-using-mathrandom-for-raffles-building-a-truly-fair-wheel-with-react-web-crypto-api-2ahh</link>
      <guid>https://dev.to/gaven_yang_438e60f53e6ff2/stop-using-mathrandom-for-raffles-building-a-truly-fair-wheel-with-react-web-crypto-api-2ahh</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpuqehn1wvmfro5kjz1xf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fpuqehn1wvmfro5kjz1xf.png" alt=" " width="800" height="350"&gt;&lt;/a&gt;We've all built that simple random picker for a side project using &lt;code&gt;Math.random()&lt;/code&gt;. It's easy, it's one line of code, and it works... mostly.&lt;/p&gt;

&lt;p&gt;But when I was building &lt;strong&gt;&lt;a href="https://joyspin.xyz" rel="noopener noreferrer"&gt;JoySpin&lt;/a&gt;&lt;/strong&gt; – a tool designed for teachers and live event raffles – I realized that "mostly" wasn't good enough. If a teacher uses my tool to pick a student for a prize, or a streamer uses it to give away a gift card, the randomness needs to be &lt;strong&gt;cryptographically secure&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Here is why &lt;code&gt;Math.random()&lt;/code&gt; fails for high-stakes picking, and how I implemented the &lt;strong&gt;Web Crypto API&lt;/strong&gt; in React to fix it.&lt;/p&gt;

&lt;h3&gt;
  
  
  The Problem: Pseudo-Randomness
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Math.random()&lt;/code&gt; is a Pseudo-Random Number Generator (PRNG). It’s fast, but it’s deterministic. If you know the internal state of the algorithm (like V8's XorShift128+), you can theoretically predict the next number.&lt;/p&gt;

&lt;p&gt;For a UI animation? Fine.&lt;br&gt;
For picking a winner? Not ideal.&lt;/p&gt;
&lt;h3&gt;
  
  
  The Solution: &lt;code&gt;window.crypto&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;To make JoySpin truly fair, I switched to &lt;code&gt;window.crypto.getRandomValues()&lt;/code&gt;. This taps into the operating system's entropy pool (mouse movements, keystrokes, thermal noise) to generate true randomness.&lt;/p&gt;

&lt;p&gt;Here is the React hook I wrote to handle the selection logic:&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 safe random number generator function&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;getSecureRandomNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;min&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;max&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;range&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;max&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;min&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;maxSafeInteger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;)&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="c1"&gt;// Determine the largest number that is a multiple of range&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;limit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;maxSafeInteger&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;maxSafeInteger&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="nx"&gt;range&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;randomBuffer&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="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;randomNumber&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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="nx"&gt;randomBuffer&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;randomNumber&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;randomBuffer&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomNumber&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="nx"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// Reject numbers to avoid bias (modulo bias)&lt;/span&gt;

  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;min&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;randomNumber&lt;/span&gt; &lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="nx"&gt;range&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;h3&gt;
  
  
  Handling the "Spin" State in React
&lt;/h3&gt;

&lt;p&gt;The logic is only half the battle. In &lt;strong&gt;JoySpin&lt;/strong&gt;, the UX is just as important. Users need to &lt;em&gt;feel&lt;/em&gt; the weight of the wheel.&lt;/p&gt;

&lt;p&gt;I separated the logic from the animation. The "Winner" is decided the moment the button is clicked (using the crypto function above), but the wheel visual is CSS logic that eases out to that specific degree.&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="nx"&gt;handleSpin&lt;/span&gt; &lt;span class="o"&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="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;spinning&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// 1. Decide the winner immediately using Crypto API&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;winningIndex&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;getSecureRandomNumber&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;currentList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;winner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;currentList&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;winningIndex&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="c1"&gt;// 2. Calculate rotation (add extra spins for suspense)&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;newRotation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;rotation&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1440&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;360&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;currentList&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;length&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;winningIndex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// 3. Update State&lt;/span&gt;
    &lt;span class="nf"&gt;setWinner&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;winner&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;setRotation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newRotation&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="c1"&gt;// ... animation logic&lt;/span&gt;
  &lt;span class="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The Result: A "Trustless" Picker
&lt;/h3&gt;

&lt;p&gt;By implementing this, I can tell users that the result isn't just a JavaScript quirk—it's mathematically fair.&lt;/p&gt;

&lt;p&gt;I built this into a full production app, &lt;strong&gt;&lt;a href="https://joyspin.xyz" rel="noopener noreferrer"&gt;JoySpin.xyz&lt;/a&gt;&lt;/strong&gt;. It runs entirely in the browser (no server-side bias), supports importing lists, and includes an "Instant Elimination" mode to remove winners after they are picked.&lt;/p&gt;

&lt;p&gt;If you are building a game or a raffle tool, I highly recommend ditching &lt;code&gt;Math.random()&lt;/code&gt;. The performance cost is negligible, but the trust you gain from users is worth it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Have you ever dealt with "randomness" complaints in your apps? Let me know in the comments!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>react</category>
      <category>javascript</category>
      <category>webdev</category>
      <category>opensource</category>
    </item>
  </channel>
</rss>
