Skip to content

Instantly share code, notes, and snippets.

View rybakit's full-sized avatar

Eugene Leonovich rybakit

View GitHub Profile
@rybakit
rybakit / gist:888262
Created March 26, 2011 13:01
A set of commands to change default GDM theme
sudo -u gdm gconftool-2 --set /desktop/gnome/interface/gtk_theme --type string "Orta"
sudo -u gdm gconftool-2 --set /desktop/gnome/background/picture_filename --type string "/usr/share/backgrounds/Collapsar.jpg"
sudo -u gdm gconftool-2 --set /desktop/gnome/interface/icon_theme --type string "Faenza-Dark"
@rybakit
rybakit / dhondt.php
Created May 26, 2011 10:05
Calculate seats distribution according to the D'Hondt method
<?php
/**
* Calculate seats distribution according to the D'Hondt method.
*
* @see http://en.wikipedia.org/wiki/D'Hondt_method
* @author Eugene Leonovich <gen.work@gmail.com>
*
* @param array $polling An associative array (party => votes).
* @param integer $totalSeats The total number of seats to be allocated.
@rybakit
rybakit / AcmeExtension.php
Last active December 10, 2015 20:58
RybakitNavigationBundle full example
<?php
// Twig/AcmeExtension.php
namespace Acme\DemoBundle\Twig\Extension;
use Symfony\Component\DependencyInjection\ContainerInterface;
class AcmeExtension extends \Twig_Extension
{
private $container;
@rybakit
rybakit / Chain.php
Last active February 1, 2023 14:35
Nested chain validator for symfony > 2.1
<?php
namespace Acme\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\Constraints\Valid;
use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
/**
* @Annotation
@rybakit
rybakit / array_add.php
Last active December 12, 2015 07:38
array_replace() vs array union benchmark
<?php
for ($i = 0; $i < 1000000; ++$i) {
$server = $_SERVER;
$server += array(
'SERVER_NAME' => 'localhost',
'SERVER_PORT' => 80,
'HTTP_HOST' => 'localhost',
'HTTP_USER_AGENT' => 'Symfony/2.X',
'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
@rybakit
rybakit / JsonListener.php
Last active December 23, 2015 08:49
Json listener for Buzz http client
<?php
use Buzz\Listener\ListenerInterface;
use Buzz\Message\MessageInterface;
use Buzz\Message\RequestInterface;
class JsonListener implements ListenerInterface
{
/**
* {@inheritdoc}
@rybakit
rybakit / 0.1 sec duration
Last active January 4, 2016 13:36
pure msgpack.php vs json_* (dataProvider version)
$ MP_BENCH_DURATION=.01 MP_BENCH_TARGETS=pure_p,pure_u,json_p,json_u php tests/bench_json.php
Filter: MessagePack\Tests\Perf\Filter\NameFilter
Rounds: 3
Duration: .01
==============================================================================================
Test/Target MessagePack\Packer MessagePack\BufferUnpacker json_encode json_decode
----------------------------------------------------------------------------------------------
nil ......................... 39820.0000 ................ 24967.0000 . 65322.3333 . 55244.3333
false ....................... 38231.0000 ................ 24824.6667 . 63387.6667 . 56517.0000
@rybakit
rybakit / bench_json_vs_msgpack.php
Last active March 30, 2020 09:01
pure msgpack.php vs json extension
<?php
use App\MessagePack\PackedMap;
use App\MessagePack\PackedMapTransformer;
use MessagePack\BufferUnpacker;
use MessagePack\Packer;
use MessagePack\PackOptions;
require __DIR__.'/vendor/autoload.php';
<?php
// Borrowed from https://gist.github.com/denji/7c3c9d4b449f2699ec73
require __DIR__.'/../vendor/autoload.php';
ini_set("display_errors", 1);
ini_set("display_startup_errors", 1);
ini_set("error_reporting", E_ALL);
empty_loop 0.076
unpack_i16 2.097 2.021
ord_i16 0.925 0.849
unpack_u16 2.051 1.975
ord_u16 0.740 0.664
------------------------
Total 5.889
php -v
PHP 7.0.5 (cli) (built: Apr 23 2016 10:48:01) ( NTS )