Skip to content

Instantly share code, notes, and snippets.

View adamziel's full-sized avatar
👋

Adam Zieliński adamziel

👋
View GitHub Profile
@adamziel
adamziel / preprocess-wxr.php
Created June 6, 2024 15:02
A CLI utility to download all the WXR assets and rewrite their URLs
<?php
/**
* Rewrites URLs in a WXR file while keeping track of the URLs found.
*
* This is a huge deal! It unlocks fast, streamed, resumable, fault-tolerant
* WordPress data migrations through WXR files AND directly between sites.
*
* In particular, this script:
*
* * Lists all the URLs found in the XML document
@adamziel
adamziel / wxr-rewriter.php
Last active June 6, 2024 14:39
A foundation for a beter WXR importer
<?php
/**
* Rewrites URLs in a WXR file while keeping track of the URLs found.
*
* This is a huge deal! It unlocks fast, streamed, resumable, fault-tolerant
* WordPress data migrations through WXR files AND directly between sites.
*
* In particular, this script:
*
* * Lists all the URLs found in the XML document
@adamziel
adamziel / playground-post-export-processor.php
Last active March 30, 2024 22:30
Playground docs contribution plugin
<?php
/**
* A copy of the WP_Interactivity_API_Directives_Processor class
* from the Gutenberg plugin.
*
* @package WordPress
* @subpackage Interactivity API
* @since 6.5.0
*/
@adamziel
adamziel / blueprint.json
Created March 23, 2024 00:05
Log in as a user with an editor role
{
"landingPage": "/wp-admin/",
"steps": [
{
"step": "runPHP",
"code": "<?php require '/wordpress/wp-load.php'; $user_id = wp_create_user('myuser', 'mypass', 'myuser@localhost'); (new WP_User($user_id))->set_role('editor');"
},
{
"step": "login",
"username": "myuser",
<?php
function download_url_stream_socket_client( $url ) {
$stream = stream_socket_client(
$url,
$errno,
$errstr,
30,
STREAM_CLIENT_CONNECT | STREAM_CLIENT_ASYNC_CONNECT
);
@adamziel
adamziel / main.c
Created December 13, 2023 11:52
WP HTML Tag Processor, but written in C
/*
* This is a fun exploration I've done of porting the Tag Processor API over to C as a PHP extension.
* For now this is just a part of the parse_next_attribute() function.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
@adamziel
adamziel / github-integration.html
Created October 25, 2023 22:08
Playground integration with GitHub for storage and workflows
<!DOCTYPE html>
<html>
<head>
<script type="module">
const TOKEN_KEY = 'githubToken';
// OAUTH FLOW {{{
// If there is a code in the URL, store it in localStorage
const urlParams = new URLSearchParams(window.location.search);
const code = urlParams.get('code');
@adamziel
adamziel / build.sh
Created October 10, 2023 11:10
Working dlopen example in Emscripten
#!/bin/bash
emcc ./module.c -sSIDE_MODULE -o module.o
emcc ./main.c \
-lnodefs.js \
-o ./main.js \
-sMAIN_MODULE \
-sEXPORTED_FUNCTIONS='["_main","ccall", "UTF8ToString", "lengthBytesUTF8", "FS"]' \
-sEXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "UTF8ToString", "lengthBytesUTF8", "FS"]' \
-sFORCE_FILESYSTEM=1
@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 \
@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;