Skip to content

Instantly share code, notes, and snippets.

View filippotoso's full-sized avatar

Filippo Toso filippotoso

View GitHub Profile
@filippotoso
filippotoso / Component.php
Last active November 22, 2023 16:20
Embrace the Larabel backend (with Livewire)
<?php
namespace Support\Livewire;
use FilippoToso\Domain\Livewire\Component as BaseComponent;
use Illuminate\Support\Facades\View;
class Component extends BaseComponent
{
public function __construct()
@filippotoso
filippotoso / usage.py
Last active July 23, 2023 09:08
Monkey Patching to intercept real usage data of OpenAI calls
from openai import Embedding, ChatCompletion, Completion
class Usage:
def __init__(self):
self.__usage = []
self.__old_embedding_create = Embedding.create
Embedding.create = self.__new_embedding_create
self.__old_completion_create = Completion.create
@filippotoso
filippotoso / laravel-http-fake-post.php
Created May 22, 2023 11:23
[Laravel] Http::fakeRequest() macro to easily fake POST/PATH/DELETE requests
<?php
use Illuminate\Support\Facades\Http;
use Illuminate\Http\Client\Request;
use Illuminate\Support\Arr;
Http::macro('fakeRequest', function ($method, $url, $payload = [], $response = null) {
Http::fake(function (Request $request) use ($method, $url, $payload, $response) {
if ($request->url() != $url) {
@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:
*
@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 / 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 / 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 / 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 / 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 / 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);
}