Skip to content

Instantly share code, notes, and snippets.

View pqr's full-sized avatar

Petr Myazin pqr

View GitHub Profile
<?php
/* скрипт для запуска тестов для стати http://pqr7.wordpress.com/2014/09/03/haskell-vs-php/ */
function runTest($cmd, $content) {
$time = microtime(true);
$descriptorspec = [];
$descriptorspec[0] = ['pipe', 'r']; //stdin
$descriptorspec[1] = ['pipe', 'w']; //stdout
B/L no. Container No. From To Vessel
868026836
TRLU6921946
Toys, games
in 1× 40ft High Cube Dry
<?php
/* php скрипт в функциональном стиле (калька с Haskell) для статьи http://pqr7.wordpress.com/2014/09/03/haskell-vs-php/ */
ini_set('xdebug.max_nesting_level', 200000);
function parse($text) {
return splitPerBlocks(getLines($text));
}
function getLines($text) {
module Main where
{- программа на Haskell для статьи http://pqr7.wordpress.com/2014/09/03/haskell-vs-php/ -}
import qualified Data.Text as T --
import Data.List
parse :: String -> [[String]]
parse text = splitPerBlocks $ getLines text
<?php
/* php скрипт в императивном стиле для статьи http://pqr7.wordpress.com/2014/09/03/haskell-vs-php/ */
function splitPerBlock(array $lines) {
$blocks = [];
//Перебираем линии, отрезая от начала массива $lines найденные блоки. В итоге массив $lines станет пустым, а массив
//$linesPerBlock наполнится данными
while ($lines) {
//Если текущий блок начинается со строки, которая содержит "Container No.", удаляем эту строку
if (strpos($lines[0], 'Container No.') !== false) {
@pqr
pqr / gist:4052059
Created November 10, 2012 18:39
light/light4 composer.json
{
"name":"light/light4",
"version":"1.0.0",
"require":{
"php":">=5.4.0",
"silex/silex": "1.0.*@dev",
"twig/twig":">=1.8,<2.0-dev",
"monolog/monolog":">=1.0.0",
"symfony/validator":"2.1.*",
"symfony/console":"2.1.*"
@pqr
pqr / gist:4052040
Created November 10, 2012 18:35
project FB composer.json
{
"repositories":[
{
"type":"hg",
"url":"ssh://hg@bitbucket.org/pqr/light4"
}
],
"require":{
"light/light4":"dev-default"
},
@pqr
pqr / gist:2038621
Created March 14, 2012 18:49
Переопределение функции с вызовом оригинала
formatMsg = (function (original) {
return function (entry) {
additinalWork();
return original.apply(this, arguments);
};
})(formatMsg);