Skip to content

Instantly share code, notes, and snippets.

@grandmanitou
grandmanitou / switch-php-versions-ubuntu.md
Created October 28, 2021 08:52
Switch between PHP version in Ubuntu

How to change the PHP version you’re using If you have multiple PHP versions installed on your Ubuntu server, you can change what version is the default one.

To set PHP 7.4 as the default, run:

update-alternatives --set php /usr/bin/php7.4 To set PHP 8.0 as the default, run:

update-alternatives --set php /usr/bin/php8.0

@grandmanitou
grandmanitou / TestClass.php
Created February 5, 2021 07:22
PHP Proxy function in class
<?php
// Source:
// https://stackoverflow.com/questions/3716649/how-to-auto-call-function-in-php-for-every-other-function-call
class test {
function __construct(){}
private function test1(){
echo "In test1", PHP_EOL;
@grandmanitou
grandmanitou / app.js
Created August 18, 2020 13:58
Create preview button next to an url input, open in new tab -- Bootstrap 4 / Laravel
$(document).on('click', '.btn-preview-url', function(e) {
e.preventDefault();
let element = $(this).data('src');
let url = $(element).val();
if (url !== '') {
window.open(url, '_blank');
}
return false;
});
@grandmanitou
grandmanitou / UserFactory.php
Created August 15, 2020 14:09
Use faker with 3rd party class in a Laravel factory
<?php
use App\User;
use Illuminate\Support\Str;
use Faker\Generator as Faker;
$factory->define(User::class, function (Faker $faker) {
$faker->addProvider(new CompanyNameGenerator\FakerProvider($faker));
return [
'first_name' => $faker->firstName,
@grandmanitou
grandmanitou / how-to-switch-node-versions.md
Created June 18, 2020 09:11
How to switch Node versions with Homebrew

Remode node modules

rm -rf node_modules

Check node current version

$ node -v

Outputs something like

@grandmanitou
grandmanitou / DowngradeNode.md
Created June 18, 2020 08:57
4 Step Process to Downgrade Node version using Homebrew

Check your current node version

$ node -v

Check for available node versions

brew search node

To unlink from current version

@grandmanitou
grandmanitou / ContactRequest.php
Created June 10, 2020 11:58
Laravel phone number (all types) custom validation rule class
<?php
namespace App\Http\Requests;
use App\Rules\PhoneNumber;
use Illuminate\Foundation\Http\FormRequest;
use libphonenumber\PhoneNumberType;
class ContactRequest extends FormRequest
{
@grandmanitou
grandmanitou / Contact.php
Created June 10, 2020 10:59
Laravel Phone Number Accessor : format phone number to local phone number or international phone number for other regions
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use libphonenumber\PhoneNumberUtil;
use libphonenumber\NumberParseException;
use libphonenumber\PhoneNumberFormat;
class Contact extends Model
@grandmanitou
grandmanitou / redis.md
Last active May 26, 2020 07:56
Install Redis for PHP 7.x +

Install Redis for PHP 7.x +

Install on OSX

brew install redis

Final result

brew info redis

@grandmanitou
grandmanitou / MeetingRegistrationRequest.php
Created January 31, 2020 10:41
Laravel validation rule for french phone number
'phone' => [
'nullable',
'regex:/^(?:(?:\+|00)33|0)\s*[1-9](?:[\s.-]*\d{2}){4}$/'
],