Skip to content

Instantly share code, notes, and snippets.

@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 / dns_get_record_from.php
Last active September 3, 2025 17:34
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 / 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 / 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 / check_ine.php
Last active March 9, 2025 22:31
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 / 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 / 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,
@bohwaz
bohwaz / instagram-delete-all.js
Created January 8, 2025 15:15
"Select all" Instagram activity (to delete all posts, all comments, all likes, etc.)
// Instagram doesn't allow to select all your posts, or all your comments, etc. to delete them.
// You can only select them one by one. This is slow as hell.
// Use this to select all the photos, comments, etc.
// 1. Open this page: https://www.instagram.com/your_activity/interactions/likes/
// 2. click on the "select" button
// 3. Press the F12 key to open the developer tools
// 4. open the console tab in the developer tools
// 5. copy-paste the following code in the command prompt of the console and press enter
// 6. Click on Delete/Unlike button