Skip to content

Instantly share code, notes, and snippets.

@delucis
delucis / astro-themes-without-tailwind.js
Created November 5, 2024 15:34
Find themes in the Astro themes catalogue that maybe don’t use Tailwind
// Fetch all themes from the Astro theme API.
const allThemes = await fetch('https://portal.astro.build/api/themes').then((res) => res.json());
// Fetch all themes tagged as using Tailwind from the Astro theme API.
const tailwindThemes = await fetch(
'https://portal.astro.build/api/themes?technology%5B%5D=tailwind'
).then((res) => res.json());
// Filter out themes using Tailwind from the list of all themes.
const themesWithoutTailwind = allThemes.filter(
(theme) =>
// Check that Tailwind isn’t mentioned in the theme’s description or body.
@delucis
delucis / store.mjs
Last active April 12, 2023 21:00
Simple observable store
/**
* Simple observable value store.
* @template {any} T
* @param {T | Promise<T>} initial
*/
export function Store(initial) {
/** @type {Set<(newValue: T) => void>} */
const subscribers = new Set();
const store = { value: Promise.resolve(initial) };
return {
@delucis
delucis / README.md
Created December 2, 2022 23:45
Migrate Astro-Flavored Markdown files to MDX

This script is a quick way to migrate existing Astro-flavoured Markdown pages in an Astro project to MDX pages.

It does the following:

  1. Loads all *.md files in your src/pages/ directory
  2. Parses each page’s frontmatter
  3. Moves the contents of setup in frontmatter into the main file body as required for imports in MDX
  4. Writes the updated contents of each page to the same location but as .mdx instead of .md
  5. Deletes the original .md file
@delucis
delucis / getAvailableMoves.js
Last active January 2, 2022 15:29
Get a list of moves available to a specific player using boardgame.io
/**
* Get a list of the moves that are currently available to a specific player.
*
* @param {import("boardgame.io").Game} game boardgame.io game object
* @param {import("boardgame.io").Ctx} ctx current game context object
* @param {import("boardgame.io").PlayerID} playerID the ID of the player to get moves for
* @returns {string[]} an array of move names
*
* @example
* const game = {
@delucis
delucis / bevel-plugin.js
Created March 26, 2021 17:04
TailwindCSS Bevelled Corners Plugin
const plugin = require('tailwindcss/plugin');
const BevelPlugin = plugin(function bevelPlugin({ addUtilities, e }) {
const base = 0.5;
const absoluteSizes = Object.entries({
md: 1.5,
lg: 2,
xl: 3,
'2xl': 4,
@delucis
delucis / README.md
Last active April 21, 2022 12:24
Extending boardgame.io storage connectors

You can extend a boardgame.io storage adapter to add custom functionality.

This example wraps the original setState method to accomplish some other task when the game is over — in this case posting the game logs elsewhere via a hypothetical dumpEndOfGameLog function.

(The example uses the FlatFile storage class, but should work with any other boardgame.io storage class.)

@delucis
delucis / deleteScrobbles.js
Last active July 27, 2020 10:49
Programmatically delete scrobbles from a Last.fm library page
/**
* Delete all (or some of) the scrobbles on a Last.fm library page
* (e.g. https://www.last.fm/user/USERNAME/library)
*
* @param {Number} [count=0] Number of scrobbles on page to delete
* @param {Number} [start=0] Index to start deleting from
*
* @example
* // delete first 20 scrobbles on page
* deleteScrobbles(20)
@delucis
delucis / async-loop.js
Created November 13, 2017 15:31
Asynchronous, parallel loops ➰➰➰
// ES7 with async/await and Promise.all
async function loopIt(array) {
await Promise.all(array.map(async member => {
// asyncStuff() will be called in parallel for all array members
let result = await asyncStuff(member)
}))
}
@delucis
delucis / copy-file-sha.sh
Created August 16, 2017 17:31
Copy a sha256 hash of a file to the clipboard
shasum -a 256 name-of-your-file | awk '{printf $1}' | pbcopy
#!/bin/bash
# Check all required CLIs are available
dependencies=( pdftoppm convert )
for dependency in "${dependencies[@]}"; do
command -v $dependency >/dev/null 2>&1 || { echo >&2 "‘$dependency’ command is required but it’s not installed. Aborting."; exit 1; }
done
# Create a directory to hold extracted images
if [ ! -d "images" ]; then