Skip to content

Instantly share code, notes, and snippets.

View spolischook's full-sized avatar
🌐
Saving the world

Serhii Polishchuk spolischook

🌐
Saving the world
View GitHub Profile
<?php
namespace Oro\Bundle\ConfigBundle\Tests\Behat\Element;
use Behat\Mink\Element\NodeElement;
use Oro\Bundle\TestFrameworkBundle\Behat\Element\Element;
class SidebarConfigMenu extends Element
{
public function clickLink($locator)
{
<?php
interface ComparativeFood
{
public static function isApplicable(Food $food)
}
class Food {}
abstract class MarketFood implements ComparativeFood
{
public function __construct(Food $food, Envirorment $env)
{}
@spolischook
spolischook / BrowserContext.php
Created July 28, 2016 12:37 — forked from fabiang/BrowserContext.php
Mink + PhantomJS catch JavaScript Errors
<?php
use Behat\MinkExtension\Context\MinkContext;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\PyStringNode;
use Behat\Gherkin\Node\TableNode;
/**
* Defines application features from the specific context.
oro_menu_config:
items:
hrm_tab:
label: 'oro.hrm.menu.hrm_tab.label'
uri: '#'
extras:
position: 100
icon: icon-folder-open
applicants:
label: ''
@spolischook
spolischook / get-files-test.php
Last active December 2, 2015 23:06
Get files test
<?php
public function testGetFiles()
{
$method = self::getMethod('getFiles');
$command = new ImportLogsCommand();
$files = $method->invokeArgs($command, [realpath(__DIR__.'/../..')]);
$this->assertContains(realpath(__DIR__.'/ImportLogsCommandTest.php'), $files);
$this->assertContains(realpath(__DIR__.'/../../AppBundle.php'), $files);
}
@spolischook
spolischook / get-files.php
Last active January 27, 2016 01:18
Get all files recursively
<?php
/**
* @param $dir
* @param array $files
* @return array
*/
protected function getFiles($dir, array &$files = [])
{
foreach (scandir($dir) as $file) {
if (in_array($file, [".", ".."])) {
function pager(val) {
var pager = document.getElementById("log_search_type_limit"),
perpage = pager.options[pager.selectedIndex].value,
url = replaceQueryParam('limit', perpage, window.location.search);
window.location = window.location.pathname + url;
}
function replaceQueryParam(param, newval, search) {
var regex = new RegExp("([?;&])" + param + "[^&;]*[;&]?");
var query = search.replace(regex, "$1").replace(/&$/, '');
@spolischook
spolischook / kotoblog_index.html.twig
Last active November 25, 2015 03:21
Select with per page pagination count
{% set limit = app.request.query.get('limit')|default(10) %}
<select class="form-control" onchange="pager()" id="perPageSelector">
<option {% if limit == 10 %}selected{% endif %} value="10">10</option>
<option {% if limit == 25 %}selected{% endif %} value="25">25</option>
<option {% if limit == 50 %}selected{% endif %} value="50">50</option>
<option {% if limit == 100 %}selected{% endif %} value="100">100</option>
</select>
@spolischook
spolischook / kotoblog_set-default-locale-in-silex-by-parsing-http-accept-language-header.php
Last active March 4, 2021 03:25
Set prefer language by parsing HTTP_ACCEPT_LANGUAGE header in Silex
<?php
$app->register(new Silex\Provider\TranslationServiceProvider(), [
'locale_fallbacks' => ['en', 'uk', 'ru'],
]);
$app->before(function() use ($app) {
$locales = $app['translator']->getFallbackLocales();
$prefLocales = array_reduce(explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']), function ($res, $el) { list($l, $q) = array_merge(explode(';q=', $el), [1]); $res[$l] = (float) $q; return $res; }, []);
asort($prefLocales);
@spolischook
spolischook / kotoblog_parse-http-accept-language-header.php
Last active November 9, 2024 05:34
Get prefer language by parsing HTTP_ACCEPT_LANGUAGE header
<?php
$prefLocales = array_reduce(
explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']),
function ($res, $el) {
list($l, $q) = array_merge(explode(';q=', $el), [1]);
$res[$l] = (float) $q;
return $res;
}, []);
arsort($prefLocales);