Skip to content

Instantly share code, notes, and snippets.

@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= [];
@thekid
thekid / Reactive.class.php
Created July 29, 2023 11:42
HTMX and the XP Framework
<?php
use web\Application;
use web\frontend\{Frontend, Handlebars, Get, Post, Delete, Param, View};
class Reactive extends Application {
public function routes() {
$impl= new class() {
private $list= ['One', 'Two'];
@thekid
thekid / contenteditable.html
Last active June 12, 2023 21:04
Automatically resizing textarea
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Input</title>
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<style>
#prompt {
font-family: 'Roboto', sans-serif;