Skip to content

Instantly share code, notes, and snippets.

View fhferreira's full-sized avatar
🏠
Home-Office since 2005

Flávio H. Ferreira fhferreira

🏠
Home-Office since 2005
View GitHub Profile
@fhferreira
fhferreira / screenshot.php
Created October 28, 2024 17:28 — forked from MogulChris/screenshot.php
Automation and taking full-screen screenshots using Laravel Dusk and Chrome webdriver
<?php
/**
* This script is using Laravel Dusk to take screenshots of a URL, but not in the context of a regular Dusk test.
* My Laravel application is taking screenshots of *other* sites, but you could adapt this to a Dusk test taking screenshots of your Laravel site.
* 1. Install Dusk https://laravel.com/docs/5.8/dusk#installation
* 2. Make sure it works with regular Dusk tests first.
* 3. Use the code below for a stand-alone Chrome webdriver instance to do automation things.
*/
@fhferreira
fhferreira / gist:06209e053c3e3bddd1599fe369e8498c
Created October 24, 2024 20:23 — forked from sabarasaba/gist:1387550
Setting a timeout for the file_get_contents function
<?php
// Create the stream context
$context = stream_context_create(array(
'http' => array(
'timeout' => 3 // Timeout in seconds
)
));
// Fetch the URL's contents
@fhferreira
fhferreira / Dockerfile
Created October 7, 2024 10:42 — forked from Victor-Fiamoncini/Dockerfile
Franken PHP Dockerfile
# Base image with PHP and FrankenPHP
FROM dunglas/frankenphp:1-php8.3 AS frankenphp
RUN apt-get update && apt-get install -y zip libzip-dev libpq-dev libicu-dev wget acl curl
RUN docker-php-ext-install sockets zip
RUN docker-php-ext-configure zip
RUN docker-php-ext-install pgsql pdo_pgsql intl
ENV SERVER_NAME my_app
@fhferreira
fhferreira / test.php
Created February 22, 2024 19:39 — forked from claudiosanches/test.php
Regex for test credit card brand
<?php
// Test cards
$cards = array(
'378282246310005', // American Express
'371449635398431', // American Express
'5078601870000127985', // Aura
'5078601800003247449', // Aura
'30569309025904', // Diners Club
'38520000023237', // Diners Club
@fhferreira
fhferreira / numerology.php
Created January 29, 2024 11:49 — forked from mateuslopes/numerology.php
PHP Numerology Calculator
<?php
class NumerologyCalc {
const BASE_LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const VALID_FINAL_NUMBERS = [1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 22, 33, 44];
public $numerology = null;
function __construct($input = "", $show = false) {
@fhferreira
fhferreira / RetryAllFailedJobsCommand.php
Created December 8, 2023 04:01 — forked from ulcuber/RetryAllFailedJobsCommand.php
Laravel Horizon. Retry all of the failed jobs like one in the horizon dashboard
<?php
namespace App\Console\Commands\Horizon;
use Illuminate\Console\Command;
use Illuminate\Queue\Failed\FailedJobProviderInterface;
use Laravel\Horizon\Contracts\JobRepository;
use Laravel\Horizon\Jobs\RetryFailedJob;
class RetryAllFailedJobsCommand extends Command
@fhferreira
fhferreira / crawler.php
Created October 11, 2023 19:07 — forked from krakjoe/crawler.php
parallel Futures, Channels (buffered, unbuffered, synchros), Events using parallel producer/consumer pattern
<?php
use \parallel\{Runtime, Future, Channel, Events};
/* usage php crawler.php [http://example.com] [workers=8] [limit=500] */
$page = $argv[1] ?: "https://blog.krakjoe.ninja"; # start crawling this page
$workers = $argv[2] ?: 8; # start this number of threads
$limit = $argv[3] ?: 500; # stop at this number of unique pages
$timeout = $argv[4] ?: 3; # socket timeout for producers
@fhferreira
fhferreira / example.php
Created October 11, 2023 19:07 — forked from krakjoe/example.php
Executor Service with Parallel and Channels
<?php
use \parallel\{Runtime, Channel};
class ExecutorService {
public function __construct(int $workers, string $channel = __CLASS__, int $backlog = Channel::Infinite) {
if ($backlog == 0) {
/*
* execute() will block until a worker is ready
*/
<?php
try{
$url = "https://api.listclean.xyz/v1/";
$endpoint = 'verify/email/';
$api_key = YOUR_API_KEY;
@fhferreira
fhferreira / SecureHeaders.php
Created July 21, 2023 04:27 — forked from DavidMRGaona/SecureHeaders.php
Laravel Middleware to add/remove headers
<?php
namespace App\Http\Middleware;
use Closure;
class SecureHeaders
{
// Enumerate unwanted headers
private $unwantedHeaderList = [