Skip to content

Instantly share code, notes, and snippets.

View mtdowling's full-sized avatar

Michael Dowling mtdowling

View GitHub Profile
@mtdowling
mtdowling / gist:9868295
Created March 30, 2014 06:01
Array and object truthiness
<?php
@$i = $argv[1] ?: 1000;
$c = array();
$s = microtime(true);
for ($j = 0; $j < $i; $j++) {
if ($c) {}
}
echo 'Empty Array: ' . (microtime(true) - $s) . "\n";
@mtdowling
mtdowling / gist:10002415
Last active August 29, 2015 13:58
jmespath.php perf
$ bin/perf.php
php bin/perf.php
time: 0.016928ms, description: ./bin/../tests/compliance/perf/basic.json, name: foo
time: 0.031948ms, description: ./bin/../tests/compliance/perf/basic.json, name: foo.bar
time: 0.046968ms, description: ./bin/../tests/compliance/perf/basic.json, name: foo.bar.baz
time: 0.060797ms, description: ./bin/../tests/compliance/perf/basic.json, name: foo.bar.baz.bad
time: 0.145912ms, description: ./bin/../tests/compliance/perf/deep_hierarchy.json, name: j49.j48.j47.j46.j45.j44.j43.j42.j41.j40
time: 0.711918ms, description: ./bin/../tests/compliance/perf/deep_hierarchy.json, name: j49.j48.j47.j46.j45.j44.j43.j42.j41.j40.j39.j38.j37.j36.j35.j34.j33.j32.j31.j30.j29.j28.j27.j26.j25.j24.j23.j22.j21.j20.j19.j18.j17.j16.j15.j14.j13.j12.j11.j10.j9.j8.j7.j6.j5.j4.j3.j2.j1.j0
time: 0.090837ms, description: ./bin/../tests/compliance/perf/multiwildcard.json, name: foo[*].bar[*].kind
time: 0.091791ms, description: ./bin/../tests/compliance/perf/multiwildcard.json, name: foo[*].bar[0].kind
### Keybase proof
I hereby claim:
* I am mtdowling on github.
* I am mtdowling (https://keybase.io/mtdowling) on keybase.
* I have a public key whose fingerprint is C660 D8CE AE59 6DDF CE43 8F4C B48A B84B 28DB 4EF7
To claim this, I am signing this object:
@mtdowling
mtdowling / install.sh
Last active August 29, 2015 14:05
Test installer
#!/usr/bin/env bash
set -e
[ -z "$CHAG_DIR" ] && CHAG_DIR="/usr/local/bin"
[ -z "$CHAG_VERSION" ] && CHAG_VERSION="master"
CHAG_SOURCE="https://raw.githubusercontent.com/mtdowling/chag/$CHAG_VERSION/chag"
echo "=> Downloading chag to '$CHAG_DIR'"
@mtdowling
mtdowling / gist:9b613158fe894e35715b
Created August 23, 2014 00:26
PHPDoc phar failure
$ wget https://github.com/phpDocumentor/phpDocumentor2/releases/download/v2.7.0/phpDocumentor.phar
--2014-08-22 17:23:24-- https://github.com/phpDocumentor/phpDocumentor2/releases/download/v2.7.0/phpDocumentor.phar
Resolving github.com... 192.30.252.131
Connecting to github.com|192.30.252.131|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://s3.amazonaws.com/github-cloud/releases/761653/f8ace192-291d-11e4-93cc-3a8d946f2e49.phar?response-content-disposition=attachment%3B%20filename%3DphpDocumentor.phar&AWSAccessKeyId=AKIAISTNZFOVBIJMK3TQ&Expires=1408753470&Signature=heQkektTHiYFmz9AVb8Z2%2FmytQA%3D [following]
--2014-08-22 17:23:30-- https://s3.amazonaws.com/github-cloud/releases/761653/f8ace192-291d-11e4-93cc-3a8d946f2e49.phar?response-content-disposition=attachment%3B%20filename%3DphpDocumentor.phar&AWSAccessKeyId=AKIAISTNZFOVBIJMK3TQ&Expires=1408753470&Signature=heQkektTHiYFmz9AVb8Z2%2FmytQA%3D
Resolving s3.amazonaws.com... 10.186.10.1
Connecting to s3.amazonaws.com|10
@mtdowling
mtdowling / diff.diff
Last active August 29, 2015 14:05
Sami static templates
diff --git a/README.rst b/README.rst
index d7f7d17..cb1961d 100644
--- a/README.rst
+++ b/README.rst
@@ -200,6 +200,9 @@ the default theme:
'js/bootstrap.min.js': 'js/bootstrap.min.js'
'js/jquery-1.11.1.min.js': 'js/jquery-1.11.1.min.js'
+ static_templates:
+ 'api_tree': 'layout/api_tree.twig'
@mtdowling
mtdowling / gist:47da5eab54337cdc7ecc
Last active August 29, 2015 14:06
React and Guzzle experiment
<?php
require 'vendor/autoload.php';
use GuzzleHttp\Stream\BufferStream;
use GuzzleHttp\Stream\AsyncReadStream;
use GuzzleHttp\Ring\Future;
$loop = React\EventLoop\Factory::create();
$dnsResolverFactory = new React\Dns\Resolver\Factory();
$dnsResolver = $dnsResolverFactory->createCached('8.8.8.8', $loop);
<?php
// Generic middleware that does not have to create a response.
$ringStyle = function(RequestInterface $request, callable $next) {
$request = $request->withHeader('Foo', 'Bar');
$response = $next($request);
$response = $response->withHeader('Baz', 'Bam');
return $response;
};
@mtdowling
mtdowling / guzzle_async_curl_with_mock.php
Created January 15, 2012 16:49
Guzzle: async curl requests with mocked responses
<?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/');
@mtdowling
mtdowling / cron-mondays.php
Created January 16, 2012 18:34
get the next 5 mondays from now using cron expression
<?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);