Sunday, October 30, 2016

mod_rewrite testing with XAMPP should be done carefully. RewriteCond %{REQUEST_FILENAME} !-f can cause some confusion

Web Server: XAMPP (both applies to other packages as well)

Problem: Strange , unexpected results from simple .htaccess mod_rewrite operations. RewriteRule doesn't seem to work.


When you would like to test your apache's .htaccess URL rewrite, make sure you test with a proper URL.

For example, if you have a RewriteRule like this:


RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ".*/$1" "/public/index.php?p=pageabc&t=$1" [NC,L,R=301]

Make sure you're testing your site with a URL like this:
http://yoursite.com/test-term

and not with something like this:

http://yoursite.com/public/index.php?***********************

The reason is obvious. The first RewriteCond won't be true and the rule won't apply.

Also, please note that by default, the url directory to your .htaccess file is automatically removed from the request's URL. So you can fetch only the part after yourdomain.com/ or yourdomain.com/subdir, if your .htaccess is inside of subdir folder.

Also, if you don't want to redirect user to target URL (2nd parameter of RewriteRule), you should remove R=301 from the RewriteRule.

Caching of URL rewrites


You should be aware of the fact that your browser might save some URL redirects and serve them any time you surf the website in future. This means that you should clear your browser cache before testing URL rewrites.

Your .htaccess doesn't get called?


A good trick to see if your .htaccess is actually getting fired at all, is to try to input a syntax error into it. That should crash the site if .htaccess is processed.

Saturday, October 29, 2016

Learn Angular 2 fast - a tutorial

Here is a crash course / tutorial in Angular 2 basic concepts. This document will be updated regularly.

Angular 2 is a modern, useful and popular JS framework. It's backed by Google and builds upon the good foundations laid by Angular 1, which is widely used by large software companies.



The basic concepts in Angular 2 are:

Component


Component represents a view. It's a TS class whose properties are going to be renedered as HTML, using the template provided by the component.


Service


Service deals with HTTP REST calls and anything else not directly tied to view.


Router


Router is a class capable of reading URL and its parts.


Directive


Directive is a class which extends HTML tags. For example, we can make an directive called HighlightTextbox, and use it like this in our HTML:

<input HighlightTextbox type='text' />

and this directive would add borders and make fonts larger. Angular 2 comes with tons of built in directives, so make sure you investigate them :)




All these four elements of Angular 2 applications, are simple TypeScript (TS) classes. TypeScript is chosen because it's easy to learn and it supports any standard ES5 JavaScript code.

This tutorial is going to be updated from time to time. Meanwhile, for a hands on tutorial, make sure you check this one on YouTube:

Here is a super cool tutorial, where you are going to build your first Angular 2 REST-based Web application in less than 60min:

Building your first Angular 2 app, cool step by step video

Friday, October 28, 2016

Solved: Eikon 510 usb fingerprint scanner not working under Windows 10

If your Eikon 510 USB fingerprint scanner doesn't seem to work under Windows 10 (or any other Windows probably), you should consider this solution:


1. Go to Control Panel ->Device Manager

2. Find "TouchChip Fingerprint Coprocessor (WBF advanced mode)" and open it's properties

3. Go to power management tab.

4. Disable "Allow the computer to turn off this device to save power


You should see the blue light coming from the Eikon 510 device immediately. It's a signal that device is up&running. The actual driver you should use is probably already included in your Windows update drivers.


If this doesn't help, you should try to find this driver:

                TouchChip Device Add-On for U.are.U SDK for Windows

It will add a new device:

TouchChip Fingerprint Coprocessor
 under Authentication Devices

JavaScript (JS) and block level variables and closures

Be careful when dealing with JavaScript (JS) block level variables. JS block level variables don't follow our intuition when they are paired with closures.

For example, imagine a for loop which instantiates a new local variable c in each iteration. Now, imagine that you increase the value of that variable c by 1 in each iteration. If you would like to print c to output console, 500ms after each increment, you would probably expect all iterations to have different values, right? However, what will happen is that all the print outs will contain the very same value.


In order to get a true block level variable in JS, we should enclose the iteration code in an anonymous function. This way, each anonymous function comes with its own scope, and closures (and setTimeout construct is a closure), will print correct (different) values.

Here is the example:






Friday, October 21, 2016

WP ACF fails to save/load data silently and intermittently

LOOK AT THIS:

Similar to the update_field() function, using a field’s key rather than it’s name allows ACF to correctly find the field if no existing value has been saved. To expand on this, if no repeater field value exists, this function will fail unless field key’s are used.

https://www.advancedcustomfields.com/resources/add_row/



It seems that we must ALWAYS use field_keys to avoid super strange and intermittent problems with ACF Pro.

Tuesday, October 18, 2016

AngularJS stopPropagation() in ng-click

To stop event propagation / bubbling in angular's ng-click directive, just add $event.stopPropagation(); to the existing ng-click handler.

Like this:



..  ng-click='kd_dd_toggle_group(kd_gui_offers_by_cta_group[group]);$event.stopPropagation();' ...

Saturday, October 1, 2016

VirtualBox won't start after Windows 10 anniversary update

If your VirtualBox GUI won't even open after Windows 10 anniversary update, you need to download the latest version of Virtual Box(currently 5.1.6) and install it.

PSR-1 and PSR-2 coding standards for PHP

Visual aspects of code play a significant role in raising or drowning developer's productivity. In case that there's too much clutte...