Skip to content

Instantly share code, notes, and snippets.

@rodurma
rodurma / sql-get-frieds-like.sql
Last active December 14, 2015 16:19
Pegar o id das páginas que seus amigos curtiram no facebook
SELECT uid, page_id, created_time FROM page_fan WHERE uid IN (SELECT uid2 FROM friend WHERE uid1 = ##)
# infos
# https://developers.facebook.com/docs/reference/fql/page_fan/
@rodurma
rodurma / gist:5337132
Created April 8, 2013 14:22
Exemplo de paginação
<ul>
<li><a href="/vendedores/?p=19"><<</a></li>
<li><a href="/vendedores/?p=1">1</a></li>
<li><a href="/vendedores/?p=2">2</a></li>
<li class="disabled"><a href="#">...</a></li>
<li><a href="/vendedores/?p=17">17</a></li>
<li><a href="/vendedores/?p=18">18</a></li>
@rodurma
rodurma / gist:5509536
Last active December 16, 2015 22:49
Fazendo login normal com laravel, caso falhar tenta com o hash antigo. Ideal para quando está migrando sites antigos para o framework Laravel
<?php
if (Auth::attempt($data))
{
// .. do your redirect
}
elseif ($user = User::where_email($data['email'])->first() and $user->password == md5($data['password']))
{
$user->password = Hash::make($data['password']);
$user->save();
@rodurma
rodurma / gist:6053651
Created July 22, 2013 12:59
Criar uma slug com o id do próprio registro no banco de dados.
DELIMITER $$
CREATE TRIGGER `create_slug` BEFORE INSERT
ON `slugs`
FOR EACH ROW
BEGIN
SET new.id = (SELECT MAX(id) FROM slugs) + 1;
SET new.slug = CONCAT(new.slug, "-", new.id);
END$$
DELIMITER ;
@rodurma
rodurma / gist:6053661
Last active December 20, 2015 02:08
Cria uma trigger para criar slugs e não deixar elas se repetirem
drop trigger if exists changeSlug;
delimiter |
CREATE TRIGGER changeSlug BEFORE INSERT ON slug2
FOR EACH ROW BEGIN
declare original_slug varchar(255);
declare slug_counter int;
set original_slug = new.slug;
set slug_counter = 1;
@rodurma
rodurma / gist:6221604
Created August 13, 2013 14:25
Pegando um valor de uma ação através do site da BMF Bovespa
// link: http://www.bmfbovespa.com.br/Pregao-online/ExecutaAcaoCotRapXSL.asp?gstrCA=&txtCodigo=VALE5&intIdiomaXsl=0
// jquery xpath
$('.tdValor:eq(1)').html().replace(/(\r\n|\n|\r| |R\$ )/gm,"").replace(",",".");
// Com PHP e PHPQuery
include "phpQuery.php";
function acao($papel){
@rodurma
rodurma / QueryLogController.php
Created August 27, 2013 13:43
Lista as querys feitas no banco de dados no CakePHP 1.3 dentro de um Controller.
<?php
$log = $this->Pedido->getDataSource()->getLog(false, false);
debug($log);
?>
@rodurma
rodurma / php-excel.class.php
Created September 5, 2013 16:51
Criando um arquivo excel simples.
<?php
/**
* Simple excel generating from PHP5
*
* @package Utilities
* @license http://www.opensource.org/licenses/mit-license.php
* @author Oliver Schwarz <[email protected]>
* @version 1.0
*/

My Validation Base Class

I was asked how I deal with validation / create and update validation rulesets. Well here is one method I have used. Don't be afraid to build on top of what the framework has already given you. In my projects I use a base class for almost anything. You never know when you want your classes to inherit some common functionality. My BaseValidator actually has some pretty useful methods and properties in it.

<?php

namespace FooProject\Internal\Validators;

use FooProject\Internal\Sanitizers\BaseSanitizer;
@rodurma
rodurma / html-jquery.html
Last active August 29, 2015 14:03
HTML5 With Jquery
<!DOCTYPE HTML>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>Page Titel</title>
<link rel="stylesheet" type="text/css" href="estilo.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
</head>
<body>