Skip to content

Instantly share code, notes, and snippets.

View paoloconi96's full-sized avatar

Paolo Conizzoli paoloconi96

View GitHub Profile
@paoloconi96
paoloconi96 / README.md
Last active February 22, 2024 08:36
Requests firewall (Java 17)

Java 17 Firewall

A Java "firewall" that given a list of blacklisted ips (with wildcards) and a list of ips can return a list of int where each number indicates if the request is successful or blocked.

A request is blocked if it matches one of the blacklisted patterns or if another successful request was made in the last 5 seconds (rate limiter).

The implementation uses a Trie for fast ip look ups and backtracking.

@paoloconi96
paoloconi96 / ExportPdf.gs
Created April 13, 2023 19:23
Simple Apps Script to automate the "Export As PDF" action of a Google Docs document
function main() {
const document = DocumentApp.getActiveDocument();
const pdfFileId = ScriptProperties.getProperty('pdfFileId');
if (!docWasUpdatedAfterPdf(document, pdfFileId)) {
return
}
updatePdfFileContent(document.getAs('application/pdf'), pdfFileId);
}
@paoloconi96
paoloconi96 / vat-number-validator.php
Created November 8, 2022 13:20
Simple PHP method to validate vatNumbers for a limited number of extra-EU and all the EU countries
private const COUNTRY_VALIDATION_PATTERNS = [
'AL' => '[JKL]\d{8}[A-Z]',
'AT' => 'U[\d]{8}',
'AU' => '\d{11}',
'BE' => '\d{10}',
'BG' => '\d{9,10}',
'BY' => '\d{9}',
'CA' => '\d{9}',
'CH' => '\d{3}\.\d{3}\.\d{3}',
'CY' => '\d{8}[A-Z]',