Skip to content

Instantly share code, notes, and snippets.

@thekid
thekid / cdp.script.php
Created April 6, 2025 13:21
CDP in PHP
<?php
use io\{File, Files};
use lang\Value;
use peer\http\HttpConnection;
use text\json\{Json, StreamInput};
use util\Comparison;
use util\cmd\Console;
use websocket\WebSocket;
@thekid
thekid / Ws.class.php
Last active January 19, 2025 12:20
Websockets example
<?php
use util\Bytes;
use web\Application;
use web\handler\WebSocket;
class Ws extends Application {
public function routes() {
return [
@thekid
thekid / TestGPT.class.php
Last active November 3, 2024 21:09
ChatGPT REST API
<?php
use com\openai\rest\OpenAIEndpoint;
use io\File;
use util\Objects;
use web\Application;
class TestGPT extends Application {
private $ai;
@thekid
thekid / TestRT.class.php
Last active November 3, 2024 22:08
ChatGPT realtime API inside websocket server
<?php
use com\openai\realtime\RealtimeApi;
use io\streams\LinesIn;
use io\{File, Files};
use util\Objects;
use util\log\Logging;
use web\Application;
class TestRT extends Application {
@thekid
thekid / rt-chat.script.php
Last active October 28, 2024 08:52
CLI audio chat with ffmpeg and Azure AI realtime API
<?php namespace test;
use com\openai\realtime\RealtimeApi;
use util\cmd\Console;
use lang\Process;
const SPINNER= ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'];
// Wave file header
function wave($numChannels, $sampleRate, $bitsPerSample, $durationSeconds) {
@thekid
thekid / .gitignore
Last active August 2, 2024 10:24
Atlas Search
composer.lock
vendor/
static/
@thekid
thekid / Todo.class.php
Last active August 26, 2024 18:16
TODO application (PHP, HTMX, SQLite)
<?php
use rdbms\{DriverManager, DBConnection};
use web\frontend\{Frontend, AssetsFrom, Handlebars, Get, Post, Delete, Put, View, Param};
use web\{Application, Environment, Handler};
class Todo extends Application {
const PATH= 'todos.db';
/** Returns a database connection */
@thekid
thekid / Upload.class.php
Last active January 26, 2024 19:52
HTMX & Vanilla JS & XP Upload, including drag & drop
<?php
use util\cmd\Console;
use web\Application;
use web\frontend\{Frontend, Handlebars, Get, Post, View, Request};
class Upload extends Application {
public function routes() {
$impl= new class() {
@thekid
thekid / Bold.class.php
Last active December 8, 2023 19:54
Convert Office Documents to Markdown
<?php
class Bold extends Container {
public function emit($emit, ... $args) {
return $emit->bold($this, ...$args);
}
}
@thekid
thekid / generic-methods-syntax.diff
Created August 7, 2023 15:35
Generic methods syntax diff
diff --git a/src/main/php/lang/ast/nodes/Signature.class.php b/src/main/php/lang/ast/nodes/Signature.class.php
index 76e3e94..0d946fb 100755
--- a/src/main/php/lang/ast/nodes/Signature.class.php
+++ b/src/main/php/lang/ast/nodes/Signature.class.php
@@ -5,6 +5,7 @@ use lang\ast\Node;
class Signature extends Node {
public $kind= 'signature';
public $parameters, $returns, $byref;
+ public $generics= [];