Skip to content

Instantly share code, notes, and snippets.

View Ocramius's full-sized avatar
🔬
In your repositories, watching your code. Always watching.

Marco Pivetta Ocramius

🔬
In your repositories, watching your code. Always watching.
View GitHub Profile
@Ocramius
Ocramius / periodic-time-ticker.php
Last active April 14, 2017 17:48
A PHP long running process that fires a command at a command bus at regular time intervals
#!/usr/bin/env php
<?php
declare(strict_types=1);
namespace CodeReviewsIo\Worker;
use CodeReviewsIo\Domain\Command\TickTime;
use Prooph\ServiceBus\CommandBus;
use React\EventLoop\Factory;
<?php
use Doctrine\DBAL\Driver\PDOSqlite\Driver;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\Configuration;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\XmlDriver;
use Doctrine\ORM\Proxy\ProxyFactory;
use Ramsey\Uuid\Doctrine\UuidType;
@Ocramius
Ocramius / active.md
Created April 7, 2016 16:38 — forked from paulmillr/active.md
Most active GitHub users (by contributions). http://twitter.com/paulmillr

Most active GitHub users (git.io/top)

The count of contributions (summary of Pull Requests, opened issues and commits) to public repos at GitHub.com from Mon, 01 Dec 2014 00:48:25 GMT till Tue, 01 Dec 2015 00:48:25 GMT.

Only first 1000 GitHub users according to the count of followers are taken. This is because of limitations of GitHub search. Sorting algo in pseudocode:

githubUsers
 .filter(user =&gt; user.followers &gt; 508)
@Ocramius
Ocramius / SubmitFakeStripeCreditCard.php
Last active March 16, 2016 13:33
Fake a stripe payment process in a Mink test context
<?php
declare(strict_types = 1);
namespace MyApp\Web\Utility\Stripe;
use Behat\Mink\Session;
use MyApp\Domain\Payment\Stripe\PublishableKey;
use Zend\Escaper\Escaper;
@Ocramius
Ocramius / psr-4-add.php
Last active May 30, 2018 14:18
Add a PSR-4 namespace to a composer.json file
#!/usr/bin/env php
<?php
file_put_contents(
'composer.json',
json_encode(array_merge_recursive(
['autoload' => ['psr-4' => [$argv[1] => $argv[2]]]],
json_decode(file_get_contents('composer.json'), true)
))
);
@Ocramius
Ocramius / .gitignore
Last active July 22, 2017 15:20
PissOff: a valid, polite and useful alternative to the `void` return type in PHP
vendor
composer.lock
@Ocramius
Ocramius / .gitignore
Last active April 21, 2016 20:05
Benchmarking type-hinted variadic arguments versus looping+checking values
vendor
composer.phar
@Ocramius
Ocramius / find-missing-return-types.php
Last active September 5, 2018 10:27
Script to find classes/interfaces/traits with missing return types: ADD THEM TO YOUR SHIT.
<?php
require_once __DIR__ . '/vendor/autoload.php';
$namespace = 'PutYourProjectNamespaceHere\\';
foreach (new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/src')), '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH) as $file) {
require_once $file[0];
}
@Ocramius
Ocramius / html-form-validator-factory.php
Created December 26, 2015 18:26
Form validation from HTML form
<?php
$formHtml = <<<'HTML'
<form action="%s" method="post">
<label for="email">Email:</label>
<input
type="email"
id="email"
name="email"
value=""
--TEST--
Verifies that generated access interceptors disallow private property direct read
--FILE--
Fatal error: Cannot access private property Kitchen::$sweets in /Users/ocramius/Documents/Projects/ProxyManager/tmp/ProxyManagerGeneratedProxy__PM__KitchenGenerated8d074ecba2008676c49d352470371679.php on line 127
Call Stack:
0.0002 229992 1. {main}() /Users/ocramius/Documents/Projects/ProxyManager/tests/language-feature-scripts/access-interceptor-denies-private-property-read.phpt:0
0.0251 2178640 2. ProxyManagerGeneratedProxy\__PM__\Kitchen\Generated8d074ecba2008676c49d352470371679->__get() /Users/ocramius/Documents/Projects/ProxyManager/tests/language-feature-scripts/access-interceptor-denies-private-property-read.phpt:17
0.0252 2183680 3. ProxyManager\Stub\EmptyClassStub->ProxyManagerGeneratedProxy\__PM__\Kitchen\{closure}() /Users/ocramius/Documents/Projects/ProxyManager/tmp/ProxyManagerGeneratedProxy__PM__KitchenGenerated8d074ecba2008676c49d352470371679.php:132