This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include 'guzzle.phar'; | |
use Guzzle\Http\Client; | |
use Guzzle\Http\Message\Response; | |
use Guzzle\Http\Plugin\BatchQueuePlugin; | |
use Guzzle\Http\Plugin\MockPlugin; | |
$client = new Client('http://www.test.com/'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// See https://github.com/mtdowling/cron-expression | |
require 'cron.phar'; | |
$totalWeeks = 5; | |
$fromDate = 'now'; | |
$cron = Cron\CronExpression::factory('0 0 * * 1'); | |
$dates = $cron->getMultipleRunDates($totalWeeks, $fromDate); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function iXml2array($xml) | |
{ | |
$result = array(); | |
$stack = array(array(&$result, &$xml)); | |
do { | |
$frame = array_pop($stack); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function xml2array($xml) | |
{ | |
$arr = array(); | |
foreach ($xml->getNamespaces() + array(null) as $prefix => $namespace) { | |
foreach ($xml->attributes($namespace) as $key => $value) { | |
// Add prefixes to prefixed attributes | |
if (is_string($prefix)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Note that this will not maintain XML attributes | |
function jsonXml2Array(SimpleXMLElement $xml) | |
{ | |
return json_decode(json_encode($xml), true); | |
} | |
function jsonXml2ArrayWithNamespacedAttributes($xml) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function evalXml2Array(SimpleXMLElement $xml) | |
{ | |
eval('$x = ' . str_replace(array('SimpleXMLElement::__set_state(', '))'), array('', ')'), var_export($xml, true)) . ';'); | |
return $x; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$fibMemo = call_user_func(function () { | |
$memo = array(0 => 0, 1 => 1); | |
$fib = function ($n) use (&$memo, &$fib) { | |
if (!isset($memo[$n])) { | |
$memo[$n] = $fib($n - 1) + $fib($n - 2); | |
} | |
return $memo[$n]; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Various methods of computing Fibonacci numbers in PHP | |
*/ | |
class Fibonacci | |
{ | |
/** | |
* @var array Memoization cache | |
* @see Fibonacci::memoized |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$m = curl_multi_init(); | |
function sendMulti($ch) | |
{ | |
global $m; | |
curl_multi_add_handle($m, $ch); | |
$active = false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var http = require("http"); | |
http.createServer(function(req, res) { | |
req.addListener("data", function(chunk) { | |
// Read data chunks | |
}); | |
// Called when the request completes | |
req.addListener("end", function() { | |
res.writeHead(200, "OK", { "Content-Length": 10 }); |
OlderNewer