Skip to content

Instantly share code, notes, and snippets.

Avatar

Larry Browning kdallas

View GitHub Profile
@kdallas
kdallas / mt_shuffle.php
Created Nov 4, 2016
A substitute for the php shuffle() function using mt_rand(), i.e. the Mersenne Twister algorithm - for improved randomness
View mt_shuffle.php
<?php
function mt_shuffle(&$array) {
$randArr = [];
$arrLength = count($array);
// while my array is not empty I select a random position
while (count($array)) {
//mt_rand returns a random number between two values
$randPos = mt_rand(0, --$arrLength);
@kdallas
kdallas / Account.php
Created Oct 29, 2015
Instant response for October CMS Flash messages combined with Romanov.Flashmessage plugin (no page reload)
View Account.php
<?php namespace RainLab\User\Components;
use Lang;
use Auth;
use Mail;
use Flash;
use Input;
use Request;
use Redirect;
use Validator;
@kdallas
kdallas / index.php
Last active Feb 26, 2017
CloudFlare DDNS updater, inspired by: http://bit.ly/2mqyiwI -- I put this on a server that I know is going to be up 24/7, and pointed my DD-WRT router to it for Dynamic DNS updates.
View index.php
<?php
/*
http://SOME_RELIABLE_SERVER/update_cloudflare/CLOUDFLARE_EMAIL/CLOUDFLARE_API-KEY/HOST
...where "update_cloudflare" is a directory containing this file (index.php)
...and the URL slug/segments are parsed with the following regex:
RewriteRule ^/update_cloudflare/([^/]+)?/?([^/]+)?/?(.*) /update_cloudflare/index.php?e=$1&k=$2&h=$3 [L,QSA]
which sends the following GET params: