Skip to content

Instantly share code, notes, and snippets.

@bohwaz
bohwaz / get_time_from_ntp.php
Created April 28, 2017 02:48
Fetches timestamp from a NTP server in PHP
<?php
/**
* Returns UNIX timestamp from a NTP server (RFC 5905)
*
* @param string $host Server host (default is pool.ntp.org)
* @param integer $timeout Timeout in seconds (default is 10 seconds)
* @return integer Number of seconds since January 1st 1970
*/
function getTimeFromNTP($host = 'pool.ntp.org', $timeout = 10)
@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.
<?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 / db.php
Last active November 22, 2021 14:15
Simple PHP wrapper around SQLite3
<?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
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 / archive_twitter.php
Created January 5, 2022 13:56
Script to scrape and archive a Twitter thread as a static HTML page, using Nitter
#!/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 / 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
#!/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 / extract-credit-mutuel-csv-garradin.php
Last active June 2, 2023 11:14
Extraction de relevé de compte Crédit Mutuel pour Garradin
<?php
/**
* Extracteur de données des relevés de compte du Crédit Mutuel
* à destination de Garradin (ou autre logiciel de compta)
*
* https://garradin.eu/
*
* Ce script prend en argument un répertoire contenant des extraits
* de compte en PDF (ou un seul extrait de compte) et crée un fichier
* CSV importable directement dans Garradin.
@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
<?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 / pdf2cbz.sh
Last active July 29, 2023 11:08
pd2cbz.sh - Convert a PDF file (eg. a comic) to a CBZ file
#!/bin/bash
which mutool &> /dev/null || (echo "mutool is not installed" && exit 1)
which convert &> /dev/null || (echo "imagemagick is not installed" && exit 1)
which zip &> /dev/null || (echo "zip is not installed" && exit 1)
if [ "$1" = "" ]
then
echo "Usage: $0 File.pdf"
exit
@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)
<?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',