Skip to content

Instantly share code, notes, and snippets.

@SofHad
SofHad / .vim_cheat_cheet.md
Last active December 22, 2015 09:42
VIM Cheat sheet #vim

Cursor movement

h - move left
j - move down
k - move up
l - move right
ctrl-b - page up
ctrl-f - page down

% - jump to matching brace

@SofHad
SofHad / git-alias
Created February 19, 2015 11:33
Git alias
alias.co checkout
alias.ci commit
alias.rb rebase
alias.st status
alias.br branch
alias.submodule-pull-all submodule foreach git pull --all
alias.submodule-fetch-all submodule foreach git fetch --tags
alias.sup submodule update --init --recursive
alias.lol log --graph --decorate --pretty=oneline --abbrev-commit
alias.lola log --graph --decorate --pretty=oneline --abbrev-commit --all
# Symfony 2
alias sf='php app/console'
alias sf-vendors='php bin/vendors update'
alias sf-db='sf doctrine:database:drop --force && sf doctrine:database:create && sf doctrine:schema:update --force'
alias sf-fixtures='sf doctrine:fixtures:load'
alias sf-cc='rm -rf app/cache/* && rm -rf app/logs/* && sf cache:clear'
alias sf-assets='rm -rf web/bundles/* && sf assets:install --symlink web'
alias sf-acl='sudo setfacl -R -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs && sudo setfacl -dR -m u:www-data:rwx -m u:`whoami`:rwx app/cache app/logs'
# Widop Fixtures Bundle
# Symfony aliases
## Cache
alias sf_cache_clear="php app/console cache:clear" # Clears the cache
alias sf_cache_warmup="php app/console cache:warmup" # Warms up an empty cache
## Doctrine
alias sf_doctrine_="php app/console doctrine:cache:clear-metadata" # Clears all metadata cache for a entity manager
alias sf_doctrine_="php app/console doctrine:cache:clear-query" # Clears all query cache for a entity manager
alias sf_doctrine_="php app/console doctrine:cache:clear-result" # Clears result cache for a entity manager
alias sf_doctrine_="php app/console doctrine:database:create" # Creates the configured databases

PHPUnit API reference

  • version 3.6
<?php
require_once dirname(__DIR__).'/../../../../app/AppKernel.php';
/**
* Test case class helpful with Entity tests requiring the database interaction.
* For regular entity tests it's better to extend standard \PHPUnit_Framework_TestCase instead.
*/
abstract class KernelAwareTest extends \PHPUnit_Framework_TestCase
{
@SofHad
SofHad / in_array_multidimensional_array.php
Created October 31, 2013 09:08
in_array() and multidimensional array
public function inMultiDimensionalArray($needle, $haystack, $strict = false) {
foreach ($haystack as $item) {
if (($strict ? $item === $needle : $item == $needle) || (\is_array($item) && $this->inMultidimensionalArray($needle, $item, $strict))) {
return true;
}
}
return false;
}
@SofHad
SofHad / gist:6574775
Created September 15, 2013 22:14
Symfony OptionsResolver example of use case
<?php
namespace Demo\FormBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller ;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\HttpKernel\Exception\HttpException;
/**
@SofHad
SofHad / FunctionToCamelizesAString
Created August 16, 2013 11:37
Function to Camelizes a string in PHP
/**
* Camelizes a string.
*
* @param string $id A string to camelize
*
* @return string The camelized string
*/
public static function camelize($id)
{
return strtr(ucwords(strtr($id, array('_' => ' ', '.' => '_ '))), array(' ' => ''));
<?php
namespace RE\AssetBundle\Model;
use Knp\Bundle\GaufretteBundle\FilesystemMap;
use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\EventDispatcher\EventDispatcher;
use Gaufrette\FileStream\Local;