Skip to content

Instantly share code, notes, and snippets.

View danilopinotti's full-sized avatar
Possibly drinking coffee

Danilo Pinotti danilopinotti

Possibly drinking coffee
View GitHub Profile
@danilopinotti
danilopinotti / RefreshDatabase.php
Created February 10, 2020 20:41
Laravel RefreshDatabase freshing database once according migrations folder.
<?php
namespace Tests;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Testing\RefreshDatabase as RefreshDatabaseBase;
use Illuminate\Foundation\Testing\RefreshDatabaseState;
trait RefreshDatabase
{
@danilopinotti
danilopinotti / CacheKeys.php
Last active December 15, 2020 18:05
Trait to generate Model cache keys. Applicable in Models from Laravel 5+
<?php
/**
* Created by: @danilopinotti
* Inspired in Laravel Model Caching article (https://laravel-news.com/laravel-model-caching).
*/
trait CacheKeys
{
/**
* Generates a key that is updated each time Model is updated.
@danilopinotti
danilopinotti / UrlHelper.php
Created December 15, 2020 18:11
A support class made to help working with URLs
<?php
/**
* A support class made to help with URLs
*/
class UrlHelper
{
/**
* Validate if param is a valid URL;
*
@danilopinotti
danilopinotti / webserver-toggle-led.ino
Last active April 26, 2021 02:00
Código para treinamento sobre bibliotecas e utilização delas
#include <Led.h>
#include <WebServer.h>
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
Led led(2);
WebServer webServer(80);
void setupWifi() {
WiFi.mode(WIFI_STA);
WiFiManager wifiManager;
@danilopinotti
danilopinotti / mqtt-serial-chat.ino
Last active April 28, 2021 03:19
Simple MQTT chat using Arduino Serial and a public broker
#include <WiFi.h>
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <PubSubClient.h> // https://github.com/knolleary/pubsubclient
#define BROKER_ADDRESS "broker.hivemq.com"
#define BROKER_PORT 1883
#define MQTT_CLIENT_ID "arduinoClient-1A2B3C"
WiFiClient wifiClient;
PubSubClient mqttClient(wifiClient);
@danilopinotti
danilopinotti / tailrecursion.php
Created June 19, 2021 23:31 — forked from pyldin601/tailrecursion.php
PHP Tail Recursion
<?php
function tail($fn)
{
$underCall = false;
$pool = [];
return function (...$args) use (&$fn, &$underCall, &$pool) {
$result = null;
$pool[] = $args;
@danilopinotti
danilopinotti / SentMailsTest.php
Created August 18, 2021 18:30
Test sent emails in Laravel 8. Applied to test emails sent by Mail or Notification facades.
<?php
namespace Tests;
use App\User;
use Tests\TestCase;
use Illuminate\Notifications\Notification;
class MyNotification extends Notification
{
@danilopinotti
danilopinotti / EmbeddedGoogleMaps.vue
Last active November 1, 2021 20:45
Embedded Google Maps Vue Component to show a given address. Stylized with Tailwind CSS
<template>
<div class="relative text-right" :style="`height: ${height}; width: ${width}`">
<div :style="`height: ${height}; width: ${width}`" class="overflow-hidden bg-none">
<iframe :width="width" :height="height"
:src="mapUrl"
frameborder="0" scrolling="no" marginheight="0" marginwidth="0"></iframe>
</div>
</div>
</template>
@danilopinotti
danilopinotti / memoization.php
Last active March 10, 2022 17:22
PHP Memoization inspired by @CViniciusSDias
<?php
use Ds\Map;
function memo(callable $function): callable
{
$cache = new Map();
return function (mixed ...$args) use (&$cache, $function): mixed {
if (isset($cache[$args])) {
return $cache[$args];
@danilopinotti
danilopinotti / OrderByPriorityTrendCriterion.php
Last active May 25, 2022 13:04
Criterion to order a given query by a priority trend. This class may be applied in Laravel Query Builder.
<?php
namespace App\QueryBuilderCriteria;
use App\Contracts\QueryBuilderCriteria;
use Illuminate\Database\PostgresConnection;
class OrderByPriorityTrendCriterion extends QueryBuilderCriteria
{
public function apply($queryBuilder)