Skip to content

Instantly share code, notes, and snippets.

View firomero's full-sized avatar

Felix Ivan Romero Rodríguez firomero

View GitHub Profile
@firomero
firomero / json
Created February 1, 2017 21:12
Provincias de Cuba
"Provincias": [{
"id": "1",
"nombre": 'Pinar del Río',
"municipios":["Consolación del Sur", "Guane", "La Palma", "Los Palacios", "Mantua", "Minas de Matahambre", "Pinar del Río", "San Juan y Martínez", "San Luis", "Sandino", "Viñales"]
}, {
"id": "2",
"nombre": 'Artemisa',
"municipios":[
"Alquízar", "Artemisa", "Bauta", "Caimito", "Guanajay", "Güira de Melena", "Mariel", "San Antonio de los Baños", "Bahía Honda", "San Cristóbal", "Candelaria"]
}, {
@firomero
firomero / uncentered-search.php
Created August 28, 2015 12:53
Binary Search Uncentered Callback
/**
* Binary Search Uncentered with Callback
* This is the method of binary search calculating the exact pivote for the search.
* @param array $haystack
* @param $first
* @param $last
* @param $needle
* @param callable $callback
* @return bool
*/
@firomero
firomero / uncentered-binary.php
Created August 28, 2015 12:51
Uncentered Binary Search
/**
* Binary Search Uncentered
* This is the method of binary search calculating the exact pivote for the search.
* @param array $haystack
* @param $first
* @param $last
* @param $needle
* @return bool
*/
function binary_search_uncentered(array $haystack, $first, $last,$needle){
@firomero
firomero / object_unique
Created August 28, 2015 12:49
Array unique in Objects
/**
* Array unique in object
* @param $obj
* @return mixed
*/
function object_unique($obj)
{
$objArray = (array)$obj;
$objArray = array_intersect_assoc(array_unique($objArray), $objArray);
@firomero
firomero / auc.php
Created August 28, 2015 12:48
array_unique_callback
/**
* Array unique callback
* @param array $arr
* @param callable $callback
* @param bool $strict
* @return array
*/
function array_unique_callback(array $arr, callable $callback, $strict = false)
{
return array_filter(
@firomero
firomero / qsort
Created June 1, 2015 03:34
quickSort
<?php
function quicksort( $array ) {
if( count( $array ) < 2 ) {
return $array;
}
$left = $right = array( );
reset( $array );
$pivot_key = key( $array );
@firomero
firomero / binaryS
Created June 1, 2015 03:32
BinarySearch
<?php
/*
* Parameters:
* $a - The sort array.
* $first - First index of the array to be searched (inclusive).
* $last - Last index of the array to be searched (exclusive).
* $key - The key to be searched for.
* $compare - A user defined function for comparison. Same definition as the one in usort