2016年1月26日 星期二

Whoops exception callback handler

You would want to use a callback handler.
$whoops = new WhoopsRun();
$handler = new WhoopsCallbackHandler(function($exception, $inspector, $run) {
    //send an email
});
$whoops->pushHandler($handler)->register();
It looks like you are using use statement aliases so I matched your format, but the class is called Whoops\Handler\CallbackHandler.

reference : http://stackoverflow.com/questions/29281480/php-whoops-error-handler-email

2016年1月20日 星期三

PHPUnit Serialization of closure exception

Not technically related to your issue. However, I had a really hard time trying to solve the "Serialization of 'Closure' is not allowed" issue while using PHPUnit, and this question is the top Google result.
The problem comes from the fact that PHPUnit serializes all the $GLOBALS in the system to essential back them up while the test is running. It then restores them after the test is done.
However, if you have any closures in your GLOBAL space, it's going to cause problems. There's two ways to solve it.
You can disable the global backup procedure totally by using an annotation.
/**
 * @backupGlobals disabled
 */
class MyTest extends PHPUnit_Framework_TestCase
{
    // ...
}
Or, if you know which variable is causing the problem (look for a lambda in var_dump($GLOBALS)), you can just blacklist the problem variable(s).
class MyTest extends PHPUnit_Framework_TestCase
{
    protected $backupGlobalsBlacklist = array('application');
    // ...
}


reference : http://stackoverflow.com/questions/4366592/symfony-2-doctrine-2-phpunit-3-5-serialization-of-closure-exception

2016年1月17日 星期日

How to get the file extension in PHP?


No need to use string functions. You can use something that's actually designed for what you want: pathinfo():
$path = $_FILES['image']['name'];
$ext = pathinfo($path, PATHINFO_EXTENSION);
reference : http://stackoverflow.com/questions/10368217/how-to-get-the-file-extension-in-php

How do you get a timestamp in JavaScript?

On almost all current browsers you can use Date.now() to get the UTC timestamp in milliseconds; a notable exception to this is IE8 and earlier (see compatibility table).
You can easily make a shim for this, though:
if (!Date.now) {
    Date.now = function() { return new Date().getTime(); }
}
To get the timestamp in seconds, you can use:
Math.floor(Date.now() / 1000)
Or alternatively you could use:
Date.now() / 1000 | 0
Which should be slightly faster, but also less readable (also see this answer).
I would recommend using Date.now() (with compatibility shim). It's slightly better because it's shorter & doesn't create a new Date object. However, if you don't want a shim & maximum compatibility, you could use the "old" method to get the timestamp in milliseconds:
new Date().getTime()
Which you can then convert to seconds using the same method as above.

reference : http://stackoverflow.com/questions/221294/how-do-you-get-a-timestamp-in-javascript

2016年1月13日 星期三

Increase IntelliJ IDEA IDE memory

For Mac OS X systems: 
Since version 12.0.0: The file /Applications/IntelliJ Idea XX.app/bin/idea.vmoptions or /Applications/IntelliJ Idea CE XX.app/bin/idea.vmoptions should be copied to ~/Library/Preferences/IntelliJIdeaXX/idea.vmoptions or ~/Library/Preferences/IdeaICXX/idea.vmoptions
Since version 14.0.0:
The file /Applications/IntelliJ Idea XX.app/Contents/bin/idea.vmoptions or /Applications/IntelliJ Idea CE XX.app/Contents/bin/idea.vmoptions should be copied to ~/Library/Preferences/IntelliJIdeaXX/idea.vmoptions or ~/Library/Preferences/IdeaICXX/idea.vmoptions
For the older versions, the settings are stored in /Applications/IntelliJ IDEA .app/Contents/Info.plist.

The final file should look like:
-Xms128m
-Xmx2048m
-XX:MaxPermSize=350m
-XX:ReservedCodeCacheSize=64m
-XX:+UseCodeCacheFlushing
-XX:+UseCompressedOops

reference:
https://www.jetbrains.com/idea/help/tuning-intellij-idea.html
http://stackoverflow.com/questions/13578062/how-to-increase-ide-memory-limit-in-intellij-idea-on-mac


2016年1月11日 星期一

I need to mock a php native function

I had the same problem a few months ago. This is what worked for me:
You could namespace your test with the namespace of the class under test. Then, before the test class, create the function in that namespace, like this:
 namespace The\Same\Like\The\Class\Under\Test

use \Mockery;

function shell_exec($cmd)
{
  return YourTest::$functions->shell_exec($cmd);
}

class YourTest extends \PHPUnit_Framework_TestCase {
  public static $functions;

  public function setUp()
  {
    self::$functions = Mockery::mock();
  }
}
Now, when you're testing your class, and want to mock the function, you could write it like this:
    self::$functions->shouldReceive('shell_exec')->with($cmd)->once();
Or in whatever way you want to mock it.
In phpspec:
This is exactly why I didn't use phpspec when I had this problem.
I think (but not sure) that with a phpspec approach in mind, you would wrap the shell command in a class, like this:
class Shell{
  public function exec($cmd)
  {
    return shell_exec($cmd);
  }
}
I guess, there's no need to test this class, since it's just a wrapper. Then, you would use this class instead of the function in your other classes, and when it comes to mocking, you could mock this class.

reference : https://laracasts.com/discuss/channels/testing/i-need-to-mock-a-php-function

How to check is XDebug is installed or not

function isXDebugInstalled(){    return function_exists('xdebug_get_code_coverage') ? true : false;}

2016年1月10日 星期日

How do I turn off the rootless in OS X El Capitan 10.11?

(As you will be restarting your OS X device. It might be helpful to print these instructions or access them from a different device).

To disable the rootless feature, reboot your OS into Recovery Mode, to do this:
  • Restart your Mac, and as soon as the screen turns black hold down ⌘R until the Apple logo appears on your screen.

     
  • You have successfully entered Recovery Mode if you see this:
  • Now click on the "Utilities" menu, and then "Terminal".


  • In the Terminal Window type:

    csrutil disable

    Press return, you should then see the following message


  • Restart OS X, your Mac should then restart as normal with SIP disabled,
To re-enable System Integrity Protection, do this:
  • Restart OS X again and hold down ⌘R as earlier, until you see the Apple Logo
  • Now click on Utilities", then "Terminal".
  • In the Terminal Window type:

    csrutil enable

    Then press the return key, you should then see the following message


  • Restart OS X, Your Mac should then restart as normal.
  • Done!

reference : https://www.quora.com/How-do-I-turn-off-the-rootless-in-OS-X-El-Capitan-10-11

2016年1月7日 星期四

PIE

PIE makes Internet Explorer 6-9 capable of rendering several of the most useful CSS3 decoration features.

reference : http://css3pie.com/

wibiya widget