Tutorial by Examples: c

$fruit1 = ['apples', 'pears']; $fruit2 = ['bananas', 'oranges']; $all_of_fruits = array_merge($fruit1, $fruit2); // now value of $all_of_fruits is [0 => 'apples', 1 => 'pears', 2 => 'bananas', 3 => 'oranges'] Note that array_merge will change numeric indexes, but overwrite string...
A function defined as async is a function that can perform asynchronous actions but still look synchronous. The way it's done is using the await keyword to defer the function while it waits for a Promise to resolve or reject. Note: Async functions are a Stage 4 ("Finished") proposal on tr...
A context manager is an object that is notified when a context (a block of code) starts and ends. You commonly use one with the with statement. It takes care of the notifying. For example, file objects are context managers. When a context ends, the file object is closed automatically: open_file = ...
SELECT * FROM Employees ORDER BY LName This statement will return all the columns from the table Employees. IdFNameLNamePhoneNumber2JohnJohnson24681012141JamesSmith12345678903MichaelWilliams1357911131 SELECT * FROM Employees ORDER BY LName DESC Or SELECT * FROM Employees ORDER BY LName ASC...
math modules includes two commonly used mathematical constants. math.pi - The mathematical constant pi math.e - The mathematical constant e (base of natural logarithm) >>> from math import pi, e >>> pi 3.141592653589793 >>> e 2.718281828459045 >>> P...
If a name is bound inside a function, it is by default accessible only within the function: def foo(): a = 5 print(a) # ok print(a) # NameError: name 'a' is not defined Control flow constructs have no impact on the scope (with the exception of except), but accessing variable that w...
x and y are extracted from the tuple: val (x, y) = (1337, 42) // x: Int = 1337 // y: Int = 42 To ignore a value use _: val (_, y: Int) = (1337, 42) // y: Int = 42 To unpack an extractor: val myTuple = (1337, 42) myTuple._1 // res0: Int = 1337 myTuple._2 // res1: Int = 42 Note that...
A case class is a class with a lot of standard boilerplate code automatically included. One benefit of this is that Scala makes it easy to use extractors with case classes. case class Person(name: String, age: Int) // Define the case class val p = Person("Paola", 42) // Instantiate a v...
The null coalescing operator makes it easy to ensure that a method that may return null will fall back to a default value. Without the null coalescing operator: string name = GetName(); if (name == null) name = "Unknown!"; With the null coalescing operator: string name = GetN...
Running the latest Liferay CE is straightforward: Go to https://www.liferay.com/downloads. Choose a bundle among the ones listed. For beginners, the Tomcat bundle is a good choice. Click in "Download." Unzip the download package whenever you find fit. The unzipped directory will...
You can use a column's number (where the leftmost column is '1') to indicate which column to base the sort on, instead of describing the column by its name. Pro: If you think it's likely you might change column names later, doing so won't break this code. Con: This will generally reduce readabilit...
Requirements: Protractor requires the following dependencies to be installed prior to installation: Java JDK 1.7 or higher Node.js v4 or higher Installation: Download and install Node.js from this URL: https://nodejs.org/en/ To see if the Node.js installation is successfull, you can go an...
HTML <div class="scale"></div> CSS .scale { width: 100px; height: 100px; background: teal; transform: scale(0.5, 1.3); } This example will scale the div to 100px * 0.5 = 50px on the X axis and to 100px * 1.3 = 130px on the Y axis. The center of the...
A context manager is any object that implements two magic methods __enter__() and __exit__() (although it can implement other methods as well): class AContextManager(): def __enter__(self): print("Entered") # optionally return an object return "A-ins...
The following are data types intrinsic to Fortran: integer real character complex logical integer, real and complex are numeric types. character is a type used to store character strings. logical is used to store binary values .true. or .false.. All numeric and logical intrinsic types are...
To raise an exception use Kernel#raise passing the exception class and/or message: raise StandardError # raises a StandardError.new raise StandardError, "An error" # raises a StandardError.new("An error") You can also simply pass an error message. In this case, the message i...
A custom exception is any class that extends Exception or a subclass of Exception. In general, you should always extend StandardError or a descendant. The Exception family are usually for virtual-machine or system errors, rescuing them can prevent a forced interruption from working as expected. # ...
Use the begin/rescue block to catch (rescue) an exception and handle it: begin # an execution that may fail rescue # something to execute in case of failure end A rescue clause is analogous to a catch block in a curly brace language like C# or Java. A bare rescue like this rescues Stand...
You can handle multiple errors in the same rescue declaration: begin # an execution that may fail rescue FirstError, SecondError => e # do something if a FirstError or SecondError occurs end You can also add multiple rescue declarations: begin # an execution that may fail rescue ...
Substitutability is a principle in object-oriented programming introduced by Barbara Liskov in a 1987 conference keynote stating that, if class B is a subclass of class A, then wherever A is expected, B can be used instead: class A {...} class B extends A {...} public void method(A obj) {...} ...

Page 72 of 826