Skip to content

Instantly share code, notes, and snippets.

View ralphschindler's full-sized avatar

Ralph Schindler ralphschindler

View GitHub Profile
<?php
setup();
$t = new Tree('top', 'T');
$t->append(new TreeNode('one', 1));
$t->append($x = new TreeNode('two', 2));
$t->append(new TreeNode('three', 3));
$t->append(new TreeNode('foo', 'foo'));
@ralphschindler
ralphschindler / tree.php
Created April 21, 2010 14:42
'tree' console command, in PHP.
#!/usr/bin/php
<?php
/**
* Because you want "tree", but cannot find the source code quick enough
* on the web to compile for OS.X or there is no suitable implementation
* on windows.
*/
// set error reporting
error_reporting(E_STRICT | E_ALL);
@ralphschindler
ralphschindler / conditional-ternary-eliminate-waste.php
Created March 4, 2011 15:59
Usage of the Conditional Ternary operator to reduce brace and newline waste when processing optional method parameters
<?php
class Coordinate
{
protected $x;
protected $y;
public function __construct($x = null, $y = null)
{
(empty($x)) ?: $this->setX($x);
<?php
$service = 'Amazon';
chdir(__DIR__);
`git clone ./zf2 ZendService{$service}-library`;
`git clone ./zf2 ZendService{$service}-tests`;
chdir(__DIR__ . '/ZendService' . $service . '-library');
<?php
namespace GitHub\Controller;
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Http\ClientStatic;
use GitHubAPIv3\UserAPI;
@ralphschindler
ralphschindler / spider.php
Created September 22, 2012 15:27
Script to be used with PHP's built-in webserver to proxy and spider a site on click
<?php
// start PHP with: php -S localhost:8888 -t . spider.php
$site = 'http://www.targetwebsite.org/';
$path = $_SERVER["REQUEST_URI"];
if ($path == '/') {
$path = '/index.html';
<?php
function getFormattedOutput($string)
{
$tags = array(
'bold' => 1, 'dark' => 2, 'italic' => 3, 'underline' => 4, 'blink' => 5, 'reverse' => 7, 'concealed' => 8,
'black' => 30, 'red' => 31, 'green' => 32, 'yellow' => 33, 'blue' => 34, 'magenta' => 35, 'cyan' => 36, 'white' => 37,
'bg_black' => 40, 'bg_red' => 41, 'bg_green' => 42, 'bg_yellow' => 43, 'bg_blue' => 44, 'bg_magenta' => 45, 'bg_cyan' => 46, 'bg_white' => 47
);
<?php
class SomeClass {
/**
* @signature __construct(string $authentication) 40 byte auth code
* @signature __construct(string $username, string $password) Github Username, Github Password
* @signature __construct(array $authentication) array('username' => 'xx', 'password' => xxx)
*
* @param string|array $authentication
*/
$ ab -k -n1 http://localhost/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking localhost (be patient).....done
Server Software: Apache/2.2.22
Server Hostname: localhost
@ralphschindler
ralphschindler / README.md
Last active October 21, 2017 12:55
Anonymous Proxy Pattern (Ralph Schindler)

README

Problem & Solution

Problem: you want to set protected properties of an object, or a set of objects as efficiently and without much convention as possible.

Solution in 5.4 is the "Anonymous Proxy", see the by-anonymous-proxy.php file.