'php' Category

  • Dynamic sleep for infinite loops based on cpu

    May 11, 2017

    Based on this function http://ivangospodinow.com/php-how-to-calculate-system-processors-load-in-percent/ we are getting current cpu load. usleep(1000000 * systemLoadInPercent() / 100); Result: 54.3% cpu load, sleep 0.543 sec  

  • Why using getArrayCopy and exhangeArray ?

    January 7, 2017

    Because that is what php are using in ArrayObject

  • Monty Hall Problem in PHP

    November 23, 2016

    define('HAS_PRICE', true); define('HAS_NO_PRICE', false); $tries = 0; $won = 0; $wonFirst = 0; $i = 0; $pick = 0; /** * Bottom line, you play against being wrong the first time */ while (++$i

  • PHP Games – Solution to The Impossible Bet

    April 8, 2016

    /** * 100 people put a number in box. * every one must find his box within 50 tries */ $allTries = 100000; $usedTries = $allTries; $players = 50; $tries = 25; $settings = []; $people = []; for ($i = 0; $i < $players; $i++) { $settings[$i] = $i; $people[$i] = $i; } $mostPeopleWon […]

  • Set php error_log dynamicaly in .htaccess

    September 20, 2015

    1. Open your .htaccess file and add this lines to be bottom. 2. Create your php.error.log file. php_value log_errors 1 php_value error_log ./php.error.log If your file is still empty, add in your php error_reporting(E_ALL); Simple as that

  • Creating issues in Jira for multiple users with Jira API

    September 12, 2015

    1. Creating Jira issue $jiraUsername = 'Jira login username'; $jiraPassword = 'Jira login password'; $jiraHost = 'http://my-jira-host.com/'; $data = array( 'fields' => array( 'project' => array('key' => 'PR'/* Project Key*/), 'summary'=> 'Issue title', 'description' => 'Some text here, no html tags', 'labels' => array('API', 'IvanGospodinow'/* Put the username so you know which one added it […]

  • Copy big MySQL database with php in 5 steps

    July 17, 2015

    1. Dump structure of the big database. 2. Open the sql file and cut the constraints. 3.  Import the structure to another database. 4. Run this code: /** * Sync from live database */ ini_set('memory_limit','512M'); $limit = 100000; $time = time(); $sleep = 1; $sleepEvery = 60; $link = new mysqli( “__HOST__”, “__USER__”, “__PASSWORD__”, “__DATABASE__” […]

  • Warning: Division by zero – easy way to get arround?

    September 26, 2014

    $sum = [0, 0, 0, 0]; echo count($sum) / array_sum($sum); // Warning: Division by zero $arraySum = 0.00001 + array_sum($sum); $number = count($sum) / $arraySum; echo round($number, 2); // Result is 0; Just add some small number to the one you are not sure that it will be bigger than zero. Easy as that.

  • Zend Framework 2 Cache Proxy – Cache Based Key Dependency.

    July 5, 2014

    Long time no ZF2 post, but here is something interesting peace of code that can solve cache problems present in most of the projects. I am assuming that, the reader knows how to create custom cache Factory in ZF2. Step 1. Edit your existing cache factory. See Line 35. namespace Application\Factory; use Application\Factory\CacheProxy; // Or […]

  • How to create google login on my site with openid in 5 min

    August 21, 2013

    As always we go straight to coding. Download how-to-create-google-login-on-my-site-with-openid-in-5-min.zip

 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org