Skip to content

Instantly share code, notes, and snippets.

Michael Pratt mpratt

Block or report user

Report or block mpratt

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@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
*/
@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 / 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 / Ejemplo1.php
Last active Oct 12, 2016
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();
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
View decorator1.php
<?php
class Damage
{
protected $name;
protected $damagePoints = 10;
public function __construct($name)
{
$this->name = $name;
}
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;
@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) */
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 Teorema-del-Coseno.sql
SELECT id, nombre, (6371 * ACOS(
SIN(RADIANS(lat)) * SIN(RADIANS(4.6665578))
+ COS(RADIANS(lng - -74.0524521)) * COS(RADIANS(lat))
* COS(RADIANS(4.6665578))
)
) AS distance
FROM direcciones
HAVING distance < 1 /* 1 KM a la redonda */
ORDER BY distance ASC
You can’t perform that action at this time.