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 / 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 / duplicated.php
Created April 15, 2024 20:55
replaced duplicated spaces with PHP
<?php
//Replacing multiple spaces with a single space simple single line of php code:
$output = preg_replace('/\s+/', ' ', $input);
//This mean that spaces, tabs or line breaks (one or more) will be replaced by a single space.
//Replace multiple spaces with one space:
$output = preg_replace('/\s+/', ' ', $input);
//Replace one or multiple tabs with one space:
$output = preg_replace('/\t+/', ' ', $input);
@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 = [
@fhferreira
fhferreira / cloudflare-purge-cache-service-worker.js
Created November 7, 2022 12:28 — forked from vdbelt/cloudflare-purge-cache-service-worker.js
A CloudFlare service worker that proxies purge cache requests. Example: https://example.com/__purge_cache?zone=XX
addEventListener('fetch', event => {
event.respondWith(purgeCache(event.request))
})
async function purgeCache(request) {
const url = new URL(request.url)