Tutorial by Examples: and

When you use or, it will either return the first value in the expression if it's true, else it will blindly return the second value. I.e. or is equivalent to: def or_(a, b): if a: return a else: return b For and, it will return its first value if it's false, else it r...
Recursion occurs when a function call causes that same function to be called again before the original function call terminates. For example, consider the well-known mathematical expression x! (i.e. the factorial operation). The factorial operation is defined for all nonnegative integers as follows:...
Technically, autoloading works by executing a callback when a PHP class is required but not found. Such callbacks usually attempt to load these classes. Generally, autoloading can be understood as the attempt to load PHP files (especially PHP class files, where a PHP source file is dedicated for a ...
When running from the CLI, PHP exhibits some different behaviours than when run from a web server. These differences should be kept in mind, especially in the case where the same script might be run from both environments. No directory change When running a script from a web server, the current w...
There are a number of different ways to install the AWS CLI on your machine, depending on what operating system and environment you are using: On Microsoft Windows – use the MSI installer. On Linux, OS X, or Unix – use pip (a package manager for Python software) or install manually with the bundle...
The preferred way of describing dependencies is by using constructor injection which follows Explicit Dependencies Principle: ITestService.cs public interface ITestService { int GenerateRandom(); } TestService.cs public class TestService : ITestService { public int GenerateRando...
It's possible to create a new ASP.NET Core project entirely from the command line using the dotnet command. dotnet new web dotnet restore dotnet run dotnet new web scaffolds a new "empty" web project. The web parameter tells the dotnet tool to use the ASP.NET Core Empty template. Use...
With C++11 and higher calculations at compile time can be much easier. For example calculating the power of a given number at compile time will be following: template <typename T> constexpr T calculatePower(T value, unsigned power) { return power == 0 ? 1 : value * calculatePower(value,...
Haskell is a pure language, meaning that expressions cannot have side effects. A side effect is anything that the expression or function does other than produce a value, for example, modify a global counter or print to standard output. In Haskell, side-effectful computations (specifically, those wh...
Using Razor @functions keyword gives the capability of introducing classes and methods for inline use within a Razor file: @functions { string GetCssClass(Status status) { switch (status) { case Status.Success: return "alert-success&qu...
For Addition "4" + 2 # Gives "42" 4 + "2" # Gives 6 1,2,3 + "Hello" # Gives 1,2,3,"Hello" "Hello" + 1,2,3 # Gives "Hello1 2 3" For Multiplication "3" * 2 # Gives "33" 2 * "3&quot...
If a type wishes to have value semantics, and it needs to store objects that are dynamically allocated, then on copy operations, the type will need to allocate new copies of those objects. It must also do this for copy assignment. This kind of copying is called a "deep copy". It effective...
Open your command console and execute the following commands: $ sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony $ sudo chmod a+x /usr/local/bin/symfony
Let's say you have an object like this: var myObject = { name: 'Peter' } Later in your code, you try to access myObject.name and you get George instead of Peter. You start wondering who changed it and where exactly it was changed. There is a way to place a debugger (or something else) on e...
You can implement the swipe-to-dismiss and drag-and-drop features with the RecyclerView without using 3rd party libraries. Just use the ItemTouchHelper class included in the RecyclerView support library. Instantiate the ItemTouchHelper with the SimpleCallback callback and depending on which functi...
using System.Net; using System.IO; ... string requestUrl = "https://www.example.com/submit.html"; HttpWebRequest request = HttpWebRequest.CreateHttp(requestUrl); request.Method = "POST"; // Optionally, set properties of the HttpWebRequest, such as: request.AutomaticD...
using System.Net; using System.IO; ... string requestUrl = "https://www.example.com/page.html"; HttpWebRequest request = HttpWebRequest.CreateHttp(requestUrl); // Optionally, set properties of the HttpWebRequest, such as: request.AutomaticDecompression = DecompressionMethods.GZ...
using System.Net; ... string serverResponse; try { // Call a method that performs an HTTP request (per the above examples). serverResponse = PerformHttpRequest(); } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError) { HttpWebResponse...
This example generates random values between 0 and 2147483647. Random rnd = new Random(); int randomNumber = rnd.Next();
Generate a random number between 0 and 1.0. (not including 1.0) Random rnd = new Random(); var randomDouble = rnd.NextDouble();

Page 27 of 153