Skip to content

Instantly share code, notes, and snippets.

BohwaZ bohwaz

Block or report user

Report or block bohwaz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@bohwaz
bohwaz / check_ine.php
Last active Oct 31, 2019
Vérification de validité de numéro INE d'étudiant (BEA/Scolarix/APOGEE)
View check_ine.php
<?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 Apr 28, 2017
Fetches timestamp from a NTP server in PHP
View get_time_from_ntp.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 Apr 23, 2017
Import CSV file in a SQLite table, including column headers
View csv2sqlite.php
<?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 Apr 23, 2017
Download images from SLSA (State Library of South Australia) collections
View download-slsa.php
<?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 Sep 4, 2018
PHP setcookie function polyfill with support for SameSite attribute (compatible with PHP 5.0+)
View setcookie_samesite_polyfill.php
<?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 / gitlab-projects-json-to-csv.php
Created Feb 8, 2017
Extract Gitlab JSON project list and convert it to CSV
View gitlab-projects-json-to-csv.php
<?php
$projects = [];
$projects[] = [
'Project path',
'Owner',
'Name',
'Description',
'Created',
@bohwaz
bohwaz / nvsprintf.php
Created Jun 28, 2016 — forked from onyxraven/nvsprintf.php
Named param vsprintf()
View nvsprintf.php
<?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 / ngv-download.php
Last active May 16, 2016
Download large images of art from National Gallery of Victoria (NGV) website
View ngv-download.php
#!/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 / download.sh
Created Dec 25, 2015 — forked from mildred/download.sh
Download from archive.org Wayback Machine
View download.sh
#!/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 / maths.php
Created Feb 4, 2012
Allow user to compute maths in PHP
View maths.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))*)+$/';
You can’t perform that action at this time.