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: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 / 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: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 / 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: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 / crontab
Created March 13, 2013 14:21
Auto-deployment.
*/15 * * * * sh /home/rafael/projects/deployment/deploy-projects
@fael
fael / functions.php
Created August 14, 2013 05:16
Get adjacent posts from a term of a custom taxonomy
<?php
function next_prev_portfolio($post, $current_term){
//echo '<pre>';
$postlist_args = array(
'posts_per_page' => -1,
//'orderby' => 'menu_order title',
//'order' => 'ASC',
'post_type' => 'portfolio',
'portfolio_category' => $current_term
);
// bling.js
var $ = window.$ = document.querySelector.bind(document);
var $$ = window.$$ = document.querySelectorAll.bind(document);
Node.prototype.on = window.on = function(name, fn) {
this.addEventListener(name, fn);
}
NodeList.prototype.__proto__ = Array.prototype;
NodeList.prototype.on = NodeList.prototype.addEventListener = (function(name, fn) {
this.forEach(function(elem) {
elem.on(name, fn);
@fael
fael / App.js
Created September 22, 2017 16:28
Async Component Loading for React
// @flow
import React, { Component } from 'react'
import { BrowserRouter, Route, Switch } from 'react-router-dom'
import asyncComponent from './asyncComponent'
const MyAwesomePage = asyncComponent(() => import('./MyAwesomePage'))
/**
* Main Component, displays App Shell UI, setup routes which are dynamically loaded
*/
@fael
fael / README.md
Created September 24, 2017 01:38
Fat arrow / ligature in Fira Code font for Visual Studio
  1. Install this VSCode Extension https://marketplace.visualstudio.com/items?itemName=be5invis.vscode-custom-css

  2. Create a CSS in a place like so ~/Users/you/vscode.css

  3. Paste the lines of file below

  4. Go to Settings to change some settings like so:

    "editor.fontLigatures": true, "editor.fontFamily": "Operator Mono", "editor.fontSize": 13, "vscode_custom_css.imports": [ "file:///Users/rafael/vscode.css"