Skip to content

Instantly share code, notes, and snippets.

@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
@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 / extract-paypal-csv.php
Created December 16, 2020 14:42
Extraction de relevé de compte Paypal pour Garradin
<?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
@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 / episodes-list.json
Last active November 8, 2020 16:23
List and download all Film Reroll (www.filmreroll.com) episodes in the right order
{
"https:\/\/feeds.soundcloud.com\/stream\/908994106-pauloquiros-film-reroll-ep-95-memento-part-3.mp3": "Ep 95: Memento (Part 3)",
"https:\/\/feeds.soundcloud.com\/stream\/896374723-pauloquiros-film-reroll-ep-94-memento-part-2.mp3": "Ep 94: Memento (Part 2)",
"https:\/\/feeds.soundcloud.com\/stream\/885518080-pauloquiros-ep-93-memento-part-1.mp3": "Ep 93: Memento (Part 1)",
"https:\/\/feeds.soundcloud.com\/stream\/865158364-pauloquiros-film-reroll-ep-92-toy-story-part-2.mp3": "Ep 92: Toy Story (Part 2)",
"https:\/\/feeds.soundcloud.com\/stream\/852471577-pauloquiros-ep-91-toy-story-part-1.mp3": "Ep 91: Toy Story (Part 1)",
"https:\/\/feeds.soundcloud.com\/stream\/841027480-pauloquiros-film-reroll-ep-90-oceans-11-part-5.mp3": "Ep 90: Oceans 11 (Part 5)",
"https:\/\/feeds.soundcloud.com\/stream\/829642777-pauloquiros-film-reroll-ep-89-oceans-11-part-4.mp3": "Ep 89: Oceans 11 (Part 4)",
"https:\/\/feeds.soundcloud.com\/stream\/820194718-pauloquiros-film-reroll-ep-88-oceans-11-part
@bohwaz
bohwaz / check_ine.php
Last active January 10, 2024 10:41
Vérification de validité de numéro INE d'étudiant (BEA/Scolarix/APOGEE)
<?php
// Licence : domaine public ou WTFPL
// 2018 BohwaZ <http://bohwaz.net/>
function check_ine($ine)
{
if (!function_exists('bcmod'))
{
throw new \LogicException('bcmath is required');
@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 / csv2sqlite.php
Created April 23, 2017 10:52
Import CSV file in a SQLite table, including column headers
<?php
$fp = fopen($argv[1], 'r');
$db = new SQLite3($argv[1] . '.sqlite');
$db->exec('BEGIN;');
$header = null;
$i = 0;
@bohwaz
bohwaz / download-slsa.php
Last active April 23, 2017 10:52
Download images from SLSA (State Library of South Australia) collections
<?php
/**
* Download large size images from SLSA Library
* (State Library of South Australia)
* Copyleft (C) 2015-2017 BohwaZ http://bohwaz.net/
* GNU AGPL license
*/
if (empty($argv[1]))
@bohwaz
bohwaz / setcookie_samesite_polyfill.php
Last active September 4, 2018 13:56
PHP setcookie function polyfill with support for SameSite attribute (compatible with PHP 5.0+)
<?php
/**
* Setcookie function with support for SameSite
* @param string|null $samesite 'Lax' or 'Strict'
*/
function setcookie_samesite($name, $value = '', $expire = 0, $path = null, $domain = null, $secure = false, $httponly = false, $samesite = null)
{
$params = array(
rawurlencode($name) . '=' . rawurlencode($value),