Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Pratt mpratt

View GitHub Profile
@mpratt
mpratt / Tenso.php
Created Jul 20, 2012
Aprendiendo con Memes: Tenso | Learning with Memes: Tenso Image Generator | URL: http://www.michael-pratt.com/blog/9/Aprendiendo-con-Memes-Tenso/
View Tenso.php
<?php
/**
* Tenso.php
*
* @author Michael Pratt <pratt@hablarmierda.net>
* @version 1.0
* @link http://www.michael-pratt.com/blog/9/Aprendiendo-con-Memes-Tenso/
* @demo http://www.michael-pratt.com/Lab/tenso/
*
* @License: MIT
@mpratt
mpratt / anonima.php
Last active Dec 16, 2015
De PHP 5.1 a 5.5
View anonima.php
<?php
// Tenemos un arreglo con números
$misNumeros = array('1', '2', '3', '4', '5', '6');
/* Pero resulta que solo queremos los numeros impares,
así que usamos array_filter con una función anonima,
en vez de declarar la funcion antes. */
print_r(array_filter($misNumeros, function($n) { return ($n%2 != 0); }));
/* Resulta en: Array([0] => 1, [2] => 3, [4] => 5) */
@mpratt
mpratt / Mailer.php
Last active Dec 31, 2015
A simple Mailer class
View Mailer.php
<?php
/**
* Mailer.php
*
* @author Michael Pratt <pratt@hablarmierda.net>
* @link http://www.michael-pratt.com/
* @license MIT
*/
namespace Mailer;
@mpratt
mpratt / Random.php
Created Dec 12, 2013
A random number/range/string/bool generator
View Random.php
<?php
/**
* Random.php
*
* @author Michael Pratt <pratt@hablarmierda.net>
* @link http://www.michael-pratt.com/
* @license MIT
*
*/
@mpratt
mpratt / Session.php
Last active Apr 14, 2016
A wrapper for session management
View Session.php
<?php
/**
* Session.php
*
* @package Bolido
* @author Michael Pratt <pratt@hablarmierda.net>
* @link http://www.michael-pratt.com/
* @license MIT
*/
View ImageManager.php
<?php
/**
* ImageManager.php
* A wrapper around GD that does multiple operations like, resizing, rotating,
* cropping and stuff.
*
* @author Michael Pratt <pratt@hablarmierda.net>
* @version 1.0
* @link http://www.michael-pratt.com/
* @demo http://www.michael-pratt.com/Lab/imageManager/
View dependency1.php
<?php
class Logger
{
protected $file;
public function __construct($file) { $this->file = $file; }
public function log($message)
{
$message = date('H:i:s ') . $message . PHP_EOL;
View decorator1.php
<?php
class Damage
{
protected $name;
protected $damagePoints = 10;
public function __construct($name)
{
$this->name = $name;
}
View AuthBcrypt.php
<?php
$nombre = $_POST['nombre'];
$password = $_POST['pass'];
// Validamos $nombre, bla bla bla..
// Extraemos el hash de la base de datos
$db = new PDO(......);
$stmt = $db->prepare('SELECT pass
FROM usuarios
@mpratt
mpratt / Ejemplo1.php
Last active Jan 12, 2020
Patrones de Diseño: Observador (Observer)
View Ejemplo1.php
<?php
/**
* Clase Partido
* En este caso este es nuestro sujeto
*/
class Partido implements \SplSubject
{
protected $teams = array();
protected $observers = array();
You can’t perform that action at this time.