Skip to content

Instantly share code, notes, and snippets.

@tom--
tom-- / Random bytes, ints, UUIDs in PHP.md
Last active July 10, 2025 16:41
PHP random bytes, integers and UUIDs

Random bytes, ints, UUIDs in PHP

Simple and safe random getters to copy-paste

string randomBytes( int $length )

int randomInt ( int $min , int $max )

string randomUuid ( void )
@tom--
tom-- / TestU01_BigCrush_results.txt
Last active June 17, 2016 00:01
Tests of PHP mt_rand()
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Starting BigCrush Starting BigCrush
Version: TestU01 1.2.3 Version: TestU01 1.2.3
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
*********************************************************** ***********************************************************
Test smarsa_SerialOver calling smultin_MultinomialOver Test smarsa_SerialOver calling smultin_MultinomialOver
*********************************************************** ***********************************************************
<?php
$a = [1, 3];
foreach ($a as $v) {
var_dump($v);
$a[1] = 9;
}
---
- name: Add APT repo key
apt_key:
url: "https://download.newrelic.com/548C16BF.gpg"
id: "548C16BF"
state: "present"
- name: Add APT repo
apt_repository:
@tom--
tom-- / mt_rand() PHP 7.1 statistical tests.md
Last active July 27, 2016 15:59
Statistical testing of updated mt_rand() in PHP 7.1 using PractRand and Dieharder
@tom--
tom-- / Persister.php
Last active November 29, 2016 18:24
Conceptual demo of data mapping in a Yii webapp. It's no prototype to elaborate into real software. It's only an object of philosophical contemplation.
<?php
/**
* A global Persister "static" class isolates the location of any persistence logic from its users.
* In this example, persitence logic for UserMovieRating objects is located in this class but it
* could be moved around ad hoc.
*/
class Persister
{
private static function _UserMovieRatingSave(UserMovieRating $object)
@tom--
tom-- / slug.php
Last active November 25, 2016 17:08
Make a slug for an earl in PHP
<?php
function slug(string $string, int $width = 100) : string
{
$string = Normalizer::normalize($string);
$string = trim(preg_replace('/[^\pL\p{Nd}]+/u', ' ', $string));
$string = strtr($string, ' ', '-');
return mb_strimwidth($string, 0, $width, '', 'UTF-8');
@tom--
tom-- / straight_join.sql
Last active May 20, 2017 21:11
Is a STRAIGHT_JOIN like a LEFT JOIN or like an INNER JOIN? (MySQL)
create table t (
id int primary key,
r_id int,
c tinyint(1) default 0
);
create table r (
id int primary key,
c tinyint(1) default 0
<?php
namespace v2\helpers;
use yii\helpers\Console;
/**
* Error code constane names, values, and descriptions are taken from
* OpenBSD's sysexits(3) man page http://man.openbsd.org/sysexits
*/
@tom--
tom-- / README.md
Last active October 14, 2017 19:47
Controling a group of daemons and timer jobs with a systemd target

Controling a group of daemons and timer jobs with a systemd target

Scenario

The custom web application My App, in addition to its web server request-driven work, has three daemons (able, baker and charlie) and three jobs (dog, easy and fox) that run (cron-like) on a pre-defined schedule.

Requirements