Thursday, September 15, 2016

Failed to install VirtualBox additions

That problem could be solved like this
sudo apt-get install dkms build-essential make gcc automake libssl-dev linux-headers-generic autoconf checkinstall intltool libtool module-assistant perl python python3
sudo reboot
After this install VirtualBox additions as usual.

Tuesday, September 6, 2016

Running nmp and grunt

I'll show you how to work with npm and grunt on a theme from GitHub. The root folder must contain files package.json and Gruntfile.js.

$ git clone --depth=1 https://github.com/thomaspark/bootswatch.git
Cloning into 'bootswatch'...
remote: Counting objects: 1965, done.
remote: Compressing objects: 100% (1059/1059), done.
remote: Total 1965 (delta 640), reused 1606 (delta 509), pack-reused 0
Receiving objects: 100% (1965/1965), 6.57 MiB | 708.00 KiB/s, done.
Resolving deltas: 100% (640/640), done.

$ cd bootswatch/

$ ls -l | grep package.json
-rw-r--r-- 1 korisnik 197121   683 Sep  7 00:44 package.json

$ npm install <========== download dependencies as stated in package.json into node_modules folder
... removed ...

$ ls -l
total 183
... removed ...
drwxr-xr-x 1 korisnik 197121     0 Sep  7 00:46 node_modules/
... removed ...

$ ls -l | grep Gruntfile.js
-rw-r--r-- 1 korisnik 197121  9688 Sep  7 00:44 Gruntfile.js <===========we have grunt file so we can run grunt tasks

$ grunt
Running "connect:base" (connect) task
Started connect web server on http://0.0.0.0:3000

Running "watch" task
Waiting...OK
>> File "lumen\variables.less" changed.  <========= I edited this file 

Running "build" task

Running "concat:dist" (concat) task
File "lumen/build.less" created. 

Running "less:dist" (less) task
File ./lumen/bootstrap.css created. <========= grunt recompiled less into css file

Running "prefix:<%=builddir%>/lumen/bootstrap.css" (prefix) task

Running "autoprefixer:dist" (autoprefixer) task
File ./lumen/bootstrap.css created.

Running "clean:build" (clean) task
Cleaning lumen/build.less...OK

Running "compress:<%=builddir%>/lumen/bootstrap.css:<%=builddir%>/lumen/bootstrap.min.css" (compress) task
compressing file <%=builddir%>/lumen/bootstrap.css <========= grunt compressed css file

Running "less:dist" (less) task
File ./lumen/bootstrap.min.css created.

Running "watch" task
... Reload lumen\variables.less ...  
Completed in 4.016s at Wed Sep 07 2016 00:53:13 GMT+0200 (Central Europe Daylight Time) - Waiting...


Many repos don't have grunt file. So you may need to install and run server your self.

Saturday, September 3, 2016

Running Solr on Windows with SimplePostTool

This tutorial covers Java 1.8.0_101 and Apache Solr 5.5.2 on Windows.
Your PATH variable will not be changed. I used full path to cmd/jar file.
I also didn't use Claspath.

c:\Users\UserName\Documents\solr-5.5.2>c:\Users\UserName\Documents\solr-5.5.2\bin\solr.cmd version
5.5.2

c:\Users\UserName\Documents\solr-5.5.2>c:\Users\UserName\Documents\solr-5.5.2\bin\solr.cmd start
Waiting up to 30 to see Solr running on port 8983
Started Solr server on port 8983. Happy searching!

c:\Users\UserName\Documents\solr-5.5.2>c:\Users\UserName\Documents\solr-5.5.2\bin\solr.cmd create -c texas

Copying configuration to new core instance directory:
c:\Users\UserName\Documents\solr-5.5.2\server\solr\texas

Creating new core 'texas' using command:
http://localhost:8983/solr/admin/cores?action=CREATE&name=texas&instanceDir=texas

{
  "responseHeader":{
    "status":0,
    "QTime":10199},
  "core":"texas"}

c:\Users\UserName\Documents\solr-5.5.2>java -jar example/exampledocs/post.jar -h

c:\Users\UserName\Documents\solr-5.5.2>java -Dtype=text/csv -Dc=texas -jar example/exampledocs/post.jar *.csv

c:\Users\UserName\Documents\solr-5.5.2>java -Dauto -Dc=texas -jar example/exampledocs/post.jar fajlovi

c:\Users\UserName\Documents\solr-5.5.2>java -Ddata=web -Dfiletypes=html -Dc=texas -jar example/exampledocs/post.jar http://example.com

More from official docs https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser
proximity search
  • "lorem amet"~20
search JSON document
  • id:978-1423103349
  • also see image
  • cat:book OR text:hardcover

Solr filters and query


Delete all indexed documents

$ curl localhost:8983/solr/texas/update -H "Content-type: text/xml" --data-binary '*:*'
$ curl localhost:8983/solr/texas/update -H "Content-type: text/xml" --data-binary ''

Stop Solr server

c:\Users\UserName\Documents\solr-5.5.2>c:\Users\UserName\Documents\solr-5.5.2\bin\solr.cmd stop -all
Stopping Solr process 5228 running on port 8983

Waiting for 0 seconds, press a key to continue ...

Thursday, August 18, 2016

Create New MySQL User and his Database

Create new MySQL user and database

create database eddy;
create user eddy@localhost identified by 'gt84weu$rA^o#HB';
grant all on eddy.* to eddy identified by 'gt84weu$rA^o#HB';

This snippet should be run from MySQL command line.

Thursday, October 22, 2015

Webgrind profiling in WAMP

You can get list of all PHP functions and their arguments that were executed with Webgrind extension. In URL of page put XDEBUGPROFILE=true as shown on video.



You need to setup your php.ini like this
; XDEBUG Extension

zend_extension = "c:/wamp/bin/php/
php5.5.12/zend_ext/
php_xdebug-2.2.5-5.5-vc11-x86_64.dll"
;
[xdebug]
xdebug.remote_enable = 1
xdebug.profiler_enable = 1
xdebug.profiler_enable_trigger = 1
xdebug.profiler_output_name = cachegrind.out.%t.%p
xdebug.profiler_output_dir = "c:/wamp/tmp"
xdebug.show_local_vars=0
Keep in mind that WAMP has two php.ini files. So you need co change the right one.

Friday, October 16, 2015

PHPUnit Testing in Composer Project

install PHPUnit

wget https://phar.phpunit.de/phpunit.phar
chmod +x phpunit.phar
mv phpunit.phar /usr/local/bin/phpunit

now phpunit is accessible globally

download some project from git that contains "Tests" folder and composer.json

git clone --depth=1 https://github.com/domnikl/DesignPatternsPHP.git
composer install

see if there is phpunit.xml.dist file in project root

cat phpunit.xml.dist 
phpunit bootstrap="./vendor/autoload.php" colors="true">
    <testsuites>
        <testsuite name="Design Patterns">
            <directory suffix="Test.php">Behavioral/*/Tests</directory>
            <directory suffix="Test.php">Creational/*/Tests</directory>
            <directory suffix="Test.php">More/*/Tests</directory>
            <directory suffix="Test.php">Structural/*/Tests</directory>
        </testsuite>
    </testsuites>
    <filter>
        <blacklist>
            <directory>./vendor</directory>
        </blacklist>
    </filter>
</phpunit>

From project root run this

phpunit -vvv
PHPUnit 5.6.1 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.0.8-0ubuntu0.16.04.2
Configuration: /var/www/html/DesignPatternsPHP/phpunit.xml.dist

................................................................. 65 / 68 ( 95%)
...                                                               68 / 68 (100%)

Time: 839 ms, Memory: 10.00MB

OK (68 tests, 208 assertions)

or you can run one test on single file also from project root

phpunit Structural/Composite/Tests/CompositeTest.php
PHPUnit 5.6.1 by Sebastian Bergmann and contributors.

.                                                                   1 / 1 (100%)

Time: 103 ms, Memory: 8.00MB

OK (1 test, 1 assertion)

detailed output for each test

phpunit --testdox
PHPUnit 5.6.1 by Sebastian Bergmann and contributors.

DesignPatterns\Behavioral\ChainOfResponsibilities\Tests\Chain
 [x] Can request key in fast storage
 [x] Can request key in slow storage

DesignPatterns\Behavioral\Command\Tests\Command
 [x] Invocation
...

Inside DesignPatternsPHP/Structural/Composite/TestsCompositeTest.php you can put method like this

public function testMyMethod(){
   print __METHOD__;
   $this->assertEquals("abcd", "abc");
}

and run phpunit --verbose you'll get

1) DesignPatterns\Structural\Composite\Tests\CompositeTest::testMyMethod
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'abcd'
+'abc'

Also you'll get name of method in output in 65th test.

XDebug in Eclipse

How to debug a PHP script in eclipse like C program in Visual Studio.