Skip to content

Instantly share code, notes, and snippets.

View jfreites's full-sized avatar

Jonathan Freites jfreites

View GitHub Profile
@jfreites
jfreites / ApiResponse.php
Last active December 8, 2024 15:09
Laravel API response trait
<?php
namespace App\Traits\Http;
use Error;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Validation\ValidationException;
@jfreites
jfreites / FilterBuilder.php
Last active December 8, 2024 15:14
Filtering request in Laravel
<?php
namespace App\Support\Filters;
use Illuminate\Database\Eloquent\Builder;
final class FilterBuilder
{
public function __construct(protected Builder $query, protected array $filters, protected string $namespace)
{
@jfreites
jfreites / demo.txt
Created December 7, 2017 00:29
codecourse-databable
This is the example for my (ugly maybe) solution:
- My controller extends from DataTableController as usual, using the builder and getDisplayableColumns methods
class AdminUsersController extends DataTableController
{
public function builder()
{
return Admin::query();
}
@jfreites
jfreites / php-installation.sh
Last active April 5, 2017 21:09
PHP installation script
PHP_TARGET_VERSION=5.4.32
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
wget http://ca.php.net/get/php-$PHP_TARGET_VERSION.tar.gz/from/this/mirror -O php-$PHP_TARGET_VERSION.tar.gz
tar -xzf php-$PHP_TARGET_VERSION.tar.gz
@jfreites
jfreites / gist:89141ff4ebface7a7925eeebdfa5b459
Created November 18, 2016 16:26
Imprimir todas las diagonales de una matriz
for ($i = 0; $i < $rows; $i++) {
for ($j = 0; $j < $cols; $j++) {
if ($i == $j) {
$res .= $arr[$i][$j].'/n';
}
if ($i == ($cols - $j - 1)) {
$res .= $arr[$i][$j];
}
}
@jfreites
jfreites / multiple-php-versions.sh
Last active February 20, 2020 16:04
Multiple PHP Versions
#!/bin/bash
# @author OSOM-IT
echo " php switcher "
version=$1
if [[ "70" -ne version && "56" -ne version && "0" -ne version ]]
then
echo "You must specify php version (70, 56)"
exit 1 else
if [[ "0" -ne version ]]
@jfreites
jfreites / memp_setup.md
Last active August 9, 2023 09:27
MEMP Stack: setup Nginx, PHP and MySQL on Mac

Setup a MEMP Stack

MacOSX + Nginx + MySQL + PHP. Tested with El Capitan

Install Homebrew:

run on terminal:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
brew doctor
@jfreites
jfreites / gist:a6cee5768f53fa022eb7
Created October 22, 2014 18:22
Check errors uploading file
$message = 'Error uploading file';
switch( $_FILES['file']['error'] ) {
case UPLOAD_ERR_OK:
$message = false;;
break;
case UPLOAD_ERR_INI_SIZE:
case UPLOAD_ERR_FORM_SIZE:
$message .= ' - file too large (limit of '. ini_get('upload_max_filesize') .' bytes).';
break;
@jfreites
jfreites / gist:11358507
Created April 28, 2014 00:00
Update value based on subquery
UPDATE target_table t
INNER JOIN (
select value1, value2
from another_table
) x
ON t.field_a = x.value2
SET t.field_b = x.value1
@jfreites
jfreites / permissions_changer
Created December 12, 2013 15:52
Set permissions for all files and folders recursively using PHP
<?php
// $ruta is the path to folder, use the correct octal value in your case...
exec ("find $ruta -type d -exec chmod 0777 {} +");
exec ("find $ruta -type f -exec chmod 0777 {} +");