Skip to content

Instantly share code, notes, and snippets.

View silasrm's full-sized avatar

Silas Ribas Martins silasrm

View GitHub Profile
@silasrm
silasrm / 1-Readme.md
Created December 1, 2015 03:23 — forked from FlYos/1-Readme.md
Redirection user by roles after login/logout in symfony2

Description of this Gist

This is the how to for redirection implementation by roles after login or logout in Symfony2

Step

  1. Copy AfterLoginRedirection.php and AfterLogoutRedirection.php to your bundle under the "Redirection" directory
  2. Edit your services.yml file in your bundle and copy/paste the content of services.yml
  3. Edit your security.yml file...
  4. ... add success_handler: redirect.after.login in form_login: section
  5. ... add success_handler: redirect.after.logout in logout: section
@silasrm
silasrm / 1. infrastructure.php
Created November 30, 2015 21:09 — forked from Koc/1. infrastructure.php
Doctrine2 bulk inserts
<?php
use Doctrine\ORM\Persisters;
class DoctrineHelper
{
protected $entityManagers = array();
public function bulkCommit(EntityManager $em, array $entities)
{
@silasrm
silasrm / wp-query-ref.php
Created September 29, 2015 21:48 — forked from luetkemj/wp-query-ref.php
WP: Query $args
<?php
/**
* WordPress Query Comprehensive Reference
* Compiled by luetkemj - luetkemj.com
*
* CODEX: http://codex.wordpress.org/Class_Reference/WP_Query#Parameters
* Source: https://core.trac.wordpress.org/browser/tags/3.9/src/wp-includes/query.php
*/
$args = array(
@silasrm
silasrm / jquery-textarea-form-submit-cmd-enter.js
Last active September 18, 2015 04:41 — forked from alexkingorg/jquery-textarea-form-submit-cmd-enter.js
Submit a form on Command+Enter when in a textarea field.
jQuery(function($) {
// add a handler for form submit (makes an AJAX call)
$(document).on('submit', 'form.my-class', myFormSubmitHandler);
// submit form on command + enter if in a textarea
$(document).on('keydown', 'body', function(e) {
if (!(e.keyCode == 13 && e.metaKey)) return;
var $target = $(e.target);
if ($target.is('textarea')) {
@silasrm
silasrm / redis_
Last active August 29, 2015 14:27 — forked from colinmollenhour/redis_
Munin plugin for Redis with added options
#!/usr/bin/perl -w
#
## Copyright (C) 2011 Colin Mollenhour <http://colin.mollenhour.com/>
##
## This program is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License
## as published by the Free Software Foundation; version 2 dated June,
## 1991.
##
@silasrm
silasrm / CpfCnpj.php
Last active August 29, 2015 14:24 — forked from afranioce/CpfCnpj.php
<?php
namespace Obras\Bundle\CadastroBundle\Validator\Constraints;
use Symfony\Component\Validator\Constraint;
/**
* @Annotation
* @Target({"PROPERTY", "METHOD", "ANNOTATION"})
*
@silasrm
silasrm / Form.php
Last active August 29, 2015 14:24 — forked from jgornick/Form.php
<?php
// ...
$this->addElementPrefixPath('My_Validate', 'My/Validate/', 'validate');
$this->addElement('text', 'start_time', array(
'label' => 'Start Time (GMT)',
'class' => 'datetime',
'required' => true,
'validators' => array(
/*
verifica_cpf_cnpj
Verifica se é CPF ou CNPJ
@see http://www.tutsup.com/
*/
function verifica_cpf_cnpj ( valor ) {
// Garante que o valor é uma string
@silasrm
silasrm / cap-first.sql
Created November 26, 2014 22:38
Função para MySQL para mudar a caixa do texto para Título (CamelCase) Ref: http://joezack.com/2008/10/20/mysql-capitalize-function/
DELIMITER $$
CREATE FUNCTION CAP_FIRST (input VARCHAR(255))
RETURNS VARCHAR(255)
DETERMINISTIC
BEGIN
DECLARE len INT;
DECLARE i INT;
@silasrm
silasrm / Meu\AppBundle\EventListener\UploadListener.php
Last active November 9, 2017 14:52
Listener de upload para OneupUploaderBundle que integra com Plupload.
<?php
namespace Meu\AppBundle\EventListener;
use Oneup\UploaderBundle\Event\PostPersistEvent;
class UploadListener
{
protected $service;