Friday 14 October 2016

Windows 10 Keyboard Shortcuts

More Keyboard shortcuts than you can shake a stick at.

Turning multiple mouse clicks into a simple press of a key or two may not seem like a lot, but if you are an avid user of keyboard shortcuts you've likely noticed just how helpful they can be. Although memorizing which shortcuts do which functions can be a little daunting at first, it's important to remember not everyone needs to know every shortcut. Learning and using the ones that are most important to you is a great way to enhance your Windows 10 experience.

Keyboard shortcut Action
Windows key Open or close Start Menu.
Windows key + A Open Action center.
Windows key + C Open Cortana in listening mode.
Windows key + D Display and hide the desktop.
Windows key + E Open File Explorer.
Windows key + G Open Game bar when a game is open.
Windows key + H Open the Share charm.
Windows key + I Open Settings.
Windows key + K Open the Connect quick action.
Windows key + L Lock your PC or switch accounts.
Windows key + M Minimize all windows.
Windows key + R Open Run dialog box.
Windows key + S Open Search.
Windows key + U Open Ease of Access Center.
Windows key + X Open Quick Link menu.
Windows key + Number Open the app pinned to the taskbar in the position indicated by the number.
Windows key + Left arrow key Snap app windows left.
Windows key + Right arrow key Snap app windows right.
Windows key + Up arrow key Maximize app windows.
Windows key + Down arrow key Minimize app windows.
Windows key + Ctrl +D Add a virtual desktop.
Windows key + Ctrl + Left or Right arrow Switch between virtual desktops.
Windows key + Ctrl + F4 Close current virtual desktop.
Windows key + Comma Temporarily peek at the desktop.
Windows key + Enter Open Narrator.
Windows key + Home Minimize all but the active desktop window (restores all windows on second stroke).
Windows key + PrtScn Capture a screenshot and save in Screenshots folder.
Windows key + Shift + Up arrow Stretch the desktop window to the top and bottom of the screen.
Windows key + Tab Open Task view.
Windows key + "+" key Zoom in using the magnifier.
Windows key + "-" key Zoom out using the magnifier.
Ctrl + Shift + Esc Open Task Manager.
Alt + Tab Switch between open apps.
Alt + Left arrow key Go back.
Alt + Right arrow key Go foward.
Alt + Page Up Move up one screen.
Alt + Page down Move down one screen.
Ctrl + Alt +Tab View open apps
Ctrl + A Select all content.
Ctrl + C Copy selected items to clipboard.
Ctrl + D Delete the selected item and move it to the Recycle Bin.
Ctrl + V Paste content from clipboard.
Ctrl + X Cut selected items.
Ctrl + Y Redo an action.
Ctrl + Z Undo an action.
Ctrl + Esc Open the Start Menu.
Ctrl + Shift Switch the keyboard layout.
Ctrl + Shift + Esc Open Task Manager.
Ctrl + F4 Close the active window.

Did we miss anything?

Do you know more keyboard shortcuts? Let us know what we missed in the comments below!

Wednesday 13 April 2016

The Most Popular Web Browser Being Used In 2016


There are many websites that track the number of people using a particular web browser, operating system, and other services. However, not many of them provide a reliable data.

On the other hand, US government Digital Analytics Program (DAP) tracks the number of people on government websites in real time and gives us a standard running count of the last 90 days.

If we take a look at the most popular web browsers being used by people, Google’s Chrome browser wins the fight by a large margin. This was a choice of more than 2 billion visitors.
The second most popular web browser has surprised many as Apple’s Safari stole the second prize with 21.9 percent visits.

As expected, the third place was secured by Microsoft’s infamous Internet Explorer whose IE 6 to IE 11 versions gathered 20.1 percent visitors.

IE was followed by Mozilla’s Firefox web browser, which continues to stumble with just 8.2 percent visitors.
Talking about the new and shiny Microsoft Edge, it’s still not getting many users and it’s stuck with just 2.5 percent users. Android’s native mobile web browser comes last with 1.6 percent visitors.

Coming back to Safari, 19.1 percent visitors were using iPhones - I hope it automatically explains the large numbers for Safari.

The federal government explains that this data comes from a unified Google Analytic account for all US government websites. The government doesn’t forget to remind the people that its DAP program doesn’t track visitors and anonymises their IP addresses.
Digital Analytics Program

Which web browser do you use for completing your internet chores? Share your views in the comments below.

Wednesday 30 March 2016

Exciting Features In PHP 7

PHP 7 was a great step forward in the evolution of PHP. Many things were added, changed and removed. In the first part of this article it was covered the things that were changed or removed and may break your PHP code that ran with the past versions. Read this article part to learn more in detail about the new features and improvements of PHP 7 that you can take advantage.


1. Scalar Type Hinting Declarations 

There are now two forms of scalar type hinting declarations. The first one is default and second one is strict. String, integer, floating point number and boolean values can now be be checked enforced when calling a function or returning a value. Consider the following example:

<?php
 // Default mode
 function sumOfInts( int ...$ints )
 {
  return array_sum($ints);
 }
 var_dump(sumOfInts(2, '3', 4.1));
?>

Output:
int(9)
The strict mode can be enabled by placing a declare directive at the top like this:
declare(strict_types=1);
Strictness of typing for scalars will be configured on per file basis. However, keep in mind that if a script is included from a parent script that does not enable strict typing, it will not be enabled for the included child script.
 

2. Return Type Hinting Declarations


PHP 7 also supports the return type hinting declarations. This kind of declarations basically specify the type of value to be returned from a function. Hence, it is very similar to the argument type hinting declarations. Consider the following code:
<?php
 function arraysSum( array ...$arrays ): array
 {
  return array_map( function( array $array): int {
   return array_sum( $array );
  }, $arrays);
 }
 print_r( arraysSum( [1,2,3], [4,5,6], [7,8,9] ));
?>
Output:
Array
([0] => 6[1] => 15[2] => 24)
 

3. Null Coalescing Operator


A new operator called null coalescing operator (??) has been added in PHP 7. It allows the developers to implicitly use a ternary expression with isset() to determine if a value is set.
In case the value is not set, it evaluates to the value second operand. If the first operand value is set, it evaluates to that value.
Consider the following example to better understand the use of null coalescing operator:
<?php
 // Fetches the value of $_GET['user'] and returns 'nobody'
 // if it does not exist.
 $username = $_GET['user'] ?? 'nobody';
 // This is equivalent to:
 $username = isset( $_GET['user']) ? $_GET['user'] : 'nobody';
 // Coalescing can be chained: this will return the first
 // defined value out of $_GET['user'], $_POST['user'], and
 // 'nobody'.
 $username = $_GET['user'] ?? $_POST['user'] ?? 'nobody';
?>
 

4. Spaceship Operator in Comparisons


The spaceship operator was introduced in PHP 7 to help with comparing two expressions. It may evaluate 0,1, or -1. This is useful for array sorting functions that take callback functions that must return one of these 3 values depending on how two array entry values compare.
Comparisons are made according to type comparison rules. Consider the following example.
<?php
 // Integers
 echo 1 <=> 1; // 0
 echo 1 <=> 2; // -1
 echo 2 <=> 1; // 1
 // Floats
 echo 1.5 <=> 1.5; // 0
 echo 1.5 <=> 2.5; // -1
 echo 2.5 <=> 1.5; // 1
 // Strings
 echo "a" <=> "a"; // 0
 echo "a" <=> "b"; // -1
 echo "b" <=> "a"; // 1
?>
 

5. Define() for Constant Arrays


From now on, in PHP, array constants can be defined with define() function. In previous versions, we could not define array constants not even in classes with the const keyword.
Consider the following example:
<?php
 define('ANIMALS', [
  'dog',
  'cat',
  'bird'
 ]);
 echo ANIMALS[1]; // outputs "cat"
?>
 

6. Anonymous Classes Support


In PHP 7, support for anonymous classes has also been added through new class construct. Anonymous classes can be used to create objects on demand without declaring class separately. Consider the following example.

<?php
 interface Logger {
 public function log( string $msg );
}

class Application {
 private $logger;

 public function getLogger(): Logger {
  return $this->logger;
 }

 public function setLogger( Logger $logger ) {
  $this->logger = $logger;
 }

}

 $app = new Application;
 $app->setLogger( new class implements Logger {
  public function log( string $msg ) {
   echo $msg;
  }
 });
 var_dump( $app->getLogger() );
?>

Output:
object(class@anonymous)#2 (0) {}
 

7. Unicode CodePoint Escape Syntax


Now you can represent Unicode characters using the Codepoint hexadecimal format. The characters are translated to strings with UTF-8 encoding. Consider the following example:

echo "\u{aa}";
echo "\u{0000aa}";
echo "\u{9999}";
Output:
ª
ª (same as before but with optional leading 0's)

 

8. Closure::Call() Function For Binding to Objects


The Call function is a PHP 7 method for temporarily binding an object scope to the closure function and then calling it as part of the object. Consider the following example:
<?php
 class A {private $x = 1;}

 // before PHP 7
 $getXCB = function() { return $this->x; };
 $getX = $getXCB->bindTo( new A, 'A'); // intermediate closure
 echo $getX();

 // Starting with PHP 7
 $getX = function() { return $this->x; };
 echo $getX->call(new A);
?>
Its output will be:
1
1
 

9. Filtered Unserialize() for Preventing Injection of Unauthorized Class Objects


When calling unserialize you can define which classes of objects are expected to be recreated. It is useful to prevent injection of code of objects by specifying a white list of classes which can be unserialized. Consider the following example:

<?php
 // converts all objects into __PHP_Incomplete_Class object 
 $data = unserialize( $foo, ["allowed_classes" => false]);
 // converts all objects into __PHP_Incomplete_Class object except those of MyClass and MyClass2 
 $data = unserialize( $foo, [ "allowed_classes" => ["MyClass", "MyClass2"]]);
 // default behaviour (same as omitting the second argument) that accepts all classes 
 $data = unserialize( $foo, [ "allowed_classes" => true] );
?>
 

10. IntlChar Class Helps Manipulating Unicode Text


Intl Class defines constants and static methods for manipulating Unicode characters. This class requires the intl extension to be enabled on your PHP 7 installation. Example:

<?php
 printf('%x', IntlChar::CODEPOINT_MAX); echo IntlChar::charName( '@' ); var_dump( IntlChar::ispunct( '!' ) );
?>

Output:
10ffff
COMMERCIAL AT
bool(true)
 

11. Expectations Can Throw Exceptions

Traditionally developers used the assert() function to verify important conditions at run time. In PHP 7 you can pass a custom exception object that will be called if the assert condition value is false.
Also in PHP 7 assertions are a built-in construct of the language. This means that if assertions are disabled in the PHP configuration, it is as if the assertion code was not inserted in your PHP code, so they are not evaluated nor executed.
Consider the following example to better understand the concept:

<?php
 ini_set( 'assert.exception', 1);
 class CustomError extends AssertionError {}
 assert(false, new CustomError( 'Some error message' ));
?>
Output:
Fatal error: Uncaught CustomError: Some error message
 

12. Group Namespace Use Declarations


In PHP7 it is now possible to import multiple constants, functions and classes from same namespace with a single use statement, thus making the code more succinct.
Consider the following example to better understand the concept:

<?php
 use some\namespace\ClassA;
 use some\namespace\ClassB;
 use some\namespace\ClassC as C;
 use function some\namespace\fn_a;
 use function some\namespace\fn_b;
 use function some\namespace\fn_c;
 use const some\namespace\ConstA;
 use const some\namespace\ConstB;
 use const some\namespace\ConstC;

 // PHP 7+ code
 use some\namespace\{ClassA, ClassB, ClassC as C};
 use function some\namespace\{fn_a, fn_b, fn_c};
 use const some\namespace\{ConstA, ConstB, ConstC};
?>
 

13. Generator Return Values Can also be Used Like Yield


Generators are functions that you can use since PHP 5.5 to return multiple values using the yield command, for instance to be iterated like with array values. Then the generator function is resumed right after the value is used by the calling code right after the yield statement.
Since PHP 7 the return command can also be used to return a value like if it was returned by yield, except that it is the last value returned by the generator function.
If you need to get the actual return value you can used the getReturn() method on the generator function closure object.
The following example demonstrates the concept:

<?php
 $gen = (function() {
  yield 1;
  yield 2;
  return 3;
 })();
 foreach ($gen as $val) {
  echo $val, PHP_EOL;
 }
 echo $gen->getReturn(), PHP_EOL;
?>

Output:
1
2
3
 

14. Generators Can Delegate on Other Generators


In PHP 7 generators can now delegate to another generator to yield a set of values. Here is an example:

<?php
 function gen()
 {
  yield 1;
  yield 2;
  yield from gen2();
 }

 function gen2()
 {
  yield 3;
  yield 4;
 }

 foreach (gen() as $val)
 {
  echo $val, PHP_EOL;
 }
?>

Output:
1
2
3
4
 

15. Faster Integer Division with Intdiv()


In PHP 7 Intdiv() can perform integer division faster than the regular / division operator. With the division operator it could return a float and you would need to convert the result to an integer if you just wanted to get the integer part ignoring the remainder.
Consider the following example.

<?php
 var_dump(intdiv(10, 3));
?>

Output:
int(3)
 

16. Advanced Session Options Can be Set at session_start()


In PHP 7 session_start() can take an array of options which will override the configuration directives which are set in php.ini .
The lazy_write option, which is enabled by default, also makes PHP only rewrite session data if it has changed and the read_and_close is passed to session_start().
Consider the following example:
<?php
 session_start([
  'cache_limiter' => 'private',
  'read_and_close' => true,
 ]);
?>
 

17. preg_replace_callback_array() Allows to Replace Multiple Expressions


The new function preg_replace_callback_array() allows the developers to specify multiple regular expressions and callback functions to replace the expressions all in a single function call
This is a much cleaner approach then using multiple preg_replace_callback calls.
 

18. Cryptographically Secure Pseudo Random Number Generators


PHP 7 introduces random_bytes() and random_int() for generating secure random strings and integers. These functions are recommended to be used for cryptography purposes instead of others like rand().
If for some reason you cannot use PHP 7 yet, you can find here an alternative user-land implementation that works with PHP 5.x series contributed by Scott Arciszewski with many other security experts of the PHP community.
 

19. Correctly Extract Values using List()


Before PHP 7 list() command was not working correctly with objects that implement ArrayAccess interface. That issue is fixed in PHP 7.