Skip to content

Instantly share code, notes, and snippets.

View angelmartz's full-sized avatar

Juan Angel Martínez Lopez angelmartz

  • CDMX, Mexico
  • 20:48 (UTC -06:00)
View GitHub Profile
@angelmartz
angelmartz / errores.blade.php
Created November 27, 2013 17:04
Errores Laravel
@if ($errors->any())
<div class="alert alert-danger">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<strong>Por favor corrige los siguentes errores:</strong>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
</div>
@angelmartz
angelmartz / diashabiles.php
Last active April 11, 2022 17:11
Obtener días hábiles en PHP
<?php
/**
* Metodo getDiasHabiles
*
* Permite devolver un arreglo con los dias habiles
* entre el rango de fechas dado excluyendo los
* dias feriados dados (Si existen)
*
* @param string $fechainicio Fecha de inicio en formato Y-m-d
* @param string $fechafin Fecha de fin en formato Y-m-d
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
@angelmartz
angelmartz / consulta.sql
Last active December 30, 2015 05:29
MySQL Spatial
SET @center = GeomFromText('POINT(20 20)');
SET @radius = 30;
SET @bbox = CONCAT('POLYGON((',
X(@center) - @radius, ' ', Y(@center) - @radius, ',',
X(@center) + @radius, ' ', Y(@center) - @radius, ',',
X(@center) + @radius, ' ', Y(@center) + @radius, ',',
X(@center) - @radius, ' ', Y(@center) + @radius, ',',
X(@center) - @radius, ' ', Y(@center) - @radius, '))'
);
SELECT name, AsText(location), SQRT(POW( ABS( X(location) - X(@center)), 2) + POW( ABS(Y(location) - Y(@center)), 2 )) AS distance
@angelmartz
angelmartz / symphony.php
Created December 8, 2013 06:21
Slug SEO URL
<?php
static public function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
// trim
$text = trim($text, '-');
// transliterate
<?php
/*
|--------------------------------------------------------------------------
| Cache route filter
|--------------------------------------------------------------------------
|
| This filter must be called 'before' and 'after' any of the front-end
| pages are loaded.
| Before the page is loaded, we return a cached version of the page, if
@angelmartz
angelmartz / gist:7879071
Created December 9, 2013 19:17
cache laravel
Route::filter('cache', function($route, $request, $response = null)
{
$key = 'route-'.Str::slug(Request::url());
if(is_null($response) && Cache::has($key))
{
return Cache::get($key);
}
elseif(!is_null($response) && !Cache::has($key))
{
Cache::put($key, $response->getContent(), 30);
@angelmartz
angelmartz / gist:7916513
Created December 11, 2013 19:11
Base de datos diferente modelo Laravel
// Model
class Client extends Eloquent
{
protected $connection = 'masterDb';
}
// config/database.php
'masterDb' => array(
'driver' => 'mysql',
ugust 23rd 2013
USING LARAVEL 4′S MODEL EVENTS TO CASCADE DELETION
Cascading deletion in Laravel 4 can be accomplished setting up FOREIGN KEY‘s and adding an ->onDelete('cascade') in your Schema.
Read on for an alternative way to cascade a deletion using Events.
Assume you have a Model called Author which has many Books.
@angelmartz
angelmartz / gist:8046466
Created December 19, 2013 21:22
Phalcon instalaciom
git clone git://github.com/phalcon/cphalcon.git
cd cphalcon/build/64bits
make clean
phpize --clean
/usr/local/php/bin/
./configure --with-php-config=/usr/local/php/bin/php-config
make && sudo make install