Skip to content

Instantly share code, notes, and snippets.

@thekid
thekid / Operations.class.php
Created April 25, 2017 20:02
Performance profiling for xp-forge/sequence
<?php
use util\data\Sequence;
class Operations extends \util\profiling\Measurable {
private static $range;
static function __static() {
self::$range= range(0, 9999);
}
--- semantic-2.2.13.js 2017-08-07 18:18:56.000000000 +0200
+++ src/main/webapp/static/vendor/semantic/semantic.js 2017-09-05 17:27:14.484722700 +0200
@@ -4564,11 +4564,12 @@
;
$.each(values, function(index, value) {
if(module.get.item(value) === false) {
+ var escapedValue = module.escape.value(value);
html = settings.templates.addition( module.add.variables(message.addResult, value) );
$userChoice = $('<div />')
.html(html)
@thekid
thekid / Home.class.php
Last active April 10, 2021 14:37
XP Frontend example
<?php
use web\frontend\{Handler, Get, Param};
#[Handler]
class Home {
#[Get]
public function get(
#[Param('name')]
@thekid
thekid / git.go
Created August 7, 2018 21:01
Fixing "Invalid path" for go + cygwin git
package main
import (
"fmt"
"os"
"os/exec"
"path/filepath"
"strings"
"syscall"
)
@thekid
thekid / typemap.script.php
Created August 29, 2018 15:41
What's the fastest implementation of a map lookup on types?
<?php namespace typemap;
use lang\Value;
use lang\reflect\Package;
use util\Objects;
use util\cmd\Console;
use util\data\unittest\fixtures\Person;
use util\profiling\Timer;
class ForeachMap {
@thekid
thekid / Chat.class.php
Last active September 13, 2019 19:46
Chat
<?php namespace de\thekid\example;
use io\redis\RedisProtocol;
use peer\SocketException;
use web\protocol\{Protocols, Http, WebSockets};
use web\{Service, Listeners};
use xp\web\ServeDocumentRootStatically;
class Chat extends Service {
private $connections= [];
@thekid
thekid / Chat.php
Last active October 5, 2024 09:56
WebSocket chat based on Redis queues
<?php
use io\redis\RedisProtocol;
use websocket\Listeners;
class Chat extends Listeners {
/** @return [:var] */
public function serve($events) {
$dsn= $this->environment->arguments()[0] ?? 'redis://localhost';
@thekid
thekid / MultiPart.class.php
Created December 13, 2019 22:48
File Uploads
<?php namespace web;
use lang\FormatException;
/** @see https://tools.ietf.org/html/rfc7578 */
class MultiPart {
private $request, $boundary;
private $buffer= '';
public function __construct($request) {
<?php
use web\frontend\{Frontend, Templates, View};
use web\session\{InFileSystem, Cookies};
use web\{Application, Filter, Filters};
class Uploads extends Application {
/** @return [:var] */
public function routes() {
@thekid
thekid / convert-annotations.script.php
Created September 20, 2020 23:05
Convert XP annotations to PHP 8 attributes
<?php namespace unittest;
use io\collections\iterate\{FilteredIOCollectionIterator, ExtensionEqualsFilter} from 'xp-framework/io-collections';
use io\collections\{FileCollection, FileElement} from 'xp-framework/io-collections';
use io\streams\LinesIn;
use util\cmd\Console;
function import(string $line): iterable {
$p= strrpos($line, '\\');