Skip to content

Instantly share code, notes, and snippets.

View danilopinotti's full-sized avatar
Probably drinking coffee

Danilo Pinotti danilopinotti

Probably drinking coffee
View GitHub Profile
@danilopinotti
danilopinotti / pi.py
Last active September 13, 2022 15:02
Simulate an approximation of PI value using Python
import numpy as np
import multiprocessing as mp
import random
import math
threads = mp.cpu_count()
points = 100_000_000
def simulate_pi(points):
radius = 1
@danilopinotti
danilopinotti / CacheManager.php
Created September 28, 2022 11:57
Cache Manager to easily converts TTL and enable/disable custom cache
<?php
namespace App\Support;
use Illuminate\Contracts\Cache\Repository;
class CacheManager
{
private ?string $driver = null;
@danilopinotti
danilopinotti / HighOrderCacheProxy.php
Created September 28, 2022 15:27
Implements a layer above objects that caches all method calls
<?php
namespace App\Support;
class HighOrderCacheProxy
{
protected string $ttl = '15 minutes';
protected array $tags = [];
public function __construct(
@danilopinotti
danilopinotti / ClientRequestWatcher.php
Last active October 6, 2022 16:49
Show the Transfer Time in Client Request URI in Telescope
<?php
namespace App\Services\Telescope\Watchers;
use Illuminate\Http\Client\Events\ResponseReceived;
use Laravel\Telescope\IncomingEntry;
use Laravel\Telescope\Watchers\ClientRequestWatcher as BaseWatcher;
use Laravel\Telescope\Telescope;
class ClientRequestWatcher extends BaseWatcher
@danilopinotti
danilopinotti / Searchable.php
Last active November 1, 2022 02:37
Laravel searchabe trait
<?php
namespace App\Support\Models;
use Illuminate\Database\PostgresConnection;
use Illuminate\Support\Arr;
trait Searchable
{
public function scopeSearch(
@danilopinotti
danilopinotti / ExecutionId.php
Created September 20, 2023 12:56
Laravel setup Logger as JSON
<?php
namespace App\Support;
use Illuminate\Support\Facades\App;
use Symfony\Component\Uid\Factory\UlidFactory;
class ExecutionId implements \Stringable
{
private string $id;
@danilopinotti
danilopinotti / keepalive.sh
Created March 9, 2026 13:11
A simple shell script function to keep a process running continuously, auto-restarting it if it stops or crashes.
keepalive() {
local command_args=("$@")
# Check if a command was provided
if [ -z "$1" ]; then
echo "Usage: keep_alive <command> [arguments]"
return 1
fi
# Handle manual interruption (Ctrl+C)