Skip to content

Instantly share code, notes, and snippets.

@bohwaz
bohwaz / demo.html
Created October 4, 2024 14:12
Insert images in a MarkDown textarea, and resize them before upload, with no specific handling on the server side
<!DOCTYPE html>
<html>
<head>
<title>Javascript insert images into markdown with resize before upload</title>
</head>
<body>
<pre><h2>This demo shows how you can easily add images to a markdown textarea</h2>
You can drag and drop, paste or select images. Files other than images are discarded.
The images are resized on the client side and inserted as Markdown inside the text.
@bohwaz
bohwaz / extract_sisimai_reasons.php
Last active October 9, 2024 12:05
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 / demo.html
Created September 29, 2024 16:52
Use OffscreenCanvas to resize images in javascript
<!DOCTYPE html>
<html>
<head>
<title>Javascript OffscreenCanvas image resize demo</title>
</head>
<body>
<h3>Select a file below to display its thumbnail</h3>
<input type="file" id="file" />
@bohwaz
bohwaz / cert_expiry_check.php
Last active September 15, 2023 05:41
Check if certificate expiry is in more than 30 days
<?php
$domain = 'mydomain.tld';
if (get_ssl_certificate_expiry($domain) < 30) {
throw new \Exception('Certificate expires in less than 30 days!');
}
function get_ssl_certificate_expiry(string $domain): ?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 / 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 / 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 / dns_get_record_from.php
Last active October 25, 2024 09:20
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): 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
#!/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)
<?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',