Skip to content

Instantly share code, notes, and snippets.

View mcsf's full-sized avatar

Miguel Fonseca mcsf

View GitHub Profile
<?php
// Two sample posts: one with lots of blocks, including groups; another with
// just a brief paragraph mentioning the word "paragraph".
$sample1 = "<!-- wp:paragraph -->\n<p>This is an example page. It's different from a blog post because it will stay in one place and will show up in your site navigation (in most themes). Most people start with an About page that introduces them to potential site visitors. It might say something like this:</p>\n<!-- /wp:paragraph -->\n\n<!-- wp:group {\"layout\":{\"type\":\"flex\",\"flexWrap\":\"nowrap\"}} -->\n<div class=\"wp-block-group\"><!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><!-- wp:paragraph -->\n<p>Hi there! I'm a bike messenger by day, aspiring actor by night, and this is my website. I live in Los Angeles, have a great dog named Jack, and I like piña coladas. (And gettin' caught in the rain.)</p>\n<!-- /wp:paragraph --></blockquote>\n<!-- /wp:quote -->\n\n<!-- wp:quote -->\n<blockquote class=\"wp-block-quote\"><!-- wp:paragraph -->\n<p>The XYZ D
@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