✂️

Code Snippets

Free
today
0

Collect the bits of code you use often, grouped by use case. Add a short note so each one is ready to copy and use.

Remove duplicates from an array

Drop duplicate values in JavaScript. Using Set is the easiest way.

const unique = [...new Set(items)];

Format a date as YYYY-MM-DD

Use this when you want to avoid timezone drift.

const ymd = new Date().toLocaleDateString("sv-SE");

Wait for a set number of milliseconds

Handy for async test delays or retry intervals.

const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); await sleep(1000);

Check whether an object is empty

Test whether an object has any contents.

const isEmpty = (obj) => Object.keys(obj).length === 0;

List files in a folder

Pull file names out of a folder in Python.

from pathlib import Path files = [p.name for p in Path("./data").glob("*.csv")]

Tips for using this

  • As you add more languages and use cases, split them up with headings
  • Note the date you verified it and a link to the source for peace of mind
  • For anything that does not work, keep the cause alongside it for next time

Comments

0
0
0