Skip to content

Instantly share code, notes, and snippets.

View mcsf's full-sized avatar

Miguel Fonseca mcsf

View GitHub Profile
@mcsf
mcsf / bisect-gutenberg-commit.sh
Last active April 5, 2024 07:54
A git-bisect script for WordPress/gutenberg. Fetch a commit's corresponding plugin ZIP file if available (to avoid running a lengthy build) and launch a fresh WP test instance.
#!/bin/sh
# Accept Git revision as first argument, otherwise default to HEAD
if ! COMMIT=$(git rev-parse "${1-HEAD}"); then
exit 255 # Abort bisection
fi
if ! gh --version >/dev/null 2>&1; then
echo "error: 'gh' must be installed'"
exit 255 # Abort bisection
@mcsf
mcsf / _deps-alt.sh
Last active July 30, 2023 11:16
Find circular dependencies in Gutenberg packages
#!/bin/sh
# Alternative implementation with JQ instead of AWK
find packages -depth 2 -name 'package.json' -print0 \
| xargs -0 jq -r '
.dependencies // {}
| keys[]
| select(contains("@wordpress/"))
| sub("@wordpress/"; "")
@mcsf
mcsf / super-basic-json-templates.js
Last active September 3, 2021 09:43
A very simple HTM-based prototype to generate Gutenberg block code. See https://github.com/youknowriad/blocky for the real deal.
const htm = require('htm')
const h = (type, props, ...children) => ({type, props, children})
const html = htm.bind(h)
const API = {
"wp.rich": "wp.blockEditor.RichText",
"wp.plain": "wp.blockEditor.PlainText",
}
const toComponent = type =>
/**
* Map a function over an array, but only return a new array object if the
* application of the function to some value isn't identical to the value.
*
* @example
* xs !== xs.map(x => x)
* xs === lazyMap(xs, x => x)
*
* @param {Array} xs Array to be mapped over.
* @param {Function} f Function to map over array.
@mcsf
mcsf / checksum
Last active July 21, 2021 10:57
Advent of Code 2019, day 08
#!/usr/bin/env awk -f
{
delete counts
for (i = 1; i <= NF; i++) counts[$i]++
if (! min || counts[0] < min) {
min = counts[0]
result = counts[1] * counts[2]
}
}
@mcsf
mcsf / aoc05.pl
Created April 13, 2021 19:35
Messing with Perl
#!/usr/bin/perl -l
use strict;
use warnings;
# Solution to https://adventofcode.com/2020/day/5
my @seats = ();
# Collect seat IDs by parsing binary sequences
while (<>) {
@mcsf
mcsf / aoc-2020-20.rkt
Last active January 24, 2021 19:20
A solution to challenge #20 of Advent of Code's 2020 edition
#lang racket
; SOLUTION TO CHALLENGE #20 OF ADVENT OF CODE'S 2020 EDITION
;
; https://adventofcode.com/2020/day/20
(define (main (filename "sample"))
(define tiles (read-tiles filename))
(define part-1 (apply * (corner-tiles tiles)))
(define part-2 (sea-roughness (tiles->string tiles)))
#!/bin/bash
# search term> i
# (partial-name-match) image
# (partial-name-match) instagram
# (partial-keyword-match) gallery
# search term> ig
# (exact-keyword-match) instagram
# search term> im
# (partial-name-match) image
# Invoke with
#
# awk -f script.awk -v term=li blocktypes.tsv
#
# With blocktypes.tsv:
#
# list List ul,ol
# revue Revue list
# paragraph Paragraph text
# image Image image,picture
@mcsf
mcsf / x.sh
Last active August 18, 2020 11:03
Tasks with `x` and `o` (Bash)
#!/bin/bash
CMD=$(basename "$0")
CONF="$HOME/.x.conf"
# shellcheck disable=1090
[ -f "$CONF" ] && source "$CONF"
X_BASE=${X_BASE:-$HOME/Desktop}
X_LOG=${X_LOG:-$X_BASE/log.txt}
X_ARCHIVE_TEMPLATE=${X_ARCHIVE_TEMPLATE:-+$X_BASE/tasks-%Y-%m-%d.txt}