Skip to content

Instantly share code, notes, and snippets.

@thekid
thekid / .nessie.yml
Last active November 10, 2015 23:17
Experiment with container-based script execution
language: php
script:
- php /composer.phar install --prefer-dist
- curl -L 'https://github.com/xp-framework/xp-runners/releases/download/v5.6.1/setup' | php
- echo "use=vendor/autoload.php" > xp.ini
- echo "[runtime]" >> xp.ini
- echo "date.timezone=Europe/Berlin" >> xp.ini
- ./unittest src/test/config/unittest/core.ini
@thekid
thekid / .nessie.yml
Last active November 11, 2015 00:41
Experiment with build and deploy
build: zip
zip:
- conf
- lib
- src
- etc
deploy: shell
@thekid
thekid / Color.class.php
Created November 15, 2015 15:25
Color class
<?php namespace lang\functions\unittest;
/**
* Represents an RGB color
*
* @see http://docs.oracle.com/javase/8/docs/api/java/awt/Color.html
*/
class Color implements \lang\Value {
const FACTOR= 0.7;
private $r, $g, $b;
@thekid
thekid / Query.class.php
Last active February 21, 2016 16:32
Query command
<?php
use rdbms\DriverManager;
use rdbms\ResultSet;
use io\streams\Streams;
use util\log\LogObserver;
use util\log\LogCategory;
use util\log\StreamAppender;
/**
@thekid
thekid / json-mono-vs-dotnet.md
Last active January 13, 2016 00:09
JSON in Mono and .NET

In a project of mine, I needed to parse Composer's composer.json files using C#. I wanted to make this work on both Windows and Unix systems, using Microsoft's .NET Framework on Windows and Mono inside my Ubuntu virtualbox.

I was parsing the JSON using the DataContractJsonSerializer class, which I'd instantiated and used as follows:

var settings = new DataContractJsonSerializerSettings {  
    UseSimpleDictionaryFormat = true  
};
var json = new DataContractJsonSerializer(typeof(Composer), settings);
@thekid
thekid / Convert.class.php
Created February 27, 2016 18:49
Convert to PHP 7
<?php
use io\collections\FileCollection;
use io\collections\iterate\FilteredIOCollectionIterator;
use io\collections\iterate\ExtensionEqualsFilter;
use util\cmd\Console;
use io\streams\Streams;
use lang\XPClass;
class Convert {
@thekid
thekid / DeferTest.class.php
Created April 27, 2016 07:07
Defer processing elements in Sequences
<?php namespace util\data\unittest;
use util\data\Sequence;
class DeferTest extends \unittest\TestCase {
#[@test]
public function defer_using_existing_apis() {
$deferred= [];
$result= Sequence::concat(
@thekid
thekid / clock.script.php
Created June 19, 2016 22:45
A clock using xp-forge/terminal
<?php namespace clock;
use util\cmd\Console;
use util\cmd\term\Terminal;
use lang\Runtime;
use lang\Runnable;
use Packaged\Figlet\Figlet;
$figlet= new Figlet(isset($argv[1]) ? $argv[1] : null);
$time= explode("\n", $figlet->render(date('H:i')));
<?php namespace isql;
use rdbms\DriverManager;
use rdbms\SQLException;
use rdbms\SQLConnectException;
use rdbms\SQLConnectionClosedException;
use util\cmd\Console;
use util\profiling\Timer;
const PROMPT = "\e[31;1m\$u@\$h \e[36;1m\$d\e[0m [\e[32;1m%s\e[0m]\n\$";
<?php
use util\collections\{HashTable, HashSet, Queue, Stack};
class Collections extends \util\profiling\Measurable {
#[@measure]
public function hashTable() {
$h= new HashTable();
$h->put('key', 'value');