Skip to content

Instantly share code, notes, and snippets.

@gtrias
gtrias / routing.yml
Last active September 8, 2015 15:27 — forked from mikeemoo/routing.yml
Catch all routing symfony2
LowpressWordpressBundle_homepage:
pattern: /{url}
defaults: { _controller: LowpressWordpressBundle:Default:index }
requirements:
url: ".*"
@gtrias
gtrias / handlebars.striptags.js
Last active August 29, 2015 14:28 — forked from tracend/handlebars.striptags.js
striptags() #handlebars #helper #cc
// This doesn't work for me
Handlebars.registerHelper("striptags", function( txt ){
// exit now if text is undefined
if(typeof txt == "undefined") return;
// the regular expresion
var regexp = new RegExp('#([^\\s]*)','g');
// replacing the text
return txt.replace(regexp, '');
});
@gtrias
gtrias / README.md
Last active February 9, 2016 12:29 — forked from tjamps/README.md
Basic RESTful API with Symfony 2 + FOSRestBundle (JSON format only) + FOSUserBundle + FOSOauthServerBundle

Basic RESTful API with Symfony 2 + FOSRestBundle (JSON format only) + FOSUserBundle + FOSOauthServerBundle

The API we are creating in this gist will follow these rules :

  • The API only returns JSON responses
  • All API routes require authentication
  • Authentication is handled via OAuth2 with password Grant Type only (no need for Authorization pages and such).
  • API versioning is managed via a subdomain (e.g. v1.api.example.com)

The API will be written in PHP with the Symfony 2 framework. The following SF2 bundles are used :

@gtrias
gtrias / vim74_lua
Last active August 29, 2015 14:16 — forked from jdewit/vim74_lua
sudo apt-get remove --purge vim vim-runtime vim-gnome vim-tiny vim-common vim-gui-common
sudo apt-get build-dep vim-gnome
sudo apt-get install liblua5.1-dev luajit libluajit-5.1 python-dev ruby-dev libperl-dev mercurial libncurses5-dev libgnome2-dev libgnomeui-dev libgtk2.0-dev libatk1.0-dev libbonoboui2-dev libcairo2-dev libx11-dev libxpm-dev libxt-dev
sudo rm -rf /usr/local/share/vim
sudo rm /usr/bin/vim
<?php
/**
* Translates a camel case string into a string with
* underscores (e.g. firstName -> first_name)
*
* @param string $str String in camel case format
* @return string $str Translated into underscore format
*/
function from_camel_case($str) {
$str[0] = strtolower($str[0]);
<?php
public function process(ContainerBuilder $container)
{
$factory = $container->findDefinition('app.doctrine.repository.factory');
$repositories = [];
foreach ($container->findTaggedServiceIds('app.repository') as $id => $params) {
foreach ($params as $param) {
$repositories[$param['class']] = $id;
<?php
namespace WSL\BaseBundle\Util\Helper;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Security\Acl\Permission\MaskBuilder;
/*
* To change this template, choose Tools | Templates
<?php
namespace Acme\UserBundle\Entity;
use Doctrine\ORM\EntityRepository;
use Doctrine\ORM\Query\Expr;
/**
* UserRepository
*
<?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
{
<?php
namespace Acme\Bundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;