Skip to content

Instantly share code, notes, and snippets.

View ThijsFeryn's full-sized avatar

Thijs Feryn ThijsFeryn

View GitHub Profile
@ThijsFeryn
ThijsFeryn / gist:2994393
Created June 26, 2012 08:31
Working with I/O streams in PHP
<?php
$stdin = fopen('php://stdin', 'r');
$stdout = fopen('php://stdout', 'w');
$stderr = fopen('php://stderr', 'w');
while(!feof($stdin)){
$line = trim(fgets($stdin));
if(strlen($line) > 0){
fwrite($stdout,strrev($line).PHP_EOL);
} else {
@ThijsFeryn
ThijsFeryn / gist:2994427
Created June 26, 2012 08:36
Short syntax for PHP command line I/O streams
<?php
while(!feof(STDIN)){
$line = trim(fgets(STDIN));
if(strlen($line) > 0){
fwrite(STDOUT,strrev($line).PHP_EOL);
} else {
fwrite(STDERR,"An empty line was passed".PHP_EOL);
}
}
@ThijsFeryn
ThijsFeryn / gist:3034005
Created July 2, 2012 16:11
Syntax highlighting using the PHP command line
$ php -s test.phps
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">if(</span><span style="color: #0000BB">$_REQUEST</span><span style="color: #007700">[</span><span style="color: #DD0000">'a'</span><span style="color: #007700">]&nbsp;==&nbsp;</span><span style="color: #DD0000">'b'</span><span style="color: #007700">){<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">'Some&nbsp;output'</span><span style="color: #007700">;<br />}<br /></span>
</span>
</code>
$
@ThijsFeryn
ThijsFeryn / gist:3034109
Created July 2, 2012 16:30
Using highlight_string to perform syntax highlighting in PHP
<?php
highlight_string('<?php echo "A line of PHP code a day keeps the doctor away";');
@ThijsFeryn
ThijsFeryn / gist:3034094
Created July 2, 2012 16:26
Using highlight_file to perform syntax highlighting in PHP
<?php
//Echo directly
highlight_file('test.php');
//Store in variable first
$source = highlight_file('test.php', true);
echo $source;
@ThijsFeryn
ThijsFeryn / gist:3034031
Created July 2, 2012 16:17
Save syntax highlighted PHP source code into an HTML file
$ php -s test.phps > test.html
$
@ThijsFeryn
ThijsFeryn / gist:3737009
Created September 17, 2012 12:26
Composer file for Silex & Zend Framework
{
"minimum-stability": "dev",
"require": {
"silex/silex": "1.0.*",
"zendframework/zendframework": "2.0.*"
}
}
@ThijsFeryn
ThijsFeryn / wordpress.vcl
Created October 10, 2012 20:33 — forked from willmot/wordpress.vcl
WordPress Varnish VCL
backend default {
.host = "127.0.0.1";
.port = "8080";
}
acl purge {
"localhost",
"69.195.222.132"
}
sub vcl_recv {
@ThijsFeryn
ThijsFeryn / symfony_esi.php
Last active November 9, 2015 13:33
A page built using Symfony Components containing 3 content blocks: the main content block with a TTL of 10 seconds and 2 content blocks loaded via ESI. The first one has a TTL of 20 seconds, the second one doesn't cache
<?php
require_once __DIR__.'/vendor/autoload.php';
use Symfony\Component\HttpKernel\HttpCache\Esi;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$esi = new Esi;
$request = Request::createFromGlobals();
$response = new Response();
$content = '<h1>This pages refreshes every 10 seconds</h1>';
@ThijsFeryn
ThijsFeryn / varnishv4esi.vcl
Last active November 12, 2015 14:04
VCL snippet that contains the minimum amount of config to support ESI using Surrogate headers
vcl 4.0;
backend default {
.host = "127.0.0.1";
.port = "8080";
}
sub vcl_recv {
set req.http.Surrogate-Capability = "key=ESI/1.0";
}