Skip to content

Instantly share code, notes, and snippets.

View fael's full-sized avatar

Rafael Santos Sá fael

  • OLX
  • Lisbon, Portugal
View GitHub Profile
@fael
fael / gist:4138179
Created November 24, 2012 02:53
Time ago
<?php
function nicetime($date){
if(empty($date)) {
return "No date provided";
}
$periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
$now = time();
@fael
fael / gist:4126068
Created November 21, 2012 17:04
CakePHP Contain Example
$conditions = array(
'conditions' => array('codigo' => '24150'),
'contain' => array(
'Card'=>array(
'Partner' => array (
'Contact' => array(
'conditions' => array('Contact.coords_lat' => '38.710930')
)
)
)
@fael
fael / gist:4111506
Last active August 9, 2017 17:21
Slug Generator that works! JavaScript and PHP
<?php
//ref: http://cubiq.org/the-perfect-php-clean-url-generator
setlocale(LC_ALL, 'en_US.UTF8');
function toAscii($str, $replace=array(), $delimiter='-') {
if( !empty($replace) ) {
$str = str_replace((array)$replace, ' ', $str);
}
$clean = iconv('UTF-8', 'ASCII//TRANSLIT', $str);
@fael
fael / example.controller.php
Created September 11, 2012 13:44
Classe Simples de Paginação
<?php
$count = $model->countAll();
$pages = new Paginator;
$pages->items_total = $count;
$pages->mid_range = 9;
$pages->paginate();
$options['limit'] = $pages->low.', '.($pages->high + 1);
@fael
fael / gist:1507594
Created December 21, 2011 20:38
Converter textos em Imagens, Videos e Links
<?php
$str = 'This is an image: google.ca/images/srpr/logo3w.png<br>
YouTube: http://www.youtube.com/watch?v=V2b8ilapFrI&feature=related <br>
Stackoverflow: http://stackoverflow.com/';
function converterLinksEmVideos($arr){
if(strpos($arr[0], 'http://') !== 0){
@fael
fael / gist:1345338
Created November 7, 2011 15:55
Exemplo de uso de Custom Types do WordPress
//gerado pelo http://themergency.com/generators/cpt-code-output/?id=8966
add_action( 'init', 'register_cpt_atividade' );
function register_cpt_atividade() {
$labels = array(
'name' => _x( 'Atividades', 'atividade' ),
'singular_name' => _x( 'Atividade', 'atividade' ),
'add_new' => _x( 'Adicionar Atividade', 'atividade' ),
@fael
fael / .htaccess
Created November 6, 2011 22:22
Exemplo PHPMailer + Tratamento de erros via HTACCESS + Qualquer console JS
# PHP error handling for production servers
# disable display of startup errors
php_flag display_startup_errors off
# disable display of all other errors
php_flag display_errors off
# disable html markup of errors
php_flag html_errors off
@fael
fael / gist:1296161
Created October 18, 2011 18:04
Another jQuery Pattern Plugin
(function ($) {
$.extend({ //plugins without context. e.g: $.plugin();
firebugLite: function () {
var vars = {
keys: [],
sequence: "68,69,66,85,71",
loaded: false,
serviceURL: 'https://getfirebug.com/firebug-lite.js'
};
@fael
fael / gist:1285038
Created October 13, 2011 18:28
Meu Antigo 'Object' Design Pattern
/* Vantagens:
- Organizador de métodos e propriedades, permite ser estendido por outros arquivos js.
- Utilizar um 'namespace' favorece o melhor consumo de memória (nos antigos IE).
Desvantagens:
- Como não é uma classe e em runtine eu não crio uma instância (new NAP()),
não é possível usar o this dentro de um método do objeto NAP
para invocar outro que também é método do objeto NAP.
*/
@fael
fael / gist:1285003
Created October 13, 2011 18:16
Meu Module Design Pattern
/* Inspirado no post: http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth
Vantagens:
- Permitir a utilização de métodos/propriedades privadas.
- Adicionar metodos ou propriedades ao objeto ProjetoX a partir de outros arquivos js
Desvantagens:
- Como não é uma classe e em runtine eu não crio uma instância (new NAP()),
não é possível usar o this dentro de um método do objeto NAP
para invocar outro que também é método do objeto NAP.