<?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: Farbod F.</title>
    <description>The latest articles on DEV Community by Farbod F. (@farbodf).</description>
    <link>https://dev.to/farbodf</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%2F4185281%2Fd81958b4-48d0-4895-9e6e-478398a7fba2.png</url>
      <title>DEV Community: Farbod F.</title>
      <link>https://dev.to/farbodf</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/farbodf"/>
    <language>en</language>
    <item>
      <title>Stop hand-writing JSON-LD: generate valid schema markup in your browser</title>
      <dc:creator>Farbod F.</dc:creator>
      <pubDate>Fri, 27 Nov 2026 20:23:34 +0000</pubDate>
      <link>https://dev.to/farbodf/stop-hand-writing-json-ld-generate-valid-schema-markup-in-your-browser-3b16</link>
      <guid>https://dev.to/farbodf/stop-hand-writing-json-ld-generate-valid-schema-markup-in-your-browser-3b16</guid>
      <description>&lt;p&gt;Hand-written JSON-LD dies on one trailing comma. There is no error page, no red squiggle in production — the whole block is silently ignored, and the page carries on as if the markup was never there.&lt;/p&gt;

&lt;p&gt;That is the failure mode that matters. A schema block is not code your users run; it is a note to a parser. If the note is malformed, the parser drops it and says nothing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The tool
&lt;/h2&gt;

&lt;p&gt;The ToolsByUs SEO Schema Generator builds the block for you, in the browser. You fill in the fields, it writes the JSON-LD, and your file's contents never leave the browser — there is nothing to upload, because the generation happens on your machine.&lt;/p&gt;

&lt;p&gt;It supports 8 schema types: Article, Product, LocalBusiness, Event, JobPosting, Recipe, Breadcrumbs, and Organization. The Article form exposes 8 fields — headline, author name, date published, description, image URL, date modified, publisher name, and publisher logo URL — and only the fields you fill in appear in the output.&lt;/p&gt;

&lt;h2&gt;
  
  
  A worked example
&lt;/h2&gt;

&lt;p&gt;I generated an Article schema with the headline "How I test a PDF tool without uploading the file", author "Farbod F.", datePublished 2026-11-27, and publisher "ToolsByUs". This is the exact block the tool produced:&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;"@context"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"https://schema.org"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"@type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Article"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"headline"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"How I test a PDF tool without uploading the file"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"author"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"@type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Person"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Farbod F."&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"datePublished"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-27"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"publisher"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;"@type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Organization"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ToolsByUs"&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;The surprising part is how small it is: 14 lines, 300 bytes. That is the entire markup for a real article — headline, author, date, and publisher — and it parsed as valid JSON when I checked it in a JSON formatter, which re-indented it to the same 14 lines and 300 bytes. The generator adds nothing you did not ask for: leave a field blank and it stays out of the output.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://toolsbyus.com/seo-schema-generator" rel="noopener noreferrer"&gt;Generate your schema with the ToolsByUs SEO Schema Generator&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Honest caveats
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Valid JSON-LD does not guarantee rich results. Google decides what, if anything, gets displayed — valid markup is a prerequisite, not a promise.&lt;/li&gt;
&lt;li&gt;Mark up only content that is actually on the page. Marking up invisible content is spam, and search engines treat it that way.&lt;/li&gt;
&lt;li&gt;Dates and values must be real. A datePublished that does not match the page, or an author who did not write the article, is a false statement in machine-readable form.&lt;/li&gt;
&lt;li&gt;The tool checks structure, not truth. It can tell you the JSON parses; it cannot tell you whether the facts inside it are correct. That part is still yours.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>seo</category>
      <category>tools</category>
    </item>
    <item>
      <title>Yes, someone built an air fryer cost calculator — the kWh math behind it</title>
      <dc:creator>Farbod F.</dc:creator>
      <pubDate>Fri, 27 Nov 2026 19:19:29 +0000</pubDate>
      <link>https://dev.to/farbodf/yes-someone-built-an-air-fryer-cost-calculator-the-kwh-math-behind-it-56m</link>
      <guid>https://dev.to/farbodf/yes-someone-built-an-air-fryer-cost-calculator-the-kwh-math-behind-it-56m</guid>
      <description>&lt;p&gt;An air fryer is a small oven with a fan and a marketing department. It is also, genuinely, a much cheaper way to cook a batch of fries — but "much cheaper" turns out to be a specific number, and the number depends on a variable most people never think about: the duty cycle, the fraction of the cooking time the heating element is actually on. A 1500-watt air fryer does not draw 1500 watts for 20 minutes straight. Once it reaches temperature, the element cycles on and off, and that cycling is most of the math.&lt;/p&gt;

&lt;h2&gt;
  
  
  The worked example: fries, 20 minutes, 1500 W
&lt;/h2&gt;

&lt;p&gt;The energy formula is simple — power × time — but the power term is an average, not the label on the box:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rated power: 1500 W, cooking time: 20 minutes, duty cycle once at temperature: ~65%&lt;/li&gt;
&lt;li&gt;Energy: 1.5 kW × (20 ÷ 60) h × 0.65 = &lt;strong&gt;0.325 kWh&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;At the US average residential rate of about 17¢/kWh: 0.325 × $0.17 = &lt;strong&gt;$0.055, about 6 cents per cook&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now the same batch of fries in a conventional electric oven. A typical oven element is 2400 W, and it has to heat a box roughly ten times the volume of an air fryer basket before the food even starts cooking:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Preheat: 15 minutes at full power: 2.4 kW × 0.25 h = &lt;strong&gt;0.600 kWh&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Cook: 25 minutes at ~50% duty cycle: 2.4 kW × (25 ÷ 60) h × 0.5 = &lt;strong&gt;0.500 kWh&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Oven total: &lt;strong&gt;1.100 kWh&lt;/strong&gt;, or about &lt;strong&gt;19 cents&lt;/strong&gt; at the same rate&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So the air fryer uses 0.325 kWh against the oven's 1.100 kWh — the oven costs &lt;strong&gt;3.38× as much&lt;/strong&gt; per batch, and the air fryer saves &lt;strong&gt;$0.13 per cook, about 70% less energy&lt;/strong&gt;. Cook fries four times a week and the annual totals are 67.6 kWh ($11.49) for the air fryer versus 228.8 kWh ($38.90) for the oven: a saving of &lt;strong&gt;$27.40 a year&lt;/strong&gt;. Real money, but not life-changing money — which is itself the honest answer to "does an air fryer save you money on energy?"&lt;/p&gt;

&lt;h2&gt;
  
  
  The surprising part: the oven's preheat alone beats the whole air-fryer cook
&lt;/h2&gt;

&lt;p&gt;Here is the figure that stopped me. The oven's preheat — fifteen minutes of heating an empty box — consumes 0.600 kWh. The entire air-fryer cook, food included, consumes 0.325 kWh. &lt;strong&gt;Preheating the oven uses 1.85× the energy of cooking the whole meal in the air fryer.&lt;/strong&gt; The preheat is pure overhead: it cooks nothing, and it costs more than the entire alternative.&lt;/p&gt;

&lt;p&gt;That is also why the air fryer's advantage shrinks on long cooks. The duty-cycle gap narrows once both appliances are at temperature, and for a two-hour roast the oven's big-box penalty matters less per minute. The air fryer wins biggest exactly where people use it most: short, everyday cooks where the preheat dominates the oven's bill.&lt;/p&gt;

&lt;h2&gt;
  
  
  The code: duty cycle is the whole model
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;energyKwh&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;watts&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minutes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;dutyCycle&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="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="n"&gt;watts&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;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;minutes&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;dutyCycle&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;cost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;kwh&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;rateCents&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="nb"&gt;Math&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;kwh&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;rateCents&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&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="no"&gt;RATE&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;17&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// US avg residential, cents/kWh (EIA 2024: 16.5)&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;airFryer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;energyKwh&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.65&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;      &lt;span class="c1"&gt;// 0.325 kWh&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;ovenPreheat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;energyKwh&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2400&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;15&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="p"&gt;;&lt;/span&gt;       &lt;span class="c1"&gt;// 0.600 kWh&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;ovenCook&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;energyKwh&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2400&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;        &lt;span class="c1"&gt;// 0.500 kWh&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;oven&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;ovenPreheat&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;ovenCook&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;               &lt;span class="c1"&gt;// 1.100 kWh&lt;/span&gt;

&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"air fryer: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;airFryer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toFixed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;" kWh, $"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;cost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;airFryer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;RATE&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;// air fryer: 0.325 kWh, $0.06&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"oven: "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;oven&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toFixed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;" kWh, $"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;cost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;oven&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;RATE&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;// oven: 1.100 kWh, $0.19&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"oven costs "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;oven&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;airFryer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toFixed&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="o"&gt;+&lt;/span&gt; &lt;span class="s2"&gt;"x the air fryer"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// oven costs 3.38x the air fryer&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;cooksPerYear&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;52&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"annual saving: $"&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nf"&gt;cost&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;cooksPerYear&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;oven&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;airFryer&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="no"&gt;RATE&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;// annual saving: $27.4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details matter. First, cost is rounded in integer cents (&lt;code&gt;Math.round(kwh * rateCents) / 100&lt;/code&gt;) so a 5.53-cent cook displays as $0.06, not $0.05525000000000001. Second, the duty cycle is a parameter, not a constant baked into the wattage — the same function models a 50% duty cycle (0.250 kWh, $0.04) or an 80% one (0.400 kWh, $0.07), so the sensitivity is visible instead of hidden in a magic number.&lt;/p&gt;

&lt;h2&gt;
  
  
  Honest caveats
&lt;/h2&gt;

&lt;p&gt;The duty cycle is an estimate, not a measurement: real air fryers cycle differently by model, food load, and set temperature, and a basket crammed full of cold fries runs the element longer than a half-empty one. The 17¢/kWh rate is a US average — Californians pay roughly double and some Europeans pay more still, which scales every dollar figure here but leaves the 3.38× ratio untouched, since both appliances pay the same rate. The oven comparison assumes you preheat for the full 15 minutes and cook 25; skip the preheat or cook a tray that fills the oven, and the oven's per-serving cost drops fast — the air fryer wins per batch, the oven can win per serving at scale. And the $27.40 annual saving does not pay for the air fryer itself: at a typical $80–120 purchase price, the energy saving alone takes three to four years to break even. You buy an air fryer for speed and crispiness; the energy saving is a bonus, not the business case.&lt;/p&gt;

&lt;p&gt;The point of building the calculator isn't that air-fryer math is hard. It's that the headline number — 1500 watts — is the wrong number, and the right one hides in a duty cycle nobody prints on the box. You can try the working version here: the &lt;a href="https://youcancalc.com/calculators/air-fryer-calculator/" rel="noopener noreferrer"&gt;air fryer calculator&lt;/a&gt; on youcancalc.com takes your wattage, time, and electricity rate and does the same calculation for your kitchen.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>I decode JWTs in the browser — and the token never leaves the tab</title>
      <dc:creator>Farbod F.</dc:creator>
      <pubDate>Mon, 23 Nov 2026 20:19:47 +0000</pubDate>
      <link>https://dev.to/farbodf/i-decode-jwts-in-the-browser-and-the-token-never-leaves-the-tab-3dpe</link>
      <guid>https://dev.to/farbodf/i-decode-jwts-in-the-browser-and-the-token-never-leaves-the-tab-3dpe</guid>
      <description>&lt;p&gt;A JWT looks like a string of punctuation until you split it on its two dots. Then it stops being opaque. It becomes a small, readable JSON document — and that is exactly why where you decode it matters.&lt;/p&gt;

&lt;p&gt;I ran the classic sample token through a browser decoder to see what it actually shows, instead of taking the usual explanation on trust. Here is what came back, and what it does not prove.&lt;/p&gt;

&lt;h2&gt;
  
  
  The three parts
&lt;/h2&gt;

&lt;p&gt;A token is &lt;code&gt;header.payload.signature&lt;/code&gt;, three base64url segments joined by dots.&lt;/p&gt;

&lt;p&gt;The header says how the token was signed. The payload carries the claims — the statements about the subject, when the token was issued, and when it stops being valid. The signature is the part a server checks to decide whether the first two parts were tampered with.&lt;/p&gt;

&lt;p&gt;The first two parts are not encrypted. Base64url is an encoding, not a cipher. Anyone who holds the token can read every claim in it. That is the first thing decoding teaches you: a JWT is a signed envelope, not a sealed one. Do not put anything in a payload that you would not want the holder to read.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the live run showed
&lt;/h2&gt;

&lt;p&gt;I pasted in the classic sample token:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The tool reported the input as 155 bytes on one line, then split it into a 36-byte, 4-line header and a 68-byte, 5-line payload:&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;"alg"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"HS256"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"typ"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"JWT"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&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;"sub"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"1234567890"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"John Doe"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"iat"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1516239022&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It annotated three claims. &lt;code&gt;sub&lt;/code&gt; is &lt;code&gt;1234567890&lt;/code&gt;, the subject the token is about, usually a user ID. &lt;code&gt;name&lt;/code&gt; is &lt;code&gt;John Doe&lt;/code&gt;, the display name. And &lt;code&gt;iat&lt;/code&gt;, the issued-at time, is &lt;code&gt;1516239022&lt;/code&gt;, rendered as 2018-01-18 01:30:22 UTC — 3,232 days ago at the time I ran it. That relative rendering is the detail that makes a raw timestamp useful: a number becomes a date, and a date becomes a story about how old this token is.&lt;/p&gt;

&lt;p&gt;The signature was shown, not checked: HS256 HMAC, &lt;code&gt;SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c&lt;/code&gt;, with the note that verifying it needs the issuer's key, and fetching one would mean sending the token somewhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  Two warnings worth reading
&lt;/h2&gt;

&lt;p&gt;The tool flagged two missing claims, and both matter more than the decoded values themselves.&lt;/p&gt;

&lt;p&gt;First, there is no &lt;code&gt;exp&lt;/code&gt; claim, so this token does not expire on its own and can only be stopped by revocation. Second, there is no &lt;code&gt;aud&lt;/code&gt; claim. Without an audience, a token issued for one service can be replayed against another service that trusts the same issuer. A token can decode cleanly and still be missing the claims that limit where and how long it is valid.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why local decoding matters
&lt;/h2&gt;

&lt;p&gt;Tokens carry real session data: user IDs, roles, expiry times, sometimes more than the developer who issued them intended. Pasting one into a server-side decoder sends that session data to someone else's log. Decoding it in the tab keeps it in the tab.&lt;/p&gt;

&lt;p&gt;That is the workflow I used here: &lt;a href="https://toolsbyus.com/jwt-decoder" rel="noopener noreferrer"&gt;the JWT Decoder&lt;/a&gt; runs entirely in the browser, so the token I pasted was decoded locally and never transmitted. For a sample token that distinction is academic. For a production token copied out of a failing request, it is the whole point.&lt;/p&gt;

&lt;h2&gt;
  
  
  Honest caveats: decoding is not verifying
&lt;/h2&gt;

&lt;p&gt;Decoding tells you what a token claims. It tells you nothing about whether those claims are true.&lt;/p&gt;

&lt;p&gt;The signature cannot be checked without the secret, so a decoded token proves nothing about authenticity. Anyone can craft a token with any &lt;code&gt;sub&lt;/code&gt; and &lt;code&gt;name&lt;/code&gt; they like, sign it with a key they control, and have it decode into perfectly readable JSON. The readable part is the easy part. Trust comes from the signature check, and that check belongs in your service, where the key already lives — not in a browser page.&lt;/p&gt;

&lt;p&gt;The same applies to expiry. The sample token had no &lt;code&gt;exp&lt;/code&gt; claim, so there was no expiry verdict to record for it. The tool's own guidance is that expiry is a claim inside the payload, not a property of the encoding: an expired token decodes exactly like a live one, and the tool reads the expiry and reports when it expired and how long ago. In other words, decoding will happily show you an expired token. It will not reject it for you. That is your server's job.&lt;/p&gt;

&lt;h2&gt;
  
  
  The habit to take away
&lt;/h2&gt;

&lt;p&gt;When a request fails with a 401, decode the token before you blame permissions. Check &lt;code&gt;iat&lt;/code&gt; and &lt;code&gt;exp&lt;/code&gt; first, then &lt;code&gt;aud&lt;/code&gt;, then &lt;code&gt;sub&lt;/code&gt;. Often the answer is a lifetime problem, a wrong audience, or a token older than you expected — and you can see all three without the token ever leaving your browser.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>tools</category>
      <category>security</category>
    </item>
    <item>
      <title>Percentage calculations have 3 flavors — handling all of them in one UI</title>
      <dc:creator>Farbod F.</dc:creator>
      <pubDate>Mon, 23 Nov 2026 19:20:28 +0000</pubDate>
      <link>https://dev.to/farbodf/percentage-calculations-have-3-flavors-handling-all-of-them-in-one-ui-hh</link>
      <guid>https://dev.to/farbodf/percentage-calculations-have-3-flavors-handling-all-of-them-in-one-ui-hh</guid>
      <description>&lt;p&gt;Percentage calculations have 3 flavors — handling all of them in one UI&lt;/p&gt;

&lt;p&gt;Every percentage calculator on the web asks you to pick a mode first, and users hate that. The reason is simple: "percentage" is not one calculation. It is three different questions wearing the same % sign, and a calculator that treats them as one will quietly give the wrong answer. Here is how to handle all three in a single UI — and the edge cases that break naive implementations.&lt;/p&gt;

&lt;p&gt;The three flavors&lt;/p&gt;

&lt;p&gt;Flavor 1: What is X% of Y? The classic. 20% of an $85 bill is $17, so a 20% tip on $85 is $17 and the total is $102. Formula: Y * X / 100.&lt;/p&gt;

&lt;p&gt;Flavor 2: X is what % of Y? The comparison. $45 is what percentage of $180? 45 / 180 × 100 = 25%. Formula: X / Y * 100.&lt;/p&gt;

&lt;p&gt;Flavor 3: Percentage change. The price went from $60 to $75. That is (75 − 60) / 60 × 100 = a 25% increase. And $80 with 25% off is $80 × 0.75 = $60. Formula: (new − old) / old * 100.&lt;/p&gt;

&lt;p&gt;A single input pair (two numbers and one percentage) can serve all three if the UI labels the result instead of making the user choose a mode upfront. Type 20, 85, and the calculator can show all three readings at once: 20% of 85 is 17; 20 is 23.5% of 85; going from 85 to 20 is a 76.5% decrease. (Check: 20 / 85 × 100 = 23.529…%, and (20 − 85) / 85 × 100 = −76.47%.)&lt;/p&gt;

&lt;p&gt;The worked example: a 25% sale&lt;/p&gt;

&lt;p&gt;A jacket costs $120. The store takes 25% off, then a week later puts the price back up by 25%. What does it cost now?&lt;/p&gt;

&lt;p&gt;Step 1: $120 × 0.75 = $90.&lt;br&gt;
Step 2: $90 × 1.25 = $112.50.&lt;/p&gt;

&lt;p&gt;Not $120. A 25% cut followed by a 25% rise leaves you 6.25% below where you started, because the second percentage is taken from a smaller base. The general rule: a cut of p% followed by a rise of p% leaves (1 − p²) of the original — here 1 − 0.0625 = 0.9375, and 0.9375 × $120 = $112.50. This is the single most common percentage mistake in retail, and it is why "50% off, then 50% back up" on a $100 item lands at $75, not $100.&lt;/p&gt;

&lt;p&gt;The surprising figure: percentage points are not percent&lt;/p&gt;

&lt;p&gt;A mortgage rate rises from 4% to 5%. Headlines call it "a 1% increase." It is not. It is a 1 percentage point increase — and a 25% relative increase: (5 − 4) / 4 × 100 = 25%. On a $400,000 loan, that "1%" costs about $238 more per month. (Rough check: at 4% over 30 years the payment is about $1,910/month; at 5% it is about $2,147/month — a difference of about $237.) Confusing percentage points with percent is a small language error with a four-figure monthly price tag, and it is the reason every honest percentage calculator should label which one it is showing.&lt;/p&gt;

&lt;p&gt;Implementation: the rounding trap&lt;/p&gt;

&lt;p&gt;The math is trivial; the edge cases are not.&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;function&lt;/span&gt; &lt;span class="nf"&gt;percentOf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;base&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="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;base&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;whatPercent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;part&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;whole&lt;/span&gt;&lt;span class="p"&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="n"&gt;whole&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="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;// division by zero: no answer, not Infinity&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;part&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;whole&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;percentChange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;oldVal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;newVal&lt;/span&gt;&lt;span class="p"&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="n"&gt;oldVal&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="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;// change from zero is undefined&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;newVal&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;oldVal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;oldVal&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// Display: round to cents for money, 2 decimals otherwise&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;fmt&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="k"&gt;return&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;round&lt;/span&gt;&lt;span class="p"&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;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&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;Three traps to handle explicitly:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Floating-point dust. 15% of $33.33 is 4.9995 in exact math, and JavaScript computes 0.15 * 33.33 as 4.999499999999999. Round for display (Math.round(n * 100) / 100 → 5.00) but never round the stored value mid-chain, or chained percentages drift.&lt;/li&gt;
&lt;li&gt;Division by zero. "What % is $50 of $0?" has no answer. Return null and say so — showing Infinity is a bug, not an edge case.&lt;/li&gt;
&lt;li&gt;Percent vs. percentage points. If your UI lets users compare two rates, label the outputs separately: "+1.00 pp" and "+25.00%". One label prevents the mortgage-rate confusion above.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Honest caveats&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Percentages hide the base. "Sales up 200%" sounds enormous until you learn sales went from 10 units to 30. Always show the absolute numbers next to the percentage — a calculator that shows only the % is hiding the story.&lt;/li&gt;
&lt;li&gt;Rounding to two decimals is a display choice, not a math result. A 33.333…% share of a bill split three ways does not become exact by rounding; the cents have to go somewhere, and your UI should say where.&lt;/li&gt;
&lt;li&gt;"Percent off" and "percent more" are not symmetric, as the jacket example shows. Any calculator that applies them as if they were is wrong by construction.&lt;/li&gt;
&lt;li&gt;This covers the three everyday flavors. Statisticians will rightly point out there are more (percentage points, basis points, relative risk), but for a general-purpose calculator these three answer the questions real users actually ask.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The full working version, with all three flavors in one page and no backend, is the percentage calculator at &lt;a href="https://youcancalc.com/calculators/percentage-calculator/" rel="noopener noreferrer"&gt;https://youcancalc.com/calculators/percentage-calculator/&lt;/a&gt; — try the jacket example on it and check the $112.50 yourself.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>I merge PDFs without uploading them — and I can prove it</title>
      <dc:creator>Farbod F.</dc:creator>
      <pubDate>Thu, 19 Nov 2026 20:31:54 +0000</pubDate>
      <link>https://dev.to/farbodf/i-merge-pdfs-without-uploading-them-and-i-can-prove-it-1ohl</link>
      <guid>https://dev.to/farbodf/i-merge-pdfs-without-uploading-them-and-i-can-prove-it-1ohl</guid>
      <description>&lt;p&gt;Most "free PDF merger" sites ask you to upload your document to a server you did not choose, wait, then download the result from that same server. I wanted to know whether the merge could happen without that round trip, so I tested it with two files I made for the purpose and measured what happened.&lt;/p&gt;

&lt;h2&gt;
  
  
  The test
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;qa-merge-a.pdf&lt;/code&gt; — a one-page invoice summary: 1 page, 631 bytes&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;qa-merge-b.pdf&lt;/code&gt; — a two-page contract: 2 pages, 951 bytes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Total going in: 3 pages, 1,582 bytes.&lt;/p&gt;

&lt;p&gt;I dropped both files into the Merge PDF tool and clicked Merge. It finished in 2.4 seconds. The file that came back, &lt;code&gt;qa-merge-a-merged.pdf&lt;/code&gt;, was 3 pages and 1.1 KB. I read the result back a second way, in the same site's Split PDF tool, which reported the same file as 3 pages at 612 × 792 pt. The page counts add up: 1 + 2 = 3.&lt;/p&gt;

&lt;h2&gt;
  
  
  The surprising part
&lt;/h2&gt;

&lt;p&gt;The merged file is smaller than the two files I put in: 1.1 KB out, against 1.5 KB in. That is not a compression trick. A PDF is not a stack of pages; it is an object graph, and merging copies each page together with the objects it depends on, renumbering the references as it goes. When both inputs share a resource — a font, for example — it gets written once. So the output can come out lighter than the sum of its parts, and nothing in either file was re-rendered or re-encoded to make that happen. Page content, fonts, and images survive exactly; what does not survive is the document-level outline, so bookmarks are not carried over.&lt;/p&gt;

&lt;p&gt;The other half of it is where the work happened: the merge ran in a Web Worker in my own browser tab. The site's Content Security Policy sets &lt;code&gt;connect-src 'self'&lt;/code&gt;, and its automated tests fail the build if any tool request carries a body. That is the mechanism, not a promise — there is nowhere for the file to go, because the page is not allowed to send it anywhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this is part of
&lt;/h2&gt;

&lt;p&gt;ToolsByUs is a set of 136 free tools that all run this way: 100% client-side, no signup, in 6 locales. The merge tool is one of them: &lt;a href="https://toolsbyus.com/merge-pdf" rel="noopener noreferrer"&gt;Merge PDF&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Honest caveats
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The 2.4 seconds was for two tiny files, 1,582 bytes in total. A large file will not take 2.4 seconds. The tool's own limits are 100 MB per file, 250 MB total, and 100 files.&lt;/li&gt;
&lt;li&gt;The merge happens in your browser, so it uses your machine's memory and processor. A very large merge on a weak device will feel it.&lt;/li&gt;
&lt;li&gt;Bookmarks do not survive a merge. If the outline matters to you, keep the original.&lt;/li&gt;
&lt;li&gt;Encrypted PDFs are declined. Unlock one first if you have the password.&lt;/li&gt;
&lt;li&gt;"Never leaves the browser" is a property of this tool's implementation, which I checked by watching what it does — not a guarantee I can make about every tool that says the same words. Test the ones you rely on.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The check you can repeat
&lt;/h2&gt;

&lt;p&gt;Take two PDFs you made yourself, note their page counts and sizes, merge them, and read the result back in a second tool. If the page count adds up and the file never left your machine, the claim holds. Mine did: 1 + 2 = 3 pages, 2.4 seconds, 1.1 KB out.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>tools</category>
      <category>privacy</category>
    </item>
    <item>
      <title>Tip math, bill splitting, and rounding: small calculators, real edge cases</title>
      <dc:creator>Farbod F.</dc:creator>
      <pubDate>Thu, 19 Nov 2026 19:20:27 +0000</pubDate>
      <link>https://dev.to/farbodf/tip-math-bill-splitting-and-rounding-small-calculators-real-edge-cases-2gb2</link>
      <guid>https://dev.to/farbodf/tip-math-bill-splitting-and-rounding-small-calculators-real-edge-cases-2gb2</guid>
      <description>&lt;h1&gt;
  
  
  Tip math, bill splitting, and rounding: small calculators, real edge cases
&lt;/h1&gt;

&lt;p&gt;Tipping looks like the simplest math in everyday life: take 20%, add it on, done. But the moment you split a bill, tip on the taxed total, or round to whole dollars, the arithmetic quietly stops adding up. A tip calculator is a small program, but it sits on top of three genuinely tricky problems — percentages on the wrong base, division that doesn't come out even, and rounding that creates or destroys cents. All three are worth handling deliberately, because getting them wrong is how a table of four ends up a cent short and nobody knows whose fault it is.&lt;/p&gt;

&lt;h2&gt;
  
  
  The worked example: an $84.50 dinner, four people, 18%
&lt;/h2&gt;

&lt;p&gt;Start with the straightforward part. The bill is $84.50 and the table agrees on 18%:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tip: 84.50 × 0.18 = &lt;strong&gt;$15.21&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Total: 84.50 + 15.21 = &lt;strong&gt;$99.71&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Each person's share: 99.71 ÷ 4 = &lt;strong&gt;$24.93&lt;/strong&gt; (24.9275, rounded)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And here's the first edge case, hiding in plain sight: $24.93 × 4 = &lt;strong&gt;$99.72&lt;/strong&gt; — one cent &lt;em&gt;more&lt;/em&gt; than the bill. The split doesn't divide evenly, so rounding each share up creates a phantom cent. If instead you round each share down to $24.92, the table collects $99.68 and comes up three cents short. There is no way to split $99.71 into four equal cent-exact amounts, because 99.71 isn't divisible by 4. The honest fix is the one every good bill-splitting app uses: three people pay $24.93 and one pays $24.92 (24.93 × 3 + 24.92 = 99.71 exactly). Equal shares are an approximation; exact shares aren't equal.&lt;/p&gt;

&lt;p&gt;The same thing happens with three people: $99.71 ÷ 3 = $33.24 (33.2366…), and $33.24 × 3 = $99.72 — again a cent over. The remainder always has to go somewhere, and "somewhere" is a design decision, not a math error.&lt;/p&gt;

&lt;h2&gt;
  
  
  The surprising part: tipping on the taxed total costs real money
&lt;/h2&gt;

&lt;p&gt;Here's the figure that surprises people. In many US cities the bill you tip on includes sales tax — and the difference isn't trivial. Take that $84.50 bill with 8.875% tax (New York City's rate):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tax: 84.50 × 0.08875 = &lt;strong&gt;$7.50&lt;/strong&gt;, so the post-tax total is &lt;strong&gt;$92.00&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;A 20% tip on the pre-tax bill: 84.50 × 0.20 = &lt;strong&gt;$16.90&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;A 20% tip on the post-tax total: 92.00 × 0.20 = &lt;strong&gt;$18.40&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Difference: &lt;strong&gt;$1.50 per meal&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A dollar fifty sounds like nothing — until you annualize it. Eat out once a week on a $60 pre-tax bill and a 20% tip is $12.00 a week, &lt;strong&gt;$624 a year&lt;/strong&gt;. Tip on the taxed total instead and you're paying roughly 8.875% more than that every single time — about $55 extra a year on the same meals, for the same service. The etiquette guides mostly say to tip on the pre-tax amount; the point here isn't the etiquette, it's that the base you choose is a real number with a real annual cost, and most people never notice which base they're using.&lt;/p&gt;

&lt;h2&gt;
  
  
  The code: about 40 lines, and the rounding is the whole job
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;tipCalc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bill&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;pct&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;people&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="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;onTaxedTotal&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;taxRate&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="o"&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;onTaxedTotal&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;bill&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;taxRate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;bill&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;tip&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;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;base&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;pct&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&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;total&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;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bill&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;tip&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;bill&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;taxRate&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="c1"&gt;// Split so the shares sum EXACTLY to the total: the remainder&lt;/span&gt;
  &lt;span class="c1"&gt;// (in whole cents) is distributed one cent at a time.&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;totalCents&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;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;total&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;100&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;shareCents&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;floor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;totalCents&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="n"&gt;people&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;remainder&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;totalCents&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;shareCents&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;people&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;shares&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;people&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="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;shareCents&lt;/span&gt; &lt;span class="o"&gt;+&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;lt;&lt;/span&gt; &lt;span class="n"&gt;remainder&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="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="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;100&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="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;tip&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;total&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;shares&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="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;dinner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;tipCalc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;84.50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.18&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dinner&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="c1"&gt;// { tip: 15.21, total: 99.71, shares: [ 24.93, 24.93, 24.93, 24.92 ] }&lt;/span&gt;
&lt;span class="nb"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;tipCalc&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;84.50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.20&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="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;onTaxedTotal&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;taxRate&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.08875&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;// { tip: 18.4, total: 110.4, shares: [ 110.4 ] }&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two details matter. First, the rounding happens in integer cents (&lt;code&gt;Math.round(x * 100) / 100&lt;/code&gt;), never on the raw float — &lt;code&gt;0.1 + 0.2&lt;/code&gt; style errors are exactly the kind of thing that turns a $15.21 tip into $15.209999999999999. Second, the split distributes the remainder cent-by-cent instead of rounding every share independently, so the shares always sum to the total. The one-cent difference between "fair" and "exact" is a choice the code has to make explicitly.&lt;/p&gt;

&lt;h2&gt;
  
  
  Honest caveats
&lt;/h2&gt;

&lt;p&gt;Tipping norms vary wildly by country — 20% is a US convention, not a law of nature, and in much of Europe and Asia the expected tip is far lower or zero, with service already included. Tax rates differ by city, so the $1.50 figure above is specific to an 8.875% rate; your city's number will differ, but the &lt;em&gt;mechanism&lt;/em&gt; — tipping on a taxed base inflates the tip by the tax rate — holds everywhere. Rounding to whole dollars ("just make it an even $100") is a fine social shortcut, but on a $99.71 bill it's a 29-cent overpayment, and those round-ups add up the same way the tax-base difference does. And no calculator settles the etiquette question of &lt;em&gt;what percentage&lt;/em&gt; is right — it only makes the arithmetic honest once you've decided.&lt;/p&gt;

&lt;p&gt;The point of building the calculator isn't that tip math is hard. It's that the easy-looking cases — a four-way split, a taxed total — are where silent one-cent errors and quiet annual costs live. You can try the working version here: the &lt;a href="https://youcancalc.com/calculators/tip-calculator/" rel="noopener noreferrer"&gt;tip calculator&lt;/a&gt; on youcancalc.com handles the tip, the split, and the rounding, with the shares always adding up to the total.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>I remove photo backgrounds without uploading the photo — the model runs in my browser</title>
      <dc:creator>Farbod F.</dc:creator>
      <pubDate>Sun, 15 Nov 2026 20:29:11 +0000</pubDate>
      <link>https://dev.to/farbodf/i-remove-photo-backgrounds-without-uploading-the-photo-the-model-runs-in-my-browser-ci7</link>
      <guid>https://dev.to/farbodf/i-remove-photo-backgrounds-without-uploading-the-photo-the-model-runs-in-my-browser-ci7</guid>
      <description>&lt;p&gt;Every background remover I used before this one asked for the same thing first: upload your photo. The photo goes to a server, a model runs there, a cut-out comes back. The privacy page says the file is deleted afterwards, and I have no way to check that.&lt;/p&gt;

&lt;p&gt;There is a different way to build the same feature, and it is the one I ended up shipping: download the model to the browser, run it there, and never send the photo anywhere.&lt;/p&gt;

&lt;h2&gt;
  
  
  How it actually works
&lt;/h2&gt;

&lt;p&gt;The tool is the Background Remover on ToolsByUs. It loads a segmentation model in the browser with ONNX Runtime Web — the model file downloads once into the browser, inference runs locally on your device, and the output is a transparent PNG. The photo's contents never leave the tab, because there is no upload step at all. There is no account, no API key, and no server that ever sees the image.&lt;/p&gt;

&lt;p&gt;That is a narrower claim than "your photo is private". It is a checkable one: open the network tab, drop in a photo, and watch — nothing is posted.&lt;/p&gt;

&lt;h2&gt;
  
  
  A real run
&lt;/h2&gt;

&lt;p&gt;I ran it on a real portrait: a 1280×1920 JPEG, about 400 KB — a woman, head and shoulders, against a plain light-grey background.&lt;/p&gt;

&lt;p&gt;On the first run in a fresh browser, the tool downloaded the model file — the page's progress showed 25.5 MB in total — and from clicking "Remove background" to a finished result took under 30 seconds, download included. A second run with the model cached took under 10 seconds. The output was a transparent PNG at the photo's full 1280×1920 resolution, 4.7 MB, up from the 400 KB JPEG I started with.&lt;/p&gt;

&lt;p&gt;At full zoom, the plain grey background is completely gone and the edges around the shoulders and neck are clean. The hair is good but not flawless: a few fine strands on the right side of the head carry a faint whitish halo where the light-grey background shows through, and there is a slight grey fringe along a couple of strands on the left. No part of the subject is cut away, and there are no leftover chunks of background — the flaws are the kind you only notice when you zoom in.&lt;/p&gt;

&lt;h2&gt;
  
  
  The part nobody mentions: the first run costs a download
&lt;/h2&gt;

&lt;p&gt;The honest trade-off of running a model in the browser is that the model has to get there. The first time you open the tool, it downloads the model file — that is the price of never uploading your photo. On a slow connection that first load is noticeable; later runs reuse the cached model and start fast.&lt;/p&gt;

&lt;p&gt;The other trade-off is your own hardware doing the work. There is no server GPU. A large photo takes longer and uses more memory than a small one, and if you close the tab mid-run, nothing is saved anywhere — there is no server copy to recover.&lt;/p&gt;

&lt;h2&gt;
  
  
  Honest caveats
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The model download happens once per browser (cached afterwards), but clearing site data means downloading it again.&lt;/li&gt;
&lt;li&gt;Edge quality on hair, fur, glass and thin objects is good, not perfect. Check the result at full zoom before you ship it.&lt;/li&gt;
&lt;li&gt;Transparent PNGs are usually larger than the JPEG you started from. That is the format, not a bug.&lt;/li&gt;
&lt;li&gt;No upload means no server-side anything: no queue, no faster GPU, no recovery if you close the tab.&lt;/li&gt;
&lt;li&gt;"Your file's contents never leave the browser" is the whole guarantee. Analytics, if any, is configured separately — the guarantee covers your file, not the page.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Why I keep building this way
&lt;/h2&gt;

&lt;p&gt;ToolsByUs is 136 free tools, all client-side. The background remover is the clearest example of why: the privacy is in the architecture, not in a promise on a privacy page. You can verify it yourself in the network tab in about thirty seconds.&lt;/p&gt;

&lt;p&gt;The tool is free, no signup: &lt;a href="https://toolsbyus.com/remove-background" rel="noopener noreferrer"&gt;https://toolsbyus.com/remove-background&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>privacy</category>
      <category>tools</category>
    </item>
    <item>
      <title>90-minute sleep cycles: the simple math behind bedtime calculators</title>
      <dc:creator>Farbod F.</dc:creator>
      <pubDate>Sun, 15 Nov 2026 19:19:34 +0000</pubDate>
      <link>https://dev.to/farbodf/90-minute-sleep-cycles-the-simple-math-behind-bedtime-calculators-592p</link>
      <guid>https://dev.to/farbodf/90-minute-sleep-cycles-the-simple-math-behind-bedtime-calculators-592p</guid>
      <description>&lt;p&gt;90-minute sleep cycles: the simple math behind bedtime calculators&lt;/p&gt;

&lt;p&gt;Sleep calculators look like magic: you type in the time you want to wake up, and they hand you a list of bedtimes like 10:45 PM, 12:15 AM, 1:45 AM. The gaps between those times are always 90 minutes, and that's the whole trick. Sleep isn't one long block — it's a series of roughly 90-minute cycles, and waking up at the end of a cycle feels very different from waking up in the middle of one.&lt;/p&gt;

&lt;p&gt;The model in one paragraph&lt;/p&gt;

&lt;p&gt;Each cycle runs through light sleep, deep sleep, and REM, then starts again. The average cycle is about 90 minutes, so a night's sleep is really a count of cycles: 4 cycles is 6 hours, 5 cycles is 7.5 hours, 6 cycles is 9 hours. A sleep calculator works backwards from your wake-up time, subtracting whole cycles, and then subtracts the time it takes you to fall asleep — about 15 minutes for most people. That's it. No sensors, no AI, just subtraction.&lt;/p&gt;

&lt;p&gt;The worked example: waking up at 6:30 AM&lt;/p&gt;

&lt;p&gt;Say you need to be up at 6:30 AM. Working backwards with 90-minute cycles and a 15-minute fall-asleep time:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;6 cycles (9 hours of sleep): asleep by 9:30 PM, so in bed by 9:15 PM&lt;/li&gt;
&lt;li&gt;5 cycles (7.5 hours): asleep by 11:00 PM, so in bed by 10:45 PM&lt;/li&gt;
&lt;li&gt;4 cycles (6 hours): asleep by 12:30 AM, so in bed by 12:15 AM&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Notice the pattern: the bedtimes are 90 minutes apart, and every one of them lands you at 6:30 AM at the end of a cycle. The same math runs forward, too. In bed at 11:00 PM, asleep around 11:15 PM, and your cycle boundaries fall at 12:45, 2:15, 3:45, 5:15, and 6:45 AM. Set the alarm for 6:45 and you get 5 full cycles; set it for 6:00 and you wake up 45 minutes into a cycle.&lt;/p&gt;

&lt;p&gt;The surprising part: 7 hours can feel worse than 6&lt;/p&gt;

&lt;p&gt;Here's the figure that makes people rethink their alarm. Seven hours of sleep is 420 minutes — that's 4 full cycles (360 minutes) plus 60 minutes into cycle 5. Sixty minutes into a cycle is roughly when you're in deep sleep, the hardest phase to wake from. So a 7-hour night can leave you groggier than a 6-hour night that ends exactly on a cycle boundary. More sleep isn't automatically better sleep; where the sleep ends matters as much as how long it lasts. That 6:00 AM alarm after a 11:15 PM sleep onset? It catches you 45 minutes into cycle 4 — also mid-cycle. Shifting it to 5:15 or 6:45, both cycle boundaries, costs nothing and can change how the whole morning feels.&lt;/p&gt;

&lt;p&gt;The code: about 30 lines&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="no"&gt;CYCLE_MINUTES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="no"&gt;FALL_ASLEEP_MINUTES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;15&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;bedtimesFor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;wakeUp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cycles&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;4&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;cycles&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;map&lt;/span&gt;&lt;span class="p"&gt;(&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="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;asleep&lt;/span&gt; &lt;span class="o"&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;wakeUp&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="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="no"&gt;CYCLE_MINUTES&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60000&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;inBed&lt;/span&gt; &lt;span class="o"&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;asleep&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="o"&gt;-&lt;/span&gt; &lt;span class="no"&gt;FALL_ASLEEP_MINUTES&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;60000&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="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;cycles&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;sleepHours&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;n&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;CYCLE_MINUTES&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;inBed&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;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;wakeUp&lt;/span&gt; &lt;span class="o"&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="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;wakeUp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setHours&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;30&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="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;for&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;t&lt;/span&gt; &lt;span class="k"&gt;of&lt;/span&gt; &lt;span class="nf"&gt;bedtimesFor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;wakeUp&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;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="sb"&gt;`${t.cycles} cycles (${t.sleepHours}h): in bed by `&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt;
    &lt;span class="n"&gt;t&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;inBed&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;toLocaleTimeString&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="n"&gt;hour&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2-digit"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;minute&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2-digit"&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;// 6 cycles (9h): in bed by 09:15 PM&lt;/span&gt;
&lt;span class="c1"&gt;// 5 cycles (7.5h): in bed by 10:45 PM&lt;/span&gt;
&lt;span class="c1"&gt;// 4 cycles (6h): in bed by 12:15 AM&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same function runs forward if you give it a bedtime instead: add the fall-asleep time, then add cycles in 90-minute steps, and you get the wake-up times that land on a boundary. The only inputs are the anchor time and the cycle count — everything else is arithmetic.&lt;/p&gt;

&lt;p&gt;Honest caveats&lt;/p&gt;

&lt;p&gt;This model is a useful approximation, not a measurement. Real sleep cycles run roughly 70 to 120 minutes, not exactly 90, and they tend to get shorter and more REM-heavy toward morning. Your fall-asleep time isn't a constant 15 minutes either — it varies with stress, caffeine, light, and the day you had. Adults generally need 7 to 9 hours, so regularly choosing 4 cycles (6 hours) because the math looks neat is a bad trade; the calculator tells you when to sleep, not how little you can get away with. And if you consistently can't fall asleep, wake up constantly, or feel exhausted despite full nights, that's a conversation with a doctor, not a JavaScript function.&lt;/p&gt;

&lt;p&gt;The point of building the calculator isn't that 90 minutes is a law of nature. It's that a tiny model — one constant, one subtraction — turns a vague "go to bed earlier" into a specific time you can actually act on. You can try the working version here: the sleep calculator (&lt;a href="https://youcancalc.com/calculators/sleep-calculator/" rel="noopener noreferrer"&gt;https://youcancalc.com/calculators/sleep-calculator/&lt;/a&gt;) on youcancalc.com does exactly this math, forward from a bedtime or backwards from a wake-up time.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>Stop hand-writing JSON Schemas: infer them from your sample payloads, in the browser</title>
      <dc:creator>Farbod F.</dc:creator>
      <pubDate>Wed, 11 Nov 2026 20:46:54 +0000</pubDate>
      <link>https://dev.to/farbodf/stop-hand-writing-json-schemas-infer-them-from-your-sample-payloads-in-the-browser-ge5</link>
      <guid>https://dev.to/farbodf/stop-hand-writing-json-schemas-infer-them-from-your-sample-payloads-in-the-browser-ge5</guid>
      <description>&lt;p&gt;Hand-writing a JSON Schema from an API response is tedious, error-prone work. The more fields a payload has, the easier it is to forget a &lt;code&gt;required&lt;/code&gt; entry or mistype a field. And the schema you write by hand is only as good as the sample you stared at while writing it.&lt;/p&gt;

&lt;p&gt;There is a faster first draft: paste sample payloads into an inference tool and let it generate the schema. I tried ToolsByUs's JSON Schema Generator — it infers a Draft 2020-12 schema from your samples and validates documents against it on the spot, all in the browser. Your sample data never leaves the tab, because the whole thing runs client-side.&lt;/p&gt;

&lt;h3&gt;
  
  
  The sample I ran through it
&lt;/h3&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="p"&gt;{&lt;/span&gt;&lt;span class="nl"&gt;"id"&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="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"taro"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"taro@example.com"&lt;/span&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;"active"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"created_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-01T09:00:00Z"&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="nl"&gt;"id"&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="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"hana"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"email"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"hana@example.com"&lt;/span&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;"inactive"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"created_at"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"2026-11-02T10:30:00Z"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nl"&gt;"nickname"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"h"&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;
  
  
  What the inference actually gets right — and one thing it doesn't
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;required detection:&lt;/strong&gt; only properties present in every sample become required. Here &lt;code&gt;id&lt;/code&gt;, &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;email&lt;/code&gt;, &lt;code&gt;status&lt;/code&gt; and &lt;code&gt;created_at&lt;/code&gt; are required; &lt;code&gt;nickname&lt;/code&gt; appears in only one of the two samples, so it stays optional. That is exactly the rule you would apply by hand, applied without fail.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;format detection:&lt;/strong&gt; &lt;code&gt;email&lt;/code&gt; is inferred as &lt;code&gt;format: email&lt;/code&gt; and &lt;code&gt;created_at&lt;/code&gt; as &lt;code&gt;format: date-time&lt;/code&gt;. UUIDs and URIs are detected the same way.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The enum surprise:&lt;/strong&gt; strings with few distinct values can become enums — but not always. The default threshold is 4, yet when I ran this sample, &lt;code&gt;status&lt;/code&gt; stayed a plain &lt;code&gt;{"type": "string"}&lt;/code&gt; despite having only two values, &lt;code&gt;active&lt;/code&gt; and &lt;code&gt;inactive&lt;/code&gt;. No enum was generated. So a small value set does not guarantee an enum; check the output rather than assuming.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Type widening:&lt;/strong&gt; when the same key holds an integer in one sample and a string in another, the inferred type widens to &lt;code&gt;["integer", "string"]&lt;/code&gt; instead of silently picking one.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Validate without leaving the page
&lt;/h3&gt;

&lt;p&gt;The round-trip validator below the generator takes a test payload and checks it against the generated schema in real time, showing which path and keyword failed on a violation. That kills the usual loop of writing a schema, opening a second tool to validate it, going back to fix it, and re-validating. One page does both halves.&lt;/p&gt;

&lt;h3&gt;
  
  
  Honest caveats
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Inference only sees the samples you give it. A field that happens to be present in every sample is treated as required even if it is optional in reality. If a field is optional, include a sample where it is missing and it drops out of &lt;code&gt;required&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The inferred schema is a starting point, not a finished contract. Read it before shipping it — especially the &lt;code&gt;required&lt;/code&gt; list and any &lt;code&gt;format&lt;/code&gt; it guessed.&lt;/li&gt;
&lt;li&gt;If all you need is TypeScript types, the same site's JSON-to-TypeScript converter is the better tool. A schema is the artefact you want when several languages need runtime validation against the same contract.&lt;/li&gt;
&lt;li&gt;Client-side means your machine does the work and your data stays local. For very large payloads that can be slower than a server — but for the hand-sized samples you actually infer schemas from, it is instant.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have API samples lying around, the first draft of your schema takes seconds. Spend the saved time on the part that matters: checking whether the inferred schema matches what your API actually promises.&lt;/p&gt;

&lt;p&gt;Try it: &lt;a href="https://toolsbyus.com/json-schema-generator" rel="noopener noreferrer"&gt;https://toolsbyus.com/json-schema-generator&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>tools</category>
      <category>json</category>
    </item>
    <item>
      <title>The BMI formula is almost 200 years old: implementing it (and its caveats) in JS</title>
      <dc:creator>Farbod F.</dc:creator>
      <pubDate>Wed, 11 Nov 2026 19:19:58 +0000</pubDate>
      <link>https://dev.to/farbodf/the-bmi-formula-is-almost-200-years-old-implementing-it-and-its-caveats-in-js-3ncf</link>
      <guid>https://dev.to/farbodf/the-bmi-formula-is-almost-200-years-old-implementing-it-and-its-caveats-in-js-3ncf</guid>
      <description>&lt;p&gt;Body mass index is one line of arithmetic:&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;function&lt;/span&gt; &lt;span class="nf"&gt;bmi&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;weightKg&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;heightM&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;weightKg&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;heightM&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;heightM&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;Adolphe Quetelet published it in 1832 — 194 years ago — as a way to describe populations, not people. It was never designed to judge an individual's health. And yet it is still the first number most health apps, insurance forms, and gym intake sheets ask for. So if you're going to implement it, implement it honestly: get the math right, and show the user where the number stops meaning anything.&lt;/p&gt;

&lt;h2&gt;
  
  
  The worked example
&lt;/h2&gt;

&lt;p&gt;Take someone 1.78 m tall weighing 80 kg:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BMI = 80 / (1.78 × 1.78) = 80 / 3.1684 = 25.2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The WHO bands are: under 18.5 underweight, 18.5–24.9 healthy, 25.0–29.9 overweight, 30 and above obese. So 25.2 lands just inside "overweight" — by 0.2 of a point.&lt;/p&gt;

&lt;p&gt;Here's the part most implementations never show the user. At 1.78 m, the healthy/overweight boundary sits at:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;25.0 × 3.1684 = 79.2 kg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;while the top of "healthy" is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;24.9 × 3.1684 = 78.9 kg
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;The gap between "healthy" and "overweight" at this height is 317 grams — about one large glass of water.&lt;/strong&gt; A single meal, a full bladder, or weighing yourself in the evening instead of the morning can move you across a category boundary that sounds like a medical verdict. Any UI that prints "overweight" in red without showing the distance to the boundary is overstating its own precision.&lt;/p&gt;

&lt;p&gt;A second example shows the opposite failure. A 1.80 m rugby player at 100 kg:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;BMI = 100 / (1.80 × 1.80) = 100 / 3.24 = 30.9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's "obese" by the table — for someone who may carry very little body fat. BMI cannot see muscle. It also cannot see age, sex, or where fat is carried, which is why clinicians pair it with waist circumference or waist-to-height ratio rather than using it alone.&lt;/p&gt;

&lt;h2&gt;
  
  
  The implementation details that matter
&lt;/h2&gt;

&lt;p&gt;Three things to get right in code:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Validate the inputs.&lt;/strong&gt; Heights in centimetres are the classic bug — a user types 178 and your function returns 0.0025. Guard the plausible range (say 0.5–2.5 m, 20–300 kg) and reject the rest with a clear message.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Round for display, never for logic.&lt;/strong&gt; &lt;code&gt;25.249&lt;/code&gt; should display as 25.2, but classify on the unrounded value — rounding 24.96 up to 25.0 and then calling it overweight is a classification error, not a display choice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Show the bands, not just the verdict.&lt;/strong&gt; The useful output is the number plus where it sits: "25.2 — 0.3 above the healthy range, 4.8 below obese." That framing is honest about how close to a boundary the person is, and it survives the 317-gram problem above.&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="no"&gt;BANDS&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="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;18.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Underweight"&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;max&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;25.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Healthy weight"&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;max&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;30.0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Overweight"&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;max&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;Infinity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;label&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Obese"&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="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;classify&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;value&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="no"&gt;BANDS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;b&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;value&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;max&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;label&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;h2&gt;
  
  
  Honest caveats
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;BMI was built for populations. On an individual it is a screening signal, not a diagnosis — it says "worth a closer look", never "you are unhealthy".&lt;/li&gt;
&lt;li&gt;It misclassifies in both directions: muscular people score too high, older adults with muscle loss can score "healthy" while carrying risky visceral fat.&lt;/li&gt;
&lt;li&gt;The boundaries are conventions, not cliffs. Nothing biological changes at 25.0 versus 24.9 — the 317-gram example above proves how arbitrary the line is at the individual level.&lt;/li&gt;
&lt;li&gt;For children and teenagers, adult bands don't apply at all; paediatric BMI is read off age-and-sex percentile charts.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to check your own numbers — including the distance to the nearest band boundary — the calculator I built for this does exactly that, with the bands shown alongside the result: &lt;a href="https://youcancalc.com/calculators/bmi-calculator/" rel="noopener noreferrer"&gt;BMI calculator&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The formula is 194 years old and one line long. The hard part was never the arithmetic. It's deciding what the number is allowed to claim — and building the UI so it claims no more than that.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
    </item>
    <item>
      <title>Compress to exactly 200 KB: how exact-target image compression works in your browser</title>
      <dc:creator>Farbod F.</dc:creator>
      <pubDate>Sat, 07 Nov 2026 21:33:23 +0000</pubDate>
      <link>https://dev.to/farbodf/compress-to-exactly-200-kb-how-exact-target-image-compression-works-in-your-browser-4k8p</link>
      <guid>https://dev.to/farbodf/compress-to-exactly-200-kb-how-exact-target-image-compression-works-in-your-browser-4k8p</guid>
      <description>&lt;p&gt;Most image compressors give you a quality slider and wish you luck. You pick 80%, export, check the size, and repeat until the file fits under the limit. ToolsByUs Compress Image does it the other way round: you state the target size, and the tool finds the settings that land on it.&lt;/p&gt;

&lt;p&gt;The whole thing runs in the browser. The file's contents never leave the tab — there is no upload step at all.&lt;/p&gt;

&lt;h2&gt;
  
  
  The worked example
&lt;/h2&gt;

&lt;p&gt;I took a 4032x3024 JPEG photo and asked the tool for exactly 200 KB:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Original: 415 KB (424,449 bytes)&lt;/li&gt;
&lt;li&gt;Target: 200 KB&lt;/li&gt;
&lt;li&gt;Result: 193 KB — 46% of the original, a 54% reduction&lt;/li&gt;
&lt;li&gt;What changed: the dimensions stayed at 4032x3024, the format stayed JPG, and no max-width resize was applied. In Target size mode, with "Under 200 KB" and Format set to "Same", the tool binary-searched the quality to land under the target, finishing in 1.3s.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The preview the tool shows is the real encoded result, not a simulation — what you see is the file you download.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why "exact target" is a different problem from "quality 80%"
&lt;/h2&gt;

&lt;p&gt;A quality slider controls one variable; file size is the outcome of quality, dimensions, format, and image content together. Hitting an exact size means searching that space: try settings, encode, measure, adjust, encode again. Doing that search locally, in the browser, is the interesting engineering part — every encode is real work on your machine, and the tool has to converge without making you wait through dozens of visible attempts.&lt;/p&gt;

&lt;p&gt;That is also why the preview matters. If the tool only estimated the size, you would still be guessing. Showing the actual encoded output means the number on screen and the file you download agree.&lt;/p&gt;

&lt;h2&gt;
  
  
  The numbers that surprised me
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;ToolsByUs ships 135 free tools, all client-side, in 6 languages — the compressor is one tool in a suite built on the same idea: the file never leaves the browser.&lt;/li&gt;
&lt;li&gt;The compressor handles JPG, PNG, and WebP, by quality or by exact target size.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Honest caveats
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Exact-target compression is a trade-off, not magic. A photo with fine detail (foliage, crowds) will lose visible quality faster than a flat graphic when squeezed to the same size. If the result looks bad, the honest fix is a bigger target or smaller dimensions, not another pass at the same size.&lt;/li&gt;
&lt;li&gt;Everything runs in the browser tab, so a very large image depends on your device's memory and CPU. That is the price of never uploading: your machine does the work a server would have done.&lt;/li&gt;
&lt;li&gt;"Your file's contents never leave the browser" is a narrower claim than "fully anonymous" — the site's analytics is configured separately. Keep the two apart.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have ever re-exported the same image four times to get under an upload limit, stating the target size up front is the saner workflow. One tool that does it, free, with no upload: &lt;a href="https://toolsbyus.com" rel="noopener noreferrer"&gt;https://toolsbyus.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>privacy</category>
      <category>javascript</category>
      <category>tools</category>
    </item>
    <item>
      <title>Modeling solar payback: the variables that matter and the ones that don't</title>
      <dc:creator>Farbod F.</dc:creator>
      <pubDate>Sat, 07 Nov 2026 19:19:52 +0000</pubDate>
      <link>https://dev.to/farbodf/modeling-solar-payback-the-variables-that-matter-and-the-ones-that-dont-1hem</link>
      <guid>https://dev.to/farbodf/modeling-solar-payback-the-variables-that-matter-and-the-ones-that-dont-1hem</guid>
      <description>&lt;h1&gt;
  
  
  Modeling solar payback: the variables that matter and the ones that don't
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;A 6 kW rooftop system at $3 a watt pays for itself in 8.8 years at average US electricity prices — but 5.0 years in California and 15.0 years where power is cheap. Same panels, same sun, triple the payback range. The panels are not the variable. Your electricity price is.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Solar payback is usually sold as a single number — "pays for itself in seven years!" — as if it were a property of the panels. It is not. Payback is a ratio between what the system costs and what each kilowatt-hour it produces is worth to you, and both halves of that ratio vary wildly by house. The model itself is small enough to fit in one function. The interesting part is which inputs move the answer and which barely touch it.&lt;/p&gt;

&lt;h2&gt;
  
  
  The model
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;paybackYears&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="nx"&gt;systemKw&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;costPerWatt&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;taxCredit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;kwhPerKw&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;electricityPrice&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="nx"&gt;grossCost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;systemKw&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1000&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;costPerWatt&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;netCost&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;grossCost&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nx"&gt;taxCredit&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;annualProduction&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;systemKw&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;kwhPerKw&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// kWh per year&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;annualSaving&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;annualProduction&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="nx"&gt;electricityPrice&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;netCost&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="nx"&gt;annualSaving&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;Four inputs, one division. But they do not matter equally — and the one most installers talk about least is the one that matters most.&lt;/p&gt;

&lt;h2&gt;
  
  
  Worked example: 6 kW system, $3/W, 30% tax credit
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Gross cost: 6,000 W × $3.00 = &lt;strong&gt;$18,000&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;After the 30% federal tax credit: $18,000 × 0.70 = &lt;strong&gt;$12,600 net&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Annual production: 6 kW × 1,400 kWh per kW = &lt;strong&gt;8,400 kWh a year&lt;/strong&gt; (a reasonable US average; sunnier states do better, cloudier ones worse)&lt;/li&gt;
&lt;li&gt;Annual saving at $0.17 per kWh: 8,400 × $0.17 = &lt;strong&gt;$1,428 a year&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;Simple payback: $12,600 / $1,428 = &lt;strong&gt;8.82 years&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Electricity prices rise, and panels degrade slightly, so the real payback is a bit shorter: with prices rising 3% a year and production falling 0.5% a year, cumulative savings pass $12,600 about &lt;strong&gt;8.1 years&lt;/strong&gt; in. Over a 25-year panel life the same assumptions give roughly &lt;strong&gt;$48,683 in total savings&lt;/strong&gt; against the $12,600 net cost — about &lt;strong&gt;$36,083 ahead&lt;/strong&gt; after payback. The panels keep producing long after they have paid for themselves, and that tail is where most of the money is.&lt;/p&gt;

&lt;h2&gt;
  
  
  The variable that matters: your electricity price
&lt;/h2&gt;

&lt;p&gt;Hold everything else fixed and change only the price you pay per kilowatt-hour:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;At &lt;strong&gt;$0.10/kWh&lt;/strong&gt;: $840 a year saved → payback &lt;strong&gt;15.0 years&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;At &lt;strong&gt;$0.17/kWh&lt;/strong&gt;: $1,428 a year saved → payback &lt;strong&gt;8.8 years&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;At &lt;strong&gt;$0.25/kWh&lt;/strong&gt;: $2,100 a year saved → payback &lt;strong&gt;6.0 years&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;At &lt;strong&gt;$0.30/kWh&lt;/strong&gt;: $2,520 a year saved → payback &lt;strong&gt;5.0 years&lt;/strong&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Same system, same roof, same sun. The payback triples between cheap-power and expensive-power regions. This is why national payback averages are nearly useless: a system that is a no-brainer in California can be a 15-year slog two states over, and no change to the panels fixes that.&lt;/p&gt;

&lt;h2&gt;
  
  
  The variables that barely matter
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;System size.&lt;/strong&gt; Double the system to 12 kW and both the cost and the savings double — payback stays at 8.8 years. Size decides how much money you save in total, not how fast you break even. (The exception is if a bigger system produces more than you use and the surplus is only worth a low export rate — then the marginal panels pay back slowly. Size matters at the edge, not in the middle.)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Panel orientation.&lt;/strong&gt; Point the array east-west instead of due south and production drops roughly 12%: 8,400 kWh becomes about 7,392 kWh, savings fall to about $1,257 a year, and payback stretches from 8.8 to &lt;strong&gt;10.0 years&lt;/strong&gt;. Noticeable, but not decisive — a bad roof direction costs you a year, not a decade. A cheap electricity tariff costs you six.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cost per watt.&lt;/strong&gt; This one does matter, but less than people think. At $2.50/W the net cost is $10,500 and payback is &lt;strong&gt;7.4 years&lt;/strong&gt;; at $3.50/W the net cost is $14,700 and payback is &lt;strong&gt;10.3 years&lt;/strong&gt;. Shopping around for a better installer quote is worth roughly three years of payback — significant, and worth doing, but it still cannot rescue a system in a cheap-electricity region.&lt;/p&gt;

&lt;h2&gt;
  
  
  The figure that surprised me: the tax credit is worth more than a year of sunshine
&lt;/h2&gt;

&lt;p&gt;The 30% credit takes the system from $18,000 to $12,600 — a $5,400 discount that cuts payback from 12.6 years to 8.8 years, nearly four years. Compare that with squeezing 12% more production out of a perfect south-facing roof: that saves about one year. Policy moves the answer more than physics does. Anyone modeling payback without the credit — or after it expires — is modeling a different purchase.&lt;/p&gt;

&lt;h2&gt;
  
  
  Honest caveats
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;This model assumes every kilowatt-hour you produce offsets a kilowatt-hour you would have bought at full retail price.&lt;/strong&gt; If your utility pays a low export rate for surplus power you send to the grid, the marginal kilowatt-hours are worth far less. Homes that use most of their solar during the day get the full $0.17; homes that export half of it do not.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Production varies by location and roof.&lt;/strong&gt; 1,400 kWh per kW per year is a US average. Arizona beats it, Seattle does not, and shade from a single tree can cost more than a wrong-facing roof. Get a site-specific production estimate before trusting any payback number.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Electricity price escalation is assumed, not guaranteed.&lt;/strong&gt; 3% a year is a reasonable planning figure, but prices can flatten for years. At 0% escalation the payback is the simple 8.8 years, not 8.1 — the conclusion survives, the exact year does not.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;This model excludes financing, inverter replacement, and maintenance.&lt;/strong&gt; Paying cash is assumed. A loan adds interest that stretches payback; an inverter replacement around year 12–15 costs roughly $1,000–$2,000 and pushes the 25-year profit down, not the payback year much. A battery is a separate purchase with its own (usually much longer) payback — do not fold it into the panel math.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The 30% federal tax credit is a US policy figure.&lt;/strong&gt; It phases down on a schedule and does not exist everywhere. Check what applies in your country and year before running these numbers.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Run your own numbers
&lt;/h2&gt;

&lt;p&gt;Put in your system size, your installer's price per watt, your electricity rate, and your roof's production — and see which variable actually decides your payback:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://youcancalc.com/calculators/solar-panel-payback-calculator/" rel="noopener noreferrer"&gt;Solar panel payback calculator&lt;/a&gt;&lt;/strong&gt; — free, no signup, runs entirely in your browser.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;The panels are the constant. Your electricity price, your tax credit, and how much of the power you actually use are the variables — and one of them matters three times as much as the rest.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
