Skip to content

Instantly share code, notes, and snippets.

View lleitep3's full-sized avatar
🏠
Working from home

Leandro (Hey Man) lleitep3

🏠
Working from home
View GitHub Profile
@lleitep3
lleitep3 / bootstrap.php
Created May 16, 2011 13:05
my default bootstrap
<?php
session_start();
date_default_timezone_set ('America/Sao_Paulo');
define ('DS', DIRECTORY_SEPARATOR);
define ('URL', "http://".$_SERVER['SERVER_NAME']);
define ('ENVIRONMENT' , 'DEV');
spl_autoload_register('autoload');
@lleitep3
lleitep3 / index.php
Created May 16, 2011 13:44
by default, I always keep the page as the first parameter of the uri.
<?php
$uriPath = parse_url ($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$uriPath = explode('/', trim($uriPath, '/') );
$page = reset($uriPath);
require $page . '.php';
@lleitep3
lleitep3 / .htaccess
Created May 16, 2011 13:48
this'. htaccess' I need to define the controller name by 'index.php'
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !(css|js|jpg|png) ./index.php
@lleitep3
lleitep3 / strRand.php
Created May 25, 2011 01:01
randomic string generator
<?php
function strRand($qtd)
{
$chars = implode(array_merge(range(0, 9),range('A', 'Z'),range('a', 'z')));
return substr(str_shuffle($chars), 0, $qtd);
}
$str = strRand(5);
echo "look: " . $str;
@lleitep3
lleitep3 / copyDir.php
Created June 7, 2011 14:57
copy a folder
<?php
function copyDir($source,$destination)
{
if(!is_dir($destination))
mkdir($destination, 0777);
chmod($destination, 0777);
$it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source),
\RecursiveIteratorIterator::SELF_FIRST);
@lleitep3
lleitep3 / listEncodingPath.pgp
Created June 17, 2011 02:31
get encoded by files of directory
<?php
function listEncodingPath($path)
{
$finfo = new finfo(FILEINFO_MIME_ENCODING, "/usr/share/misc/magic");
foreach(new DirectoryIterator($path) as $file)
if(!$file->isDot() && !$file->isDir())
$return[$file->getBasename()] = $finfo->file($file->getPathname());
return $return;
}
@lleitep3
lleitep3 / developerquiz.php
Created August 9, 2011 20:28 — forked from alganet/developerquiz.php
Full script for the Google Developer Day Quiz (http://developerquiz.appspot.com) in 39 lines
<?php //Run as command line. Input file as first argument.
const G_FOO = 'aeiou'; //Googlon special letters
const G_INV = 'z'; //Preposition invalidator
const G_PREP = 3; //Preposition size
const G_VERB = 8; //Verb size
const G_ORDER = 'qnbczxjtklmvhrwfsdgp'; //Letter ordering
const G_NUM_MOD = 4; //Pretty number divisor
const G_NUM_MAX = 526593; //Pretty number minimum
$textB = explode(' ', file_get_contents($argv[1]));
@lleitep3
lleitep3 / LateStaticBindingsSolution.php
Created August 10, 2011 13:49
Late Static Bindings
<?php
class A {
public static function who() {
echo get_called_class();
}
public static function whoParent() {
echo get_parent_class(get_called_class());
}
@lleitep3
lleitep3 / ascii2entities.php
Created March 17, 2012 16:09
ascii2entities
<?php
// encontrada nesse link
// http://www.php.net/manual/en/function.htmlentities.php
function ascii2entities($string){
for($i=128;$i<=255;$i++){
$entity = htmlentities(chr($i), ENT_QUOTES, 'cp1252');
$temp = substr($entity, 0, 1);
$temp .= substr($entity, -1, 1);
@lleitep3
lleitep3 / deleteDir.php
Created October 9, 2012 13:42
delete some folder recursive
<?php
function deleteDir($source)
{
if(!is_dir($source))
return false;
$it = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($source),
\RecursiveIteratorIterator::SELF_FIRST);
$it->next();