Skip to content

Instantly share code, notes, and snippets.

View xavismeh's full-sized avatar

Xav. xavismeh

View GitHub Profile
<?php
declare(strict_types=1);
namespace MyPackage\Validator\Constraints\Vat;
use Psr\Log\LoggerInterface;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
@xavismeh
xavismeh / symfony-messenger_sqs_installation.md
Last active June 13, 2019 17:57
Tutorial to use Amazon SQS with symfony/messenger component
  1. Install librairies/bundle:
$ composer require sroze/messenger-enqueue-transport enqueue/sqs
  1. Enable EnqueueAdapterBundle bundle:
// config/bundles.php
<?php
@xavismeh
xavismeh / cachetool.rake
Created May 27, 2016 15:09
Flush FCGI opcache during capistrano deployment using cachetool
namespace :cachetool do
task :run, :command do |t, args|
args.with_defaults(:command => :list)
on release_roles(fetch(:cachetool_roles)) do
within fetch(:cachetool_working_dir) do
execute :cachetool, args[:command], *args.extras
end
end
end
$ brew install php56 --with-gmp --with-homebrew-apxs --with-homebrew-curl --with-homebrew-libressl --with-homebrew-libxml2 --with-homebrew-libxslt --with-imap --with-mssql --with-postgresql --without-apache
==> Installing php56 from homebrew/homebrew-php
==> Downloading https://php.net/get/php-5.6.14.tar.bz2/from/this/mirror
Already downloaded: /Library/Caches/Homebrew/php56-5.6.14
==> ./configure --prefix=/usr/local/Cellar/php56/5.6.14 --localstatedir=/usr/local/var --sysconfdir=/usr/local/etc/php/5.6 --with-config-file-path=/us
==> make
==> make install
==> Caveats
The php.ini file can be found in:
/usr/local/etc/php/5.6/php.ini
import os
filename = 'my_file.txt'
filesize = os.path.getsize(filename)
b_read = 0
f = open(filename, 'r')
# read n bytes and perform action
# ...
b_read += n
@xavismeh
xavismeh / gist:37e8d6b331d18231fb9a
Last active September 1, 2015 23:50
hack to use a translator that will return keys
<?php
// in config : <parameter key="translator.class">AppBundle\Translation\TestTranslator</parameter>
namespace AppBundle\Translation;
use Symfony\Component\Translation\Translator;
class TestTranslator extends Translator
{
/**

Keybase proof

I hereby claim:

  • I am xavismeh on github.
  • I am xavismeh (https://keybase.io/xavismeh) on keybase.
  • I have a public key whose fingerprint is 2ACE B635 69E9 EA77 B76A D60A CD45 79C3 2D73 9BEA

To claim this, I am signing this object:

<?php
$input = ['a' => 'b', 'c' => 'd'];
$keys = array_keys($input);
$values = array_values($input);
$i = 0;
while (isset($keys[$i], $values[$i])) {
$currentKey = $keys[$i];
$currentValue = $values[$i];
function f($a, $k) {
$b = $a;
$c = &$k;
$b[$k] = null;
if (null === $a[$k]) {
$a[$k] = $c;
return true;
}
function f($a, $k) { ob_start(); debug_zval_dump($a[$k]); preg_match('/refcount\((\d+)/', ob_get_clean(), $b); return $b[1] == 1; }