Skip to content

Instantly share code, notes, and snippets.

View filippotoso's full-sized avatar

Filippo Toso filippotoso

View GitHub Profile
@filippotoso
filippotoso / temporary_filename.php
Created January 22, 2018 17:58
Get a temporary filename with a specific extension
/**
* Get a temporary filename with a specific extension
* @method temporary_filename
* @param string $dir The directory where it tries to create the temporary file
* @param string $extension The extension of the file (default: '')
* @param string $prefix The prefix of the file (default: '')
* @param integer $retry The number of times it tries to create a random filename (default: 100)
* @return string|FALSE
*/
function temporary_filename($dir, $extension = '', $prefix = '', $retry = 100) {
function array_clone($array) {
return array_slice($array, 0, null, true);
}
@filippotoso
filippotoso / update.php
Created March 22, 2018 14:11
Update the Larevel's public/index.php file to work outside the project folder
<?php
$content = file_get_contents(__DIR__ . '/project/public/index.php');
$content = str_replace("__DIR__.'/../", "__DIR__.'/../project/", $content);
file_put_contents(__DIR__ . '/project/public/index.php', $content);
@filippotoso
filippotoso / remote_file_size.php
Last active April 9, 2018 12:14
PHP remote file size
<?php
use GuzzleHttp\Client;
function remote_file_size($url) {
$client = new Client();
$response = $client->head($url);
$headers = $response->getHeader('Content-Length');
return end($headers);
}
@filippotoso
filippotoso / spacing.scss
Created September 28, 2018 13:57
Spacing extension for Bulma.io (CSS Framework)
/*
* A spacing extension to Bulma.io
*
* This extension implements rules likes:
* has-margin-none, has-padding-medium, has-margin-bottom-large, has-margin-auto
*
* The classes are built as follows (in rem):
*
* has-margin
* -(*|top|right|bottom|left)
@filippotoso
filippotoso / debug.css
Created September 28, 2018 16:17
debug.css
/*! debug.css | MIT License | zaydek.github.com/debug.css */
*:not(path):not(g) {
color: hsla(210, 100%, 100%, 0.9) !important;
background: hsla(210, 100%, 50%, 0.5) !important;
outline: solid 0.25rem hsla(210, 100%, 100%, 0.5) !important;
box-shadow: none !important;
}
@filippotoso
filippotoso / struct2array.php
Last active February 21, 2019 08:34
Google\Protobuf\Struct to PHP Array
<?php
use Google\Protobuf\Struct;
function struct2array(Struct $struct) {
return json_decode($struct->serializeToJsonString(), true);
}
@filippotoso
filippotoso / httpd-vhosts.conf
Created June 22, 2019 22:20
Virtual Host configuration
<VirtualHost *:80>
DocumentRoot "D:/Projects/<project>/public_html"
ServerName <project>.local
ServerAlias <project>.local
<Directory "D:/Projects/<project>/public_html">
AllowOverride All
Require all Granted
</Directory>
</VirtualHost>
@filippotoso
filippotoso / setup.bat
Created May 6, 2020 06:59
Laravel Setup
@echo off
SET /P FOLDER=Please enter the project folder:
IF "%FOLDER%"=="" GOTO Error
mkdir %FOLDER%
cd %FOLDER%
call laravel new project --auth
move project/public public_html
cd project
composer require filippo-toso/models-generator filippo-toso/test-email --dev
php artisan vendor:publish --tag=config --provider="FilippoToso\ModelsGenerator\ServiceProvider"
@filippotoso
filippotoso / URI.php
Last active June 24, 2021 07:39
URI Class
<?php
/**
* Copyright 2021 Filippo Toso
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
* modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software
* is furnished to do so, subject to the following conditions:
*