Skip to content

Instantly share code, notes, and snippets.

<?php namespace xp\runtime;
/**
* Runs classes embedded in shell scripts
*
* Example:
*
* ```sh
* #!/bin/sh
* exec xp xp.runtime.Sh "$0" "$@"
@thekid
thekid / MoveTests.class.php
Created November 10, 2013 17:13
Execute using `xp -cp ../_tools/ MoveTests src/test/php/ net.xp_framework.unittest.remote remote.unittest`
<?php
use util\cmd\Console;
use io\streams\Streams;
use io\collections\FileCollection;
use io\collections\iterate\FilteredIOCollectionIterator;
use io\collections\iterate\ExtensionEqualsFilter;
class MoveTests extends \lang\Object {
@thekid
thekid / module.md
Created January 7, 2014 18:57
Modules for the XP Framework, 6.0

Modules for the XP Framework, 6.0

The goal

We want to modularize our code in order to encourage people to work on small and manageable chunks of the framework, which we'll call modules. The workflow to start working on such a module should consist of the smalles possible amount of steps. Ideally, given PHP and the XP Framework have been installed before, a git clone would suffice to start working:

# Set up - this is all that's necessary
$ git clone $remote/$lib
<?php
function with_array(array $a) { }
function with_callable(callable $c) { }
function with_class(Exception $e) { }
function with_primitive($p) { }
if (strstr($argv[1], '::')) {
$param= new ReflectionParameter(explode('::', $argv[1]), 0);
} else {
@thekid
thekid / php.md
Last active August 29, 2015 13:57
PHP: Steps to excellence

A while ago, maybe two years or so at the time of writing, I began thinking PHP was dead. There were releases, and bugfixes, of course, but no noticeable innovation strategy. It's over the zenith, I believed, and that we'd see a slow but steady decline in projects. Time for rethinking technology at home and at work?

Today, it seems my thoughts were too early: The PHP group has since released PHP 5.4, 5.5 and the first alpha of 5.6. Each of them has brought a list of improvements not only on the detail level, but actually meaningful to adapting to nowaday's languages: Short array syntax, traits, method and array call chaining, full closure support, generators (yield), to name just a few. Also, they finally managed to rid themselves of the magic quotes crap. At the same time, each release has brought performance and memory usage improvements. And all that without compromising on stability: The number of critical bugs is perceivedly on an all-time low.

Also, the rise of Composer and its becoming a pseudo-stand

@thekid
thekid / Composer.class.php
Created March 31, 2014 07:33
Invoke Composer from XP
<?php namespace xp\composer;
use util\cmd\Console;
use lang\ClassLoader;
/**
* XP Composer
*/
class Runner extends \lang\Object {
@thekid
thekid / hexdump_lib_index.js
Last active August 29, 2015 14:01
LDAP work in progress: Debugging / utilities
var Hexdump = {
chars: function(bytes, start, offset) {
var s = '';
var l = Math.min(offset, bytes.length);
for (j = start; j < l; j++) {
var c = bytes[j];
s += c < 0x20 || c > 0x7F ? '.' : String.fromCharCode(c);
}
return s;
branch_info() {
branch=`git name-rev HEAD --name-only 2>/dev/null`
if [ 0 = $? ] ; then
printf "$1" $branch
fi
}
export PS1="\[\e]0;\w\a\]\n\[\e[31m\]\u@\h \[\e[36m\]\w\$(branch_info ' [\[\033[01;32m\]%s\[\033[01;36m\]] ')\[\e[0m\]\n\$ "
@thekid
thekid / gdb output 1
Last active August 29, 2015 14:01
phpng Segmentation Faults
(gdb) run -C -q -dinclude_path=".:/home/friebe/xp/xp-framework/core::." -dmagic_quotes_gpc=0 -ddate.timezone="Europe/Berlin" /home/friebe/xp/xp-framework/core/tools/class.php xp.unittest.Runner src/test/config/unittest/core.ini
Starting program: /home/friebe/devel/php-src/sapi/cli/php -C -q -dinclude_path=".:/home/friebe/xp/xp-framework/core::." -dmagic_quotes_gpc=0 -ddate.timezone="Europe/Berlin" /home/friebe/xp/xp-framework/core/tools/class.php xp.unittest.Runner src/test/config/unittest/core.ini
warning: Could not load shared library symbols for linux-vdso.so.1.
Do you need "set solib-search-path" or "set sysroot"?
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib64/libthread_db.so.1".
[........................................................................
.........................................................................
.........................................................................
..............................................................NNNNN..
@thekid
thekid / feature-rewrite.diff
Created May 14, 2014 15:17
Feature: Rewrite
diff --git a/core/src/main/php/xp/scriptlet/AbstractUrlHandler.class.php b/core/src/main/php/xp/scriptlet/AbstractUrlHandler.class.php
index a7ccd7d..f2c8380 100755
--- a/core/src/main/php/xp/scriptlet/AbstractUrlHandler.class.php
+++ b/core/src/main/php/xp/scriptlet/AbstractUrlHandler.class.php
@@ -66,6 +66,8 @@ abstract class AbstractUrlHandler extends \lang\Object {
* @param [:string] headers request headers
* @param string data post data
* @param peer.Socket socket
+ * @param string[] matches
+ * @return int