Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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: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 / 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 / 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 / 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'),
);
}