Skip to content

Instantly share code, notes, and snippets.

@bohwaz
bohwaz / check_ine.php
Last active October 21, 2026 05:52
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 / lcp_download.php
Created June 29, 2023 20:10
Transform LCP/LCPL files to regular EPUB/PDF/ZIP
#!/usr/bin/php
<?php
// Note: this code does not contain any DRM removal, DRM removal is made by https://notabug.org/NewsGuyTor/DeDRM_tools-LCP
//
// Install steps:
// Debian/Ubuntu/Mint: apt install php-cli python3 python3-cryptodome python3-lxml zip unzip
//
// How to use?
// Just run: php lcp_download.php FILE.LCPL PASSWORD
// A new FILE_decrypted.epub will be created in the same directory
@bohwaz
bohwaz / dns_get_record_from.php
Last active August 30, 2026 08:39
PHP script to retrieve a DNS record from a custom nameserver
<?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, string $protocol = 'udp'): array
{
@bohwaz
bohwaz / pdf2cbz.sh
Created February 3, 2025 19:42
Convert a PDF file to CBZ (Comic Books)
#!/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 / extract_sisimai_reasons.php
Last active March 6, 2026 16:07
Export Sisimai reasons to JSON
<?php
function ignore_spaces_regexp(string $r) {
return str_replace(' ', '\s*', $r);
}
function parse_reason(string $path)
{
$src = file_get_contents($path);
$out = new \stdClass;
@bohwaz
bohwaz / sqlite_fts4_rank.php
Created December 3, 2025 15:21
rank function for SQLite3 FTS3/FTS4
<?php
/**
* SQLite search ranking user defined function
* Converted from C from SQLite manual: https://www.sqlite.org/fts3.html#appendix_a
*/
function sqlite_rank(string $aMatchinfo, ...$weights): float
{
/* Check that the number of arguments passed to this function is correct.
** If not, jump to wrong_number_args. Set aMatchinfo to point to the array
@bohwaz
bohwaz / extract-credit-mutuel-csv-garradin.php
Last active June 17, 2025 08:19
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_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 / php-8.1-strftime.php
Last active March 20, 2025 11:19
strftime() replacement function for PHP 8.1
<?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 / facebook-delete-all-photos.js
Created January 9, 2025 18:03
Delete all photos from your Facebook profile (French)
// Facebook is fascist network AND makes it super hard to delete all your photos!
// Here is a script that will automatically click on buttons
// to delete all your photos one by one from your Facebook account.
//
// 1. Click on the "Photos" tab of your Facebook profile
// 2. Click on the pencil on the right-top corner of a photo
// 3. Note the label of the button to delete a photo
// 4. Click on this button
// 5. Note the label of the confirm button
// 6. Change the following three labels to match the real buttons labels,