Skip to content

Instantly share code, notes, and snippets.

View yoterri's full-sized avatar

Yassir Terri Mejia yoterri

View GitHub Profile
@yoterri
yoterri / remaining_time.php
Last active September 27, 2017 16:30
calculates the remaining time for a given CLI script
$time_start = microtime(true);
$total = '10000' // records count;
for($i=0; $i <= $total; $i++)
{
$counter++;
$remaining = ($total - $counter);
$timeTaken = microtime(true) - $time_start;
$linesProcessed = $counter;
@yoterri
yoterri / strong-passwords.php
Created June 16, 2016 19:50 — forked from tylerhall/strong-passwords.php
A user friendly, strong password generator PHP function.
<?PHP
// Generates a strong password of N length containing at least one lower case letter,
// one uppercase letter, one digit, and one special character. The remaining characters
// in the password are chosen at random from those four sets.
//
// The available characters in each set are user friendly - there are no ambiguous
// characters such as i, l, 1, o, 0, etc. This, coupled with the $add_dashes option,
// makes it much easier for users to manually type or speak their passwords.
//
// Note: the $add_dashes option will increase the length of the password by
@yoterri
yoterri / course_get_parent_categories
Created July 18, 2014 12:26
Moodle. Get parent categories for a course
/**
*
* Get parent categories for a course
*
* @param stdClass|int $course
* @return array
*/
function course_get_parent_categories($course)
{
global $DB;
/**
*
* @param int $min
* @param int $max
* @param int $type 1=alpha|2=alnum|3=numeric
* @return string|int
*/
function app_random($min = 6, $max = 10, $type = 1)
{
$letters = 'abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ';
function header_status($statusCode, $exit = false)
{
static $statusCodes = null;
if ($statusCodes === null)
{
$statusCodes = array (
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
function cut_word($text, $max)
{
if(strlen($text) > $max)
{
if(substr($text, 0, ($max + 1)) != ' ')
{
$text = substr($text, 0, $max);
$exploded = explode(' ', $text);
array_pop($exploded);