Skip to content

Instantly share code, notes, and snippets.

@gabrieleromanato
gabrieleromanato / password.c
Created August 31, 2023 05:42
C: random password generator
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdbool.h>
// Function to generate a random password
void generateRandomPassword(int length, bool includeSymbols) {
const char charset[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_+{}[]<>,.?/"; // Characters to choose from
int charsetSize = sizeof(charset) - 1;
@gabrieleromanato
gabrieleromanato / convert-phpdocs-to-pdf.py
Created June 22, 2023 16:51
Convert all the HTML files of the PHP documentation into PDF files
import tarfile
import os
import pdfkit
# Get the archive file at https://www.php.net/distributions/manual/php_manual_en.tar.gz
# Install pdfkit: https://github.com/JazzCore/python-pdfkit
def decompress_tar_file(file_name):
tar = tarfile.open(file_name)
tar.extractall()
@gabrieleromanato
gabrieleromanato / python-alt-switch-case.js
Created May 29, 2022 11:16
Emulating switch/case Statements in Python with Dictionaries: JavaScript version
'use strict';
/*
https://www.youtube.com/watch?v=gllUwQnYVww
Emulating switch/case Statements in Python with Dictionaries
*/
const execFunc = (operand = 'add', a = 1, b = 1) => {
const getOperand = (name, obj) => {
if(typeof obj[name] !== 'function') {
@gabrieleromanato
gabrieleromanato / Cloudflare.py
Created April 18, 2022 10:11
Cloudflare class to check whether a domain has been added to the service
from CloudflareRequest import CloudflareRequest
from CloudflareDNS import CloudflareDNS
class Cloudflare:
def __init__(self, host):
self.host = host
self.url = 'https://' + self.host
self.request = CloudflareRequest(self.url)
self.dns = CloudflareDNS(self.host)
@gabrieleromanato
gabrieleromanato / CloudflareDNS.py
Created April 18, 2022 10:09
Cloudflare: get the NS records of a given domain via the Google DNS API
import requests
import validators
from validators import ValidationFailure
class CloudflareDNS:
def __init__(self, host):
self.host = host
self.record = 'NS'
self.api_url = 'https://dns.google/resolve?'
@gabrieleromanato
gabrieleromanato / CloudflareRequest.py
Created April 18, 2022 10:06
Cloudflare: get HTTP headers of a given domain/URL
import requests
import validators
from validators import ValidationFailure
class CloudflareRequest:
def __init__(self, url):
self.url = url
def send(self):
@gabrieleromanato
gabrieleromanato / overhead.php
Created January 30, 2018 16:56
Unnecessary WordPress overhead: the wp hook incorrect use
<?php
// Never ever use the wp hook to run unnecessary routines
// Global overhead ahead!
function my_factorial( $n ) {
if( function_exists( 'gmp_fact' ) ) {
return gmp_fact( $n );
} else {
if ( $n < 2 ) {
return 1;
@gabrieleromanato
gabrieleromanato / numeri-primi.js
Last active June 18, 2017 08:33
numeri-primi
"use strict";
(function() {
const isPrimeNumber = number => {
if ( number == 1 || number == 2 ) {
return true;
}
for ( var i = 2; i < number; i++ ) {
/*
* Scrivere un programma che legge in ingresso un numero intero non
* negativo a, e stampa sullo schermo tutti i numeri primi compresi
* tra 0 ed a. Realizzare il programma definendo ed utilizzando
* almeno le due funzioni seguenti.
*
* Una funzione che, dato un numero intero passato come parametro,
* ritona true se il numero e' primo, false altrimenti.
*
* Una funzione che, dato un numero intero n passato come parametro,
'use strict';
module.exports = {
paypal: {
businessEmail: 'your-paypal-business-email',
url: 'https://www.sandbox.paypal.com/cgi-bin/webscr',
currency: 'USD'
},
secret: 'secret-session-key',
name: 'name-of-session-cookie',