Skip to content

Instantly share code, notes, and snippets.

@bohwaz
bohwaz / get_ssl_expiry.php
Created September 8, 2022 15:21
PHP function to get number of days before SSL/TLS certificate expiry from a HTTPS URL
View get_ssl_expiry.php
<?php
/**
* Return number of days before certificate expiry from a HTTPS URL
* Usage: get_ssl_certificate_expiry('https://www.framasoft.net/')
* => int(45)
* @author bohwaz
*/
function get_ssl_certificate_expiry(string $url): ?int
{
@bohwaz
bohwaz / dns_get_record_from.php
Last active June 6, 2023 20:42
PHP script to retrieve a DNS record from a custom nameserver
View dns_get_record_from.php
<?php
/**
* Make a DNS a request to a custom nameserver, this is similar to dns_get_record, but allows you to query any nameserver
* Usage: dns_get_record_from('ns.server.tld', 'A', 'mydomain.tld');
* => ['42.42.42.42']
* @author bohwaz
*/
function dns_get_record_from(string $server, string $type, string $record): array
{
@bohwaz
bohwaz / save_twitter_thread.php
Last active September 2, 2022 02:20
Save a Twitter thread to static HTML (using Nitter) - Save and run "php save_twitter_thread.php URL FILE.html" - The created file is static, no external dependency, no JS, except images and videos
View save_twitter_thread.php
#!/usr/bin/env php
<?php
/*
This file is part of KD2FW -- <http://dev.kd2.org/>
Copyright (c) 2001-2019 BohwaZ <http://bohwaz.net/>
All rights reserved.
@bohwaz
bohwaz / cavites.php
Created July 4, 2022 12:13
Téléchargement et conversion en GPX de la BDCavité (liste des cavités souterraines du BRGM)
View cavites.php
<?php
// Mode d'emploi : créer un répertoire vierge et lancer "php cavites.php"
const JSON_URL = 'https://www.georisques.gouv.fr/webappReport/ws/telechargement/cavites?anneemin=2003';
const PROJECTIONS = [
1 => 'LambertI',
2 => 'LambertII',
3 => 'LambertIII',
@bohwaz
bohwaz / archive_twitter.php
Created January 5, 2022 13:56
Script to scrape and archive a Twitter thread as a static HTML page, using Nitter
View archive_twitter.php
#!/usr/bin/env php
<?php
/*
This file is part of KD2FW -- <http://dev.kd2.org/>
Copyright (c) 2001-2019 BohwaZ <http://bohwaz.net/>
All rights reserved.
View garradin-plugin-login.diff
Index: src/include/lib/Garradin/Membres/Session.php
==================================================================
--- src/include/lib/Garradin/Membres/Session.php
+++ src/include/lib/Garradin/Membres/Session.php
@@ -157,10 +157,21 @@
protected function deleteAllRememberMeSelectors($user_id)
{
return $this->db->delete('membres_sessions', $this->db->where('id_membre', $user_id));
}
@bohwaz
bohwaz / php-8.1-strftime.php
Last active April 17, 2023 10:00
strftime() replacement function for PHP 8.1
View php-8.1-strftime.php
<?php
namespace PHP81_BC;
/**
* Locale-formatted strftime using \IntlDateFormatter (PHP 8.1 compatible)
* This provides a cross-platform alternative to strftime() for when it will be removed from PHP.
* Note that output can be slightly different between libc sprintf and this function as it is using ICU.
*
* Usage:
* use function \PHP81_BC\strftime;
@bohwaz
bohwaz / db.php
Last active November 22, 2021 14:15
Simple PHP wrapper around SQLite3
View db.php
<?php
/*
* $db = new DB('file.sqlite');
* var_dump($db->simple('SELECT * FROM table WHERE name = ?;', 'My Name'));
* var_dump($db->simpleSingle('SELECT * FROM table WHERE date > ? LIMIT 1;', '2020-01-01'));
* var_dump($db->simpleColumn('SELECT birthdate FROM table WHERE name = ?;', 'David Lynch'));
*/
class DB extends \SQLite3
@bohwaz
bohwaz / mijia_temperature.php
Created October 13, 2021 22:15
Reads data from LYWSD03MMC Xiaomi Mijia temperature sensor and stores it in a SQLite database.
View mijia_temperature.php
<?php
/**
* Reads data from LYWSD03MMC Xiaomi Mijia temperature sensor
* and stores it in a SQLite database.
*
* @author BohwaZ <https://bohwaz.net/>
* @see https://github.com/davi-domo/Xiaomi-Mijia-LYWSD03MMC-/blob/main/mijia_bd/MIJIA_MULTI_BD.sh
* @see https://smhosy.blogspot.com/2021/01/quelle-temperature-et-hydrometrie-dans.html
* @see https://www.fanjoe.be/?p=3911
*
@bohwaz
bohwaz / extract-paypal-csv.php
Created December 16, 2020 14:42
Extraction de relevé de compte Paypal pour Garradin
View extract-paypal-csv.php
<?php
/**
* Extracteur de données des relevés de compte Paypal
* à destination de Garradin (ou autre logiciel de compta)
*
* https://garradin.eu/
*
* Ce script prend en argument un fichier CSV exporté de Paypal
* https://business.paypal.com/merchantdata/reportHome?reportType=DLOG
* et produit un import exploitable dans Garradin