Skip to content

Instantly share code, notes, and snippets.

View adamziel's full-sized avatar
👋

Adam Zieliński adamziel

👋
View GitHub Profile
@adamziel
adamziel / gist:a45b5906700425aab0336a6f1b3ce175
Last active July 14, 2021 10:51
Trigger the `Block moves to "Inactive widgets" after saving` issue in Gutenberg
// This Gist makes it easy to reproduce https://github.com/WordPress/gutenberg/issues/33335
// Just go to /wp-admin/widgets.php and paste this entire script into your devtools
(function main() {
const r1 = (existingBlockIds) => {
console.log( 'existingBlockIds', existingBlockIds );
return apiRequest( "/index.php?rest_route=%2Fbatch%2Fv1&_locale=user", {
"data": {
"validation": "require-all-validate", "requests": [
{ "path": "/wp/v2/widgets","body": {"id_base": "block","instance": { "raw": { "content": "<!-- wp:legacy-widget /-->" } },"sidebar": "sidebar-1"}, "method": "POST" },
@adamziel
adamziel / entities.mjs
Last active February 9, 2022 12:43
Compile WordPress API JSON Schema to TypeScript type definitions for entity records
const __ = (x) => x;
export const defaultEntities = [
{
label: __( 'Base' ),
name: '__unstableBase',
kind: 'root',
baseURL: '/',
},
{

Extending

You can extend the entity record definitions using TypeScript's declaration merging.

For example, if you're building a plugin that displays a number of views of each comment, you can add a new numberOfViews field to the Comment type like this:

// In core-data
export namespace WPBaseTypes {
@adamziel
adamziel / fun.php
Last active January 14, 2023 11:02
Pack HTML entities trie into a string
<?php
$character_references = array(
"AE" => array( "names" => array( "lig;", "lig" ), "refs" => array( "Æ", "Æ" ) ),
"AM" => array( "names" => array( "P;", "P" ), "refs" => array( "&", "&" ) ),
"Aa" => array( "names" => array( "cute;", "cute" ), "refs" => array( "Á", "Á" ) ),
"Ab" => array( "names" => array( "reve;" ), "refs" => array( "Ă" ) ),
"Ac" => array( "names" => array( "irc;", "irc", "y;" ), "refs" => array( "Â", "Â", "А" ) ),
"Af" => array( "names" => array( "r;" ), "refs" => array( "𝔄" ) ),
"Ag" => array( "names" => array( "rave;", "rave" ), "refs" => array( "À", "À" ) ),
@adamziel
adamziel / 1.translate.php
Last active February 7, 2023 17:50
POC: CREATE TABLE translation MySQL -> SQLite with SqlParser
<?php
// require autoload
use PhpMyAdmin\SqlParser\Context;
use PhpMyAdmin\SqlParser\Components\CreateDefinition;
use PhpMyAdmin\SqlParser\Components\DataType;
use PhpMyAdmin\SqlParser\Statements\CreateStatement;
require_once __DIR__.'/../vendor/autoload.php';
@adamziel
adamziel / mysql-to-sqlite-more-queries.php
Last active February 8, 2023 12:28
V2 of MySQL->SQLite compat layer for WordPress
<?php
// require autoload
use PhpMyAdmin\SqlParser\Context;
use PhpMyAdmin\SqlParser\Components\CreateDefinition;
use PhpMyAdmin\SqlParser\Components\DataType;
use PhpMyAdmin\SqlParser\Token;
use PhpMyAdmin\SqlParser\Statements\CreateStatement;
use PhpMyAdmin\SqlParser\Statements\SelectStatement;
@adamziel
adamziel / a_related_issue.md
Last active March 22, 2023 23:30
Lightweight Gutenberg block esbuild setup
@adamziel
adamziel / 1. Results.md
Last active April 15, 2023 11:06
Measure performance of php.wasm

Naive benchmark of php.wasm performance

I wrote a simple script that measures how many json_encode("Hello World") it can do in 5 seconds and these are the results:

With php test.php:

Serialized 'Hello World' to JSON 63862450 times in 5 seconds.

With PHP=8.1 npx @php-wasm/cli test.php:

@adamziel
adamziel / glotpress.ts
Last active April 21, 2023 09:17
GlotPress Playground as a blueprint
import { phpVars } from '@php-wasm/common';
import { ProgressTracker } from '@php-wasm/progress';
import {
PlaygroundClient,
runBlueprint,
StepDefinition,
Blueprint,
connectPlayground,
} from '@wp-playground/client';
const query = new URL(document.location.href).searchParams;
@adamziel
adamziel / Dockerfile
Last active July 3, 2023 11:09
Building PHP CLI to WebAssembly
# Emscripten has an official image, but it's super slow on Apple Silicon.
# Ubuntu is much faster:
FROM ubuntu:lunar as emscripten
SHELL ["/bin/bash", "-c"]
WORKDIR /root
# Install Emscripten and build dependencies {{{
RUN apt-get update && \
apt-get --no-install-recommends -y install \
build-essential automake autoconf libtool pkgconf flex make re2c gdb git \