Skip to content

Instantly share code, notes, and snippets.

@akovalyov
akovalyov / gist:5705639
Created June 4, 2013 12:49
filtering function for collections of objects for twig
use Doctrine\Common\Collections\Collection;
use Symfony\Component\PropertyAccess\PropertyAccess;
public function getFilters()
{
return array(
'sortCollection' => new \Twig_Filter_Method($this, 'sortCollection'),
);
}
@akovalyov
akovalyov / WebHelper.php
Last active December 18, 2015 16:09
Selenium interaction with Chozen plugin in Codeception
<?php
namespace Codeception\Module;
// here you can define custom functions for WebGuy
/**
* Class WebHelper
* @package Codeception\Module
*/
class WebHelper extends \Codeception\Module
@akovalyov
akovalyov / preventDoubleSubmit.js
Last active December 19, 2015 05:59
simple jquery snippet for preventing double submits in form
(function (jQuery) {
/**
* prevents double submits
*
* usage
*
* just fire on document.ready, i.e.
* $(function(){
* $.preventDoubleSubmit()
* });
@akovalyov
akovalyov / gist:6421406
Last active December 22, 2015 05:08
accessing private properties of parent class which are set in the parent constructor. With php 5.3
function __construct($someProperty)
{
$className = get_parent_class($this);
$reflection = new \ReflectionClass($className);
if (version_compare(phpversion(), '5.4', '<')) {
$instance = new \ReflectionObject(unserialize(
sprintf('O:%d:"%s":0:{}', strlen($className), $className)
));
} else {
$instance = $reflection->newInstanceWithoutConstructor();
@akovalyov
akovalyov / satis.json
Created October 24, 2013 12:28
satis config
{
"name": "My local Repository",
"homepage": "http://satis.dev",
"repositories": [
{"type": "vcs", "url": "http://github.com/symfony/symfony"},
{"type": "vcs", "url": "https://github.com/symfony/AsseticBundle"},
{"type": "vcs", "url": "https://github.com/symfony/SwiftmailerBundle"},
{"type": "vcs", "url": "https://github.com/symfony/MonologBundle"},
{"type": "vcs", "url": "https://github.com/symfony/PropertyAccess"},
{"type": "vcs", "url": "https://github.com/symfony/Icu"},
@akovalyov
akovalyov / gist:7677179
Last active December 29, 2015 13:29
get all constraints from mysql
-- helps to debug strange errors like General error: 1005 Can't create table '$some_db.#sql-186d_71' (errno: 121)
-- usually it happens whem you manually rename a table and schema is generated via a tool
-- need to execute also
-- ALTER TABLE `$table`
-- DROP FOREIGN KEY `old_key`,
-- ADD CONSTRAINT `new_key` FOREIGN KEY (field) REFERENCES $table2(id);
SELECT
constraint_name,
table_name
FROM
@akovalyov
akovalyov / pre-commit
Last active September 7, 2016 14:33 — forked from cgmartin/pre-commit
Global hook - git config --global init.templatedir '~/.git_template'
#!/usr/bin/env php
<?php
/**
* .git/hooks/pre-commit
*
* This pre-commit hooks will check for PHP errors (lint), and make sure the
* code is PSR-2 compliant.
*
* Dependecy: PHP-CS-Fixer (https://github.com/fabpot/PHP-CS-Fixer)
*/
@akovalyov
akovalyov / FeatureContext.php
Created July 23, 2014 23:07
Behat redirects
<?php
namespace Context;
use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Knp\FriendlyContexts\Context\RawPageContext;
class FeatureContext extends RawPageContext implements Context, SnippetAcceptingContext
{
@akovalyov
akovalyov / gnome-screenshot
Created April 9, 2015 20:41
Take screenshot, upload it to your owncloud instance immediately, set share time to 24 hours and push the link of the shared screenshot to the clipboard. It assumes that you move the original gnome-screenshot tool from /usr/bin/gnome-screenshot to /usr/bin/gnome-screenshot.bin and put this shell script to /usr/bin/gnome-screeshot. Sorry, there i…
#!/bin/bash
USER="!!!USER!!!" #changeme
PASSWORD="!!!PASSWORD!!!" #changeme
URL="!!!DOMAIN!!!" #changeme
SCHEME="!!!https or http!!!" #changeme
SCREENS_DIR=Screenshots #changeme or not
YEAR=$(date +"%Y")
NOW=$(date +"%m_%d_%s")
@akovalyov
akovalyov / console.php
Last active August 29, 2015 14:21
Symfony2 console with docker
#!/usr/bin/env php
<?php
// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
set_time_limit(0);
const DOCKER_CONTAINER_NAME = 'app_phpfpm_1';