Skip to content

Instantly share code, notes, and snippets.

View gravataLonga's full-sized avatar
🤓
Zig Nerding

Jonathan Fontes gravataLonga

🤓
Zig Nerding
View GitHub Profile
@gravataLonga
gravataLonga / view_helper.php
Created December 17, 2011 18:18
view system of MVC framework
<?php
// Function similar of MVC sistem
function view ( $file , $data = null){
// IF data different of null and diferrent than array
if($data!= NULL && !is_array($data)){
// Erro, expection.
throw new Exception('Data view isn\'t valid!');
return false;
}
@gravataLonga
gravataLonga / image_ratio_helper.php
Last active September 28, 2015 20:18
aspect ratio of an image
<?php
// Exists functions gmp_gcd ?
if(!function_exists('gmp_gcd')){
// No, so create
// find greatest common divisor
function gmp_gcd($a, $b) {
while ($b != 0)
$remainder = $a % $b;
$a = $b;
@gravataLonga
gravataLonga / mit licence
Created September 8, 2012 20:37
MIT Licence
(c) Copyright 2012 Jonathan Fontes.
Licensed under the MIT license:
http://www.opensource.org/licenses/mit-license.php
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@gravataLonga
gravataLonga / sample.php
Last active December 18, 2015 13:09
site_url in php.
<?php
require 'site_url.php';
echo site_url(array('blog','como-criar-url'));
// output: http://www.jonathanfontes.pt/blog/como-criar-url
echo site_url('blog/como-criar-url');
// output: http://www.jonathanfontes.pt/blog/como-criar-url
@gravataLonga
gravataLonga / genPassword.php
Last active April 9, 2016 14:38
Generate a random Password
<?php
function generatePassword ($length = 8) {
$password = "";
$possible = "2346789bcdfghjkmnpqrtvwxyzBCDFGHJKLMNPQRTVWXYZ";
$maxlength = strlen($possible);
// check for length overflow and truncate if necessary
if ($length > $maxlength) {
$length = $maxlength;
@gravataLonga
gravataLonga / Exception
Created November 1, 2013 11:45
Exception php
<?php
interface IException
{
/* Protected methods inherited from Exception class */
public function getMessage(); // Exception message
public function getCode(); // User-defined Exception code
public function getFile(); // Source filename
public function getLine(); // Source line
public function getTrace(); // An array of the backtrace()
public function getTraceAsString(); // Formated string of trace
@gravataLonga
gravataLonga / cleanUrl.php
Last active April 9, 2016 14:38
Clean URL
<?php
function cleanForShortURL($toClean) {
$charactersToRemove = array(
'Š'=>'S', 'š'=>'s', 'Ð'=>'Dj','Ž'=>'Z', 'ž'=>'z', 'À'=>'A', 'Á'=>'A', 'Â'=>'A', 'Ã'=>'A', 'Ä'=>'A',
'Å'=>'A', 'Æ'=>'A', 'Ç'=>'C', 'È'=>'E', 'É'=>'E', 'Ê'=>'E', 'Ë'=>'E', 'Ì'=>'I', 'Í'=>'I', 'Î'=>'I',
'Ï'=>'I', 'Ñ'=>'N', 'Ò'=>'O', 'Ó'=>'O', 'Ô'=>'O', 'Õ'=>'O', 'Ö'=>'O', 'Ø'=>'O', 'Ù'=>'U', 'Ú'=>'U',
'Û'=>'U', 'Ü'=>'U', 'Ý'=>'Y', 'Þ'=>'B', 'ß'=>'Ss','à'=>'a', 'á'=>'a', 'â'=>'a', 'ã'=>'a', 'ä'=>'a',
'å'=>'a', 'æ'=>'a', 'ç'=>'c', 'è'=>'e', 'é'=>'e', 'ê'=>'e', 'ë'=>'e', 'ì'=>'i', 'í'=>'i', 'î'=>'i',
<?php
/* ---------------------------------------------------------- */
/* minibots.class.php Ver.1.9g */
/* ---------------------------------------------------------- */
/* Mini Bots class is a small php class that allows you to */
/* use some free web seriveces online to retrive usefull data */
/* and infos. This version includes: */
/* smtp validation, check spelling, meteo, exchange rates, */
/* shorten urls, and geo referencing with IP address and more */
/* Feel free to use in your applications, but link my blog: */
function emptySet(x) {
return false;
}
function insert(elem, set) {
return function(x) {
if (x === elem) { // insert smarter comparison here if needed
return true;
}
return function() { return contains(x, set); };
@gravataLonga
gravataLonga / output.php
Last active April 28, 2017 19:30
output cli function
<?php
function output ( $str, $tabs = 0, $date = TRUE, $silent = FALSE )
{
// Silent echo's
if( !empty($silent))
{
return FALSE;
}
if( is_array($str))