Skip to content

Instantly share code, notes, and snippets.

View adamziel's full-sized avatar
👋

Adam Zieliński adamziel

👋
View GitHub Profile
@adamziel
adamziel / sparse-checkout-in-js.js
Created June 21, 2024 00:21
JavaScript optimized Git client
// Run in a clone of isomorphic-git repo
import { GitPktLine } from './src/models/GitPktLine.js'
import { GitTree } from './src/models/GitTree.js'
import { GitAnnotatedTag } from './src/models/GitAnnotatedTag.js'
import { GitCommit } from './src/models/GitCommit.js'
import { GitPackIndex } from './src/models/GitPackIndex.js'
import { collect } from './src/internal-apis.js'
import { GitRemoteManager } from './src/managers/GitRemoteManager.js'
import { parseUploadPackResponse } from './src/wire/parseUploadPackResponse.js'
@adamziel
adamziel / Read page.js
Created June 18, 2024 10:46
Reag page using OpenAI API
async function fetchAudioBlob(textContent) {
const myHeaders = new Headers();
myHeaders.append("Authorization", "Bearer TOKEN-HERE"); // Add your actual API key here
myHeaders.append("Content-Type", "application/json");
const raw = JSON.stringify({
"model": "tts-1",
"input": textContent,
"voice": "alloy"
});
@adamziel
adamziel / 1_usage.md
Created June 11, 2024 13:20
Markdown -> Blocks in Bun / Node.js

Converts markdown documents to WordPress block markup offline, without the browser.

Usage:

npm install
bun md-to-blocks.ts document.md > output.html
@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');