unslopkit

Components / Code blocks

Avoid and prefer

Two short snippets for one rule: the version to avoid with the problem underlined, and the version to use instead, each with the reason in a line. For style guides.

Filter a day with a rangeMarina bookings · Postgres

AvoidThe function hides the column from its index.
SELECT id, berth, starts_at
FROM bookings
WHERE date(starts_at) = '2026-12-05';
PreferA plain range the index can walk.
SELECT id, berth, starts_at
FROM bookings
WHERE starts_at >= '2026-12-05'
  AND starts_at <  '2026-12-06';
Drawn in your kit, Plain.Change the look

The code

Plain HTML and CSS on your kit's variables. Put it next to tokens/variables.css from your kit's files and it draws in your look.

<div class="ukc-code-do-dont">
<div class="dd">
  <p class="cap"><b>Filter a day with a range</b><span>Marina bookings · Postgres</span></p>
  <div class="pair">
    <figure class="no">
      <figcaption><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M6 6l12 12M18 6L6 18"/></svg><b>Avoid</b><span>The function hides the column from its index.</span></figcaption>
      <pre class="src"><code><span class="l"><span class="k">SELECT</span> id, berth, starts_at</span>
<span class="l"><span class="k">FROM</span> bookings</span>
<span class="l"><span class="k">WHERE</span> <span class="bad"><span class="f">date</span>(starts_at)</span> = <span class="s">'2026-12-05'</span>;</span></code></pre>
    </figure>
    <figure class="yes">
      <figcaption><svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M5 12.5l4.5 4.5L19 7.5"/></svg><b>Prefer</b><span>A plain range the index can walk.</span></figcaption>
      <pre class="src"><code><span class="l"><span class="k">SELECT</span> id, berth, starts_at</span>
<span class="l"><span class="k">FROM</span> bookings</span>
<span class="l"><span class="k">WHERE</span> starts_at &gt;= <span class="s">'2026-12-05'</span></span>
<span class="l">  <span class="k">AND</span> starts_at &lt;  <span class="s">'2026-12-06'</span>;</span></code></pre>
    </figure>
  </div>
</div>
</div>

More code blocks

All 24
  • Git, the five you use daily

    • git switch -c fix/late-feesStart a branch and move onto it
    • git add -pStage your changes one hunk at a time
    • git commit --amend --no-editFold what is staged into the last commit
    • git stash push -m wip-feesPark unfinished work under a name
    • git log --oneline -5See the last five commits, one line each

    Swap fix/late-fees and wip-fees for your own names.

    Command cheat sheet

  • src/pricing/ticket.ts 86% lines8 of 10 branches
    18×export function ticketPrice(age: number, member: boolean) {
    18×  if (age < 5) return 0;
    15×  if (member) {
    6×    return age < 16 ? 4 : 9;1 of 2 branches
      }
    9×  if (age >= 65) {never true
    0×    return 8;never run
      }
    9×  return age < 16 ? 6 : 12;
    }
    • Ran
    • Some branches
    • Never ran

    Coverage gutter

  • import { Halden } from "@halden/sdk";
     
    // Reads HALDEN_KEY from your environment
    const halden = new Halden();
    const job = await halden.jobs.get("JS-2207");
    const invoice = await job.invoice();
    await invoice.send({ to: job.client });
    from halden import Halden
     
    # Reads HALDEN_KEY from your environment
    halden = Halden()
    job = halden.jobs.get("JS-2207")
    invoice = job.invoice()
    invoice.send(to=job.client)
    # The same call, straight to the API
    curl api.halden.example/v2/invoices \
      -H "Authorization: Bearer $HALDEN_KEY" \
      -d job=JS-2207 \
      -d send=true
    $ npx tsx send-invoice.ts
    ✓ Drafted INV-0418 from 22.5 h and 3 receipts
    ✓ Sent to Reyes Framing · $2,140.00
    $ 

    Snippet with terminal

  • Install with
    npm install @halden/sdkpnpm add @halden/sdkyarn add @halden/sdk

    v3.2.018 kB gzippedNode 18 and up

    Install command

  • halden sync~/crews/reyes
    $ halden sync --since monday
    Syncing 38 job sheets for Reyes Framing
    31/38
    ✓JS-2207Alder St refit22.5 h
    ✓JS-2211Garage roof, Pier Ln14.0 h
    !JS-2214Bathroom, Mill Lnno sign-off
    ✗JS-2216Back deck rebuildupload failed
     Uploading receipts, 4 of 9

    Terminal mid-run

  • src/totals.ts +4−1
    @@ -12,3 +12,5 @@ function lineTotal
     export function lineTotal(l: Line) {
    −  return l.qty * l.rate * (1 + TAX);
    +  const net = round(l.qty * l.rate);
    +  const tax = round(net * l.taxRate);
    +  return { net, tax, total: net + tax };
     }
    @@ -24,2 +26,3 @@
     export const round = (n: number) =>
    +  // To the cent, half away from zero
       Math.round(n * 100) / 100;

    Unified diff