Skip to content

Instantly share code, notes, and snippets.

@bohwaz
bohwaz / maths.php
Created February 4, 2012 22:53
Allow user to compute maths in PHP
<?php
function mathEval($q)
{
$q = preg_replace('/\s+/', '', $q);
$number = '(?:\d+(?:[,.]\d+)?|pi|π)';
$functions = '(?:sinh?|cosh?|tanh?|abs|acosh?|asinh?|atanh?|exp|log10|deg2rad|rad2deg|sqrt|ceil|floor|round)';
$operators = '[+\/*\^%-]';
$regexp = '/^(('.$number.'|'.$functions.'\s*\((?1)+\)|\((?1)+\))(?:'.$operators.'(?2))*)+$/';
@bohwaz
bohwaz / download.sh
Created December 25, 2015 06:53 — forked from mildred/download.sh
Download from archive.org Wayback Machine
#!/bin/bash
url=http://redefininggod.com
webarchive=https://web.archive.org
wget="wget -e robots=off -nv"
tab="$(printf '\t')"
additional_url=url.list
# Construct listing.txt from url.list
# The list of archived pages, including some wildcard url
@bohwaz
bohwaz / ngv-download.php
Last active May 16, 2016 01:36
Download large images of art from National Gallery of Victoria (NGV) website
#!/usr/bin/php
<?php
/**
* Download a large size art image from National Gallery of Victoria (NGV) website
* Copyleft (C) 2016 BohwaZ http://bohwaz.net/ (Public domain)
*/
if (empty($argv[1]))
{
@bohwaz
bohwaz / nvsprintf.php
Created June 28, 2016 04:39 — forked from onyxraven/nvsprintf.php
Named param vsprintf()
<?php
/**
* Named-Param vsprintf()
*
* positional-params based on key name, much the same as positional in sprintf()
*
* @link http://php.net/manual/en/function.sprintf.php
* @link http://www.php.net/manual/en/function.vsprintf.php
*
* @param string $str format string - replacements are in %KEY$x format
@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),
@bohwaz
bohwaz / php_sqlite_rank.php
Created November 10, 2011 16:09
Pure PHP rank function for SQLite FTS4 (adapted from SQLite doc)
<?php
/*
Adapted from C function available at http://www.sqlite.org/fts3.html#appendix_a
Use like this:
$db = new SQLite3('database.db');
$db->createFunction('rank', 'sql_rank');
$db->query('CREATE VIRTUAL TABLE products USING fts4 (id INTEGER, title TEXT, description TEXT);');
$db->query('SELECT * FROM products WHERE products MATCH \'Computer\' ORDER BY rank(matchinfo(products), 0, 1.0, 0.5) DESC;');
@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 / 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 / gitlab-projects-json-to-csv.php
Created February 8, 2017 01:23
Extract Gitlab JSON project list and convert it to CSV
<?php
$projects = [];
$projects[] = [
'Project path',
'Owner',
'Name',
'Description',
'Created',