Skip to content

Instantly share code, notes, and snippets.

@thekid
thekid / codeinterpreter.script.php
Last active April 10, 2026 19:15
xp-forge/aws: Use code interpreter
<?php
use com\amazon\aws\{CredentialProvider, ServiceEndpoint};
use lang\{Closeable, Value};
use util\cmd\Console;
use util\{Comparison, Objects};
use util\log\Logging;
/** @see https://docs.aws.amazon.com/bedrock-agentcore/latest/devguide/code-interpreter-resource-session-management.html */
class CodeInterpreter {
@thekid
thekid / base64.script.php
Last active March 29, 2026 13:55
Base64 native functions vs. streaming
<?php
use io\streams\{FilterInputStream, FileInputStream, Streams};
use lang\Runtime;
use util\cmd\Console;
use util\profiling\Timer;
$source= $argv[1];
$method= $argv[2];
@thekid
thekid / mimetypes.script.php
Created February 15, 2026 23:47
Create mimetypes for XP Core
<?php namespace tools;
use util\cmd\Console;
use peer\http\HttpConnection from 'xp-framework/http';
use text\json\StreamInput from 'xp-forge/json';
$c= new HttpConnection('https://cdn.jsdelivr.net/gh/jshttp/mime-db@latest/db.json');
$r= $c->get();
if (200 !== $r->statusCode()) {
@thekid
thekid / mcp-app.js
Last active February 21, 2026 09:39
MCP Apps
class McpApp {
#nextId = 1;
#pending = {};
#handlers = {
'ui/notifications/host-context-changed': params => this.#apply(params.styles),
};
/** Creates a new MCP app */
constructor(name, version= '1.0.0') {
this.name = name;
@thekid
thekid / branch-is.diff
Created January 31, 2026 11:01
Match pattern matching inside branches
diff --git a/src/main/php/lang/ast/syntax/php/IsOperator.class.php b/src/main/php/lang/ast/syntax/php/IsOperator.class.php
index 30832b5..9c3f126 100755
--- a/src/main/php/lang/ast/syntax/php/IsOperator.class.php
+++ b/src/main/php/lang/ast/syntax/php/IsOperator.class.php
@@ -125,6 +125,8 @@ class IsOperator implements Extension {
});
$language->prefix('match', 0, function($parse, $token) use($pattern) {
+ static $id= 0;
+
@thekid
thekid / OAuth2Gateway.class.php
Last active January 1, 2026 16:54
MCP OAuth flow POC
<?php
use io\streams\Streams;
use web\Routes;
use web\auth\Authentication;
use web\filters\Invocation;
use web\session\Sessions;
class OAuth2Gateway {
private $base, $tokens, $clients;
@thekid
thekid / arrayaccess.diff
Last active December 28, 2025 12:12
Is operator array structure support for ArrayAccess
diff --git a/src/main/php/lang/ast/syntax/php/IsOperator.class.php b/src/main/php/lang/ast/syntax/php/IsOperator.class.php
index 30832b5..bb1048e 100755
--- a/src/main/php/lang/ast/syntax/php/IsOperator.class.php
+++ b/src/main/php/lang/ast/syntax/php/IsOperator.class.php
@@ -250,24 +250,29 @@ class IsOperator implements Extension {
}
return $compound;
} else if ($pattern instanceof IsArrayStructure) {
- $compound= new BinaryExpression(
- new InvokeExpression(new Literal('is_array'), [$init]),
@thekid
thekid / unpack.diff
Created December 28, 2025 10:15
Is operator with binding rest
diff --git a/src/main/php/lang/ast/syntax/php/IsOperator.class.php b/src/main/php/lang/ast/syntax/php/IsOperator.class.php
index 7e34fc1..99c40b3 100755
--- a/src/main/php/lang/ast/syntax/php/IsOperator.class.php
+++ b/src/main/php/lang/ast/syntax/php/IsOperator.class.php
@@ -14,6 +14,7 @@ use lang\ast\nodes\{
MatchExpression,
OffsetExpression,
ScopeExpression,
+ UnpackExpression,
Variable
@thekid
thekid / IsOptional.class.php
Created December 27, 2025 16:52
Is operator with binding defaults using =
<?php namespace lang\ast\syntax\php;
use lang\ast\Type;
use util\Objects;
class IsOptional extends Type {
public $binding, $default;
/**
* Creates a an optional binding "type"
@thekid
thekid / IsOptional.class.php
Created December 27, 2025 16:34
Is operator with binding defaults using ??
<?php namespace lang\ast\syntax\php;
use lang\ast\Type;
use util\Objects;
class IsOptional extends Type {
public $binding, $default;
/**
* Creates a an optional binding "type"