Skip to content

Instantly share code, notes, and snippets.

@thekid
thekid / .gitignore
Last active June 16, 2024 17:58
Atlas Search
composer.lock
vendor/
static/
@thekid
thekid / Todo.class.php
Last active June 10, 2024 19:02
TODO application (PHP, HTMX, SQLite)
<?php
use rdbms\DriverManager;
use web\Application;
use web\frontend\{Frontend, AssetsFrom, Handlebars, Get, Post, Delete, Put, View, Param};
class Todo extends Application {
public function routes() {
$db= $this->environment->path('todos.db');
@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;
@thekid
thekid / index.html
Created June 5, 2023 07:01
Web Speech API
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Speech test</title>
</head>
<body>
<h1>Speech test</h1>
@thekid
thekid / PropertyDelegates.php
Last active May 22, 2023 19:04
Reusable property hooks
<?php
use util\cmd\Console;
class ByLazy {
public function __construct(private callable $init) { }
public function get($self, $property) {
return ($property->value??= [($this->init)()])[0];
}
@thekid
thekid / this.property.diff
Created May 18, 2023 15:21
Alternative to parent::$x::get()
diff --git a/src/main/php/lang/ast/emit/PHP.class.php b/src/main/php/lang/ast/emit/PHP.class.php
index b15f8bb..e85c8ba 100755
--- a/src/main/php/lang/ast/emit/PHP.class.php
+++ b/src/main/php/lang/ast/emit/PHP.class.php
@@ -436,7 +436,7 @@ abstract class PHP extends Emitter {
// Virtual properties support: __virtual member + __get() and __set()
if ($context->virtual) {
- $result->out->write('private $__virtual= [');
+ $result->out->write('protected $__virtual= [');