Tuesday, July 7, 2015

Mocking PHP functions in PHPUnit test

It relies on using namespaces. Call to PHP function must be in the form time() and not \time().

Class to test(Example.php):
<?php
namespace Example;
class Example {
    public function doSomething()
    {
         return time();
    }
}


Test class(ExampleTest.php):
<?php
namespace Example {
    function time()
    {
        return 5;
    }
}
namespace ExampleTest {
    use Example\Example;

    class ExampleTest extends \PHPUnit_Framework_TestCase {
        protected $sut;

        public function setUp()
        {
             $this->sut = new Example();
        }

        public function testDoSomething()
        {
             $this->assertSame(5, $this->sut->doSomething());
        }
    }
}


Note: Auto loading of classes is omitted.

Tuesday, May 12, 2015

Getting youtube's subscriptions RSS


1. Login in Youtube
2. Click the links in order specified below:


3. Scroll to the bottom of the page (you may adjust subscriptions before that if you like):

4. Import downloaded file in your favorite RSS reader.

Thursday, December 25, 2014

How to enable CUDA for Freemake Video Converter for drivers after 337.88

For NVidia drivers after 337.88 CUDA option is unavailable:



1. Download 337.88 WHQL driver from NVidia website
2. Extract it to some folder with 7z
3. In Display.Driver folder extract nvcuvenc32.dl_ with 7z to nvcuvenc32.dll and rename it to nvcuvenc.dll
4. Copy nvcuvenc.dll to the  Freemake installation folder

The end result:


Note: NVidia drivers 347.09@GTX970, Freemake VC 4.1.5

Saturday, December 20, 2014

ADATA SP920SS 256GB vs KINGSTON SV300S37A 240G vs ADATA NH13 USB 1TB

SP920 256GB:



SV300S37A 240GB:


24% free space

87% free space

ADATA NH13 1TB



Kingston results are not very impressive, but it has somewhat nice price and it is quieter than standard HDD. ADATA NH13 contains  TOSHIBA MQ01ABD100/SATA2/5400/8MB drive. Here is benchmark on H97/i5/16GB RAM System with 2TB Seagate (Seagate2000DM001) disk:


Note: I just run the benchmarks no additional setup was made so I do not pretend they to be 'valid'. I hope someone finds them useful.

Saturday, November 29, 2014

Creating Windows Recovery Partition with AOMEI OneKey

Preconditions
 Installed Windows
 System Reserved partition is available

Steps
1. Install AOMEI OneKey backup
2. Run it and create recovery partition
3. Add a letter to the system reserved partition (one created during windows installation) - for example X:
4. Run command prompt as administrator and type the following commands:


bcdboot c:\windows /s x:
bcdedit /set {3940e26a-75e7-11e4-bfda-88dcdc879809} device partition=X:

where {3940e26a-75e7-11e4-bfda-88dcdc879809} is identifier of AOMEI entry (you can check it with bcdedit without parameters)

5. Move okldr.mbr, okcf.lst and okldr from C:'s root to X:'s
6. Remove letter from system reserved partition
7. (Optional) Test recovery

Note: When you run OneKey to recover, it will restore boot manager to the state when it was run i.e. AOMEI boot entry will point to C: - just repeat steps 3-6.

This covers the case when OS partition is formatted or essential files are deleted which in standard way won't work because AOMEI boot files are on OS partition..

Wednesday, July 16, 2014

Veeam Backup Free Edition Rant

I wanted to try this 'free' tool the ads for which were poking my eyes for a long time, but :


They want not only my phone but they do not accept 'public' email address. Also if you think that in the following screen:

you can sign in using Google+ account for example - think again (and read the underlined text). You will need to create account anyway. I don't want to link my Google+ account I want to log in with it and download the damn tool. In fact if the tool is free - I don't want to log in at all.

My conclusion: I am not the target audience. Whatever.

EDIT: Found it on Softpedia (no registration required).
EDIT 2: Softpedia version is 7.0.0.690 which does not support vSphere 5.5 . You need to download at least R2 patch which leads to the registration problem.

PS. Tried some alternatives:
1. NAKIVO Free Edition - does not support Free ESXi
2. Trilead VM Explorer - does not support latest version of ESXi 5.5 (2014-07-01) , but looks promising and probably when updated will support it.

EDIT 3: Latest 5.0.031.0 works and looks it will do :)

For the moment decided to use WinSCP + SSH on the host. Speed was around 100Mbit which works for me.

PS. After switching to 1000Mbit  had to enable rc4 and blowfish ssh ciphers on the server to get more than 20MB/s. By default only aes ciphers are enabled.



Saturday, July 12, 2014

Monday, July 7, 2014

CM HAF XB EVO and Corsair HX1000




The distance between HDD cage and PSU is 40mm. I removed hotplug board - it is getting bad reviews anyway. HX1000 is 200mm long modular PSU.

Monday, June 9, 2014

PHPUnit XML Schema for use with Netbeans

Here is a XML schema heavily annotated to ease creation of phpunit.xml configuration file for PHPUnit when edited in Netbeans IDE. I have used official one for version 4.1.1 as a starting point. See phpunit.md for usage information.

Sunday, May 18, 2014

How to import cookies and bookmarks in Firefox from Opera 15+

In support article Import bookmarks from Google Chrome you can see that it is possible to import cookies and bookmarks from Chrome. Since Opera switched to Webkit from version 15 it turns out they use the same format. To import from Opera to Firefox do the following:

  1. Backup your Chrome's cookies and bookmarks, usually located at C:\Users\<your_username>\AppData\Local\Google\Chrome\User Data\Default\ . There are 4 files: BookmarksBookmarks.bak, Cookies and Cookies-journal.
  2. Overwrite the previous  4 files with Opera's ones, usually located at C:\Users\<your_username>\AppData\Roaming\Opera Software\Opera Stable\
  3. Follow Mozilla procedure above (select cookies and bookmarks to import)
  4. Restore Google's cookies.

Thursday, April 17, 2014

Repair Windows Store

If after cleanup you accidentally deleted Windows store files from your profile directory - the store will not work anymore. Here is how I repaired mine:
  1. Create a new user
  2. Log in as the new user (you will need to wait a little)
  3. Go to store
  4. Install an app
  5. Sign out
  6. Log in as your regular user
  7. Copy folder starting with WinStore_xxxxxxxx from the new user profile located in C:\Users\<New User>\AppData\Local\Packages to corresponding location in your profile directory.
  8. Check if the store is working
  9. Reinstall all your store applications
  10. Delete the new user (optional)

Thursday, January 16, 2014

How to enable APC caching for Doctrine Zend 2 module

  
 array(
        'connection'    => array(
            // connection configuration
        ),
        'configuration' => array(
            'orm_default' => array(
                'generate_proxies' => false,
                'metadata_cache'   => 'apc',
                'query_cache'      => 'apc',
                'result_cache'     => 'apc',
            ),
        ),
    )
);

You can see list of other types of supported caches in the doctrine module source.

How to generate doctrine entities from database

Following command is executed from /home/projects/zend-skeleton/vendor/bin folder:
  
./doctrine-module orm:convert-mapping --from-database annotation --namespace="Application\Entity\\" 
/home/projects/zendskeleton/module/Application/src
Note: In the latest version of doctrine module you can also run it from project root directory like this:
  php public/index.php orm:convert-mapping --from-database annotation --namespace="Application\Entity\\" 
/home/projects/zendskeleton/module/Application/src
Generated entities will be in folder /home/projects/zendskeleton/module/Application/src/Application/Entity/ and will have namespace Application\Entity. If you have enum types in the database you have to add following lines to application configuration:

 'doctrine_type_mappings' => array(
  'enum' => 'string'
 );
  
so it looks like this:

 array(
        'connection' => array(
            'orm_default' => array(
               'driverClass'=>'Doctrine\DBAL\Driver\PDOMySql\Driver',
               'params'      => array(
                   'host'     => 'localhost',
                   'dbname'   => 'xxxx',
                   'user'     => 'xxxx',
                   'password' => 'xxxx'
               ),
               'doctrine_type_mappings' => array(
                   'enum' => 'string'
               )
            ),
        )
    )
);
  

Saturday, November 2, 2013

How to setup Phalcon framework under Windows 8 for PHP 5.5 and Netbeans

Compiling PHP extension

  1. Download and install Microsoft Visual Studio Express 2012. Microsoft removed it from downloads - for the moment you can find it at Softpedia .
  2. Create the folder C:\php-sdk
  3. Unpack the binary-tools archive (php-sdk-binary-tools-20110915.zip) into this directory, there should be one sub-directory called bin and one called script
  4. Open VS2012 x86 Native Tools Command Prompt (it's available from the start menu group)
  5. Execute the following commands:
    cd c:\php-sdk\
    bin\phpsdk_setvars.bat
    bin\phpsdk_buildtree.bat php
    
  6. Create C:\php-sdk\php\vc11 directory and copy content from vc9 one
  7. Extract PHP source code for Windows (you can download it from http://windows.php.net/downloads/releases/) in C:\php-sdk\php\vc11\x86
  8. Download  libraries required to build PHP and extract them in C:\php-sdk\php\vc11\x86\deps
  9. Create directory C:\php-sdk\php\vc11\x86\php\ext\phalcon 
  10. Download Phalcon source from Github
  11. Copy files from Phalcon source build\32bits directory in C:\php-sdk\php\vc11\x86\php\ext\phalcon 
  12. Run following commands:
    cd C:\php-sdk\php\vc11\x86\php
    buildconf
    configure --disable-all --enable-cli --enable-phalcon=shared
    nmake
    
  13. The php_phalcon.dll after the compilation is located in C:\php-sdk\php\vc11\x86\Release_TS\
Note: Above steps are based on https://wiki.php.net/internals/windows/stepbystepbuild and http://internals.phalconphp.com/en/latest/reference/compilation.html . They are for building 32-bit version of extension . Precompiled version for PHP 5.5.5 is here .

Enable Phalcon extension

In php.ini add following:
extension=php_phalcon.dll

Configure code completion for Netbeans

  1. Download Phalcon Developer Tools . How to setup them is described in documentation 
  2. In ide directory there is gen-stubs.php script. You have to point 'CPHALCON_DIR' to where your extracted phalcon source is, then run:
    php ide/gen-stubs.php
    This will create ide subdirectory in which you will find directory with your Phalcon version as name. In latter there is Phalcon subdirectory - copy it in your Netbeans php\phpstubs\phpruntime directory. Now you will have code completion for Phalcon.

Monday, October 21, 2013

Codeception: Phantomjs setup for WebDriver when using self-signed SSL certificate

When using phantomjs as browser for acceptance tests with WebDriver in Codeception - if the targeted site is using self-signed SSL certificate tests will fail. To avoid that - phantomjs must be started with --ignore-ssl-errors=true command line option. Here is an example acceptance.suite.yml configuration:

# Codeception Test Suite Configuration
# suite for acceptance tests.
# perform tests in browser using the Selenium-like tools.
# powered by Mink (http://mink.behat.org).
# (tip: that's what your customer will see).
# (tip: test your ajax and javascript by one of Mink drivers).

# RUN `build` COMMAND AFTER ADDING/REMOVING MODULES.

class_name: WebGuy
modules:
    enabled: [WebDriver, WebHelper]
    config:
        WebDriver:
            url: 'https://example.com/'
            browser: phantomjs
            capabilities:
                phantomjs.cli.args: ['--ignore-ssl-errors=true']
Another alternative is to use method from Ghostdriver documentation - Register GhostDriver with a Selenium Grid hub

Thursday, July 18, 2013

First post. Setting up syntax highlighting.

I am using highlightjs. Go to Design->Template->Edit HTML. Add following snippet to the end of head section:

  <head>
        ...
     <link href='http://yandex.st/highlightjs/8.0/styles/sunburst.min.css' rel='stylesheet'/>
     <script src='http://yandex.st/highlightjs/8.0/highlight.min.js'/>
     <script type='text/javascript'>
         hljs.configure({tabReplace: '    '});
         hljs.initHighlightingOnLoad();
     </script>
  </head>
The result:

<?php
  echo 'Hello world!';