Skip to content

Instantly share code, notes, and snippets.

<?php
use Twig\Environment;
use Twig\Loader\ArrayLoader;
function twig_template(string $template): callable
{
$twigEnvironment = new Environment($loader = new ArrayLoader());
$loader->setTemplate($templateName = md5($template), $template);

Keybase proof

I hereby claim:

  • I am alexeyshockov on github.
  • I am alexeyshockov (https://keybase.io/alexeyshockov) on keybase.
  • I have a public key ASDd7Y2ZklOhKdpNZkRBzgWqx98Q5yAV3XPkNZ38SyMkaQo

To claim this, I am signing this object:

<?php
use GuzzleHttp\Client;
use GuzzleHttp\Pool;
use GuzzleHttp\Promise\CancellationException;
use GuzzleHttp\Psr7\Request;
require 'vendor/autoload.php';
$client = new Client();
<?php
/*
*
* To set up:
* 1. Install composer.
* 2. Run `php composer.phar require guzzlehttp/guzzle
* 3. Run this test script with one of the following arguments:
* 3.1. php guzzle-pool-test.php curl (to use GuzzleHttp\Handler\CurlHandler)
* 3.2. php guzzle-pool-test.php multicurl (to use GuzzleHttp\Handler\MultiCurlHandler)
@alexeyshockov
alexeyshockov / obset.php
Created August 15, 2017 14:13
Object set & object map in PHP
<?php
/**
*
* Object map proof of concept.
*
*/
class Map implements IteratorAggregate, ArrayAccess, Countable
{
Removing: /usr/local/Cellar/ack/2.14... (3 files, 182.7KB)
Removing: /usr/local/Cellar/ack/2.16... (4 files, 190.7KB)
Removing: /usr/local/Cellar/ant/1.10.0... (1,617 files, 36.6MB)
Removing: /usr/local/Cellar/bash/4.4.5... (146 files, 8.8MB)
Removing: /usr/local/Cellar/bash-completion/1.3_1... (188 files, 605.9KB)
Removing: /usr/local/Cellar/boost/1.63.0... (12,491 files, 397.1MB)
Removing: /usr/local/Cellar/carthage/0.18.1... (49 files, 12.4MB)
Removing: /usr/local/Cellar/carthage/0.20.1... (64 files, 22.4MB)
Removing: /usr/local/Cellar/colordiff/1.0.16... (8 files, 54.4KB)
Removing: /usr/local/Cellar/colordiff/1.0.17... (10 files, 57.9KB)
#!/usr/bin/env php
<?php
$file = $argv[1];
$date = (new DateTime())->modify('-1 day');
$doc = new SimpleXMLElement(file_get_contents($file));
foreach ($doc->trk->trkseg->children() as $k => $trkpt) {
<?php
namespace GuzzleDynamicRequests;
require __DIR__ . '/vendor/autoload.php';
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Response;
// Do not extend IteratorIterator, because it cashes the return values somehow!
@alexeyshockov
alexeyshockov / imap-test.out
Created October 10, 2015 13:47
Mailtrap.io PHP tests
$ php imap-test.php
int(1)
string(0) ""
@alexeyshockov
alexeyshockov / booleans
Last active December 17, 2015 11:19
Fucking PHP type system.
± phpsh
Starting php
type 'h' or 'help' to see instructions & features
php> $a = [1, 4, 3, true, false, 6, 0, 19]
php> =$a
array(
0 => 1,
1 => 4,
2 => 3,