'php' Tag

  • 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

  • HTTP Request showing progress on background task without ajax

    November 17, 2016

    The idea: show progress for process that is running in the background Execution: takes advantage of the fact that JavaScript is loaded in parallel ignore_user_abort(); set_time_limit(3600); session_write_close(); @ob_end_clean(); @ob_end_flush(); @header('Content-Encoding: text/html'); echo 'I am doing some very very very long job '; $taskId = uniqueId(); touch($taskId); echo ''; echo 'Doing it '; while (file_exists($taskId)) { […]

  • 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

  • Zf2 Doctrine 2 Log Every Entity Change

    September 18, 2015

    In this article I will show a simple way to log every change to doctrine 2 entity. This one will not be copy / paste. Just check out the code and help yourself. 1. Create event service /** * @developer Ivan Gospodinow */ namespace Application\Service; use Application\Entity\DbLogEntity; use Application\Entity\AbstractEntity; use Doctrine\Common\Persistence\Event\LifecycleEventArgs; use \DateTime; class DoctrineLogChangesService […]

  • Zend Framework 2 change layout for ajax requests

    September 15, 2015

    How to change layout for ajax requests in Zend Framework 2 1. Module.php public function onBootstrap(MvcEvent $e) { $e->getApplication() ->getEventManager() ->getSharedManager() ->attach( 'Zend\Mvc\Controller\AbstractController', 'dispatch', function ($e) { $controller = $e->getTarget(); if ($controller->getRequest() instanceof HttpRequest) { if ($controller->getRequest()->isXmlHttpRequest()) { $controller->layout('layout/ajax'); } } }, 100 ); } 2. module.config.php Add the layout path 'view_manager' => array( 'template_map' […]

  • 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 […]

  • 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


Warning: Use of undefined constant XML - assumed 'XML' (this will throw an Error in a future version of PHP) in /home/c2kblate/sites/ivangospodinow.com/wp-content/plugins/wp-syntaxhighlighter/wp-syntaxhighlighter.php on line 1048
 
Powered by Wordpress and MySQL. Theme by Shlomi Noach, openark.org