Tutorial by Examples: c

We can use Predefined Constants for Date format in date() instead of the conventional date format strings since PHP 5.1.0. Predefined Date Format Constants Available DATE_ATOM - Atom (2016-07-22T14:50:01+00:00) DATE_COOKIE - HTTP Cookies (Friday, 22-Jul-16 14:50:01 UTC) DATE_RSS - RSS (Fri, 22...
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 ...
An anonymous function is just a function that doesn't have a name. // Anonymous function function() { return "Hello World!"; }; In PHP, an anonymous function is treated like an expression and for this reason, it should be ended with a semicolon ;. An anonymous function should b...
In PHP, an anonymous function has its own scope like any other PHP function. In JavaScript, an anonymous function can access a variable in outside scope. But in PHP, this is not permitted. $name = 'John'; // Anonymous function trying access outside scope $sayHello = function() { return &q...
A closure is an anonymous function that can't access outside scope. When defining an anonymous function as such, you're creating a "namespace" for that function. It currently only has access to that namespace. $externalVariable = "Hello"; $secondExternalVariable = "Foo&qu...
A std::vector can be useful for returning a dynamic number of variables of the same type. The following example uses int as data type, but a std::vector can hold any type that is trivially copyable: #include <vector> #include <iostream> // the following function returns all integers...
Program units often make use of literal constants. These cover the obvious cases like print *, "Hello", 1, 1.0 Except in one case, each literal constant is a scalar which has type, type parameters and value given by the syntax. Integer literal constants are of the form 1 -1 -1_1 ...
You can call a function in Racket by wrapping it in parentheses with the arguments after it. This looks like (function argument ...). > (define (f x) x) > (f 1) 1 > (f "salmon") "salmon" > (define (g x y) (string-append x y)) > (g "large" "sal...
A common pattern in C# is using bool TryParse(object input, out object value) to safely parse objects. The out var declaration is a simple feature to improve readability. It allows a variable to be declared at the same time that is it passed as an out parameter. A variable declared this way is sco...
Local functions are defined within a method and aren't available outside of it. They have access to all local variables and support iterators, async/await and lambda syntax. This way, repetitions specific to a function can be functionalized without crowding the class. As a side effect, this improves...
Define AccumulatorParam import org.apache.spark.AccumulatorParam object StringAccumulator extends AccumulatorParam[String] { def zero(s: String): String = s def addInPlace(s1: String, s2: String)= s1 + s2 } Use: val accumulator = sc.accumulator("")(StringAccumulator) sc.pa...
Define AccumulatorParam: from pyspark import AccumulatorParam class StringAccumulator(AccumulatorParam): def zero(self, s): return s def addInPlace(self, s1, s2): return s1 + s2 accumulator = sc.accumulator("", StringAccumulator()) def add(x): gl...
Preconditions allows methods to provide minimum required values for input parameters Example... void DoWork(string input) { Contract.Requires(!string.IsNullOrEmpty(input)); //do work } Static Analysis Result...
Postconditions ensure that the returned results from a method will match the provided definition. This provides the caller with a definition of the expected result. Postconditions may allowed for simplied implmentations as some possible outcomes can be provided by the static analyizer. Example......
AlertDialog.Builder builder = new AlertDialog.Builder(context); //Set Title builder.setTitle("Reset...") //Set Message .setMessage("Are you sure?") //Set the icon of the dialog .setIcon(drawable) //Set...
Let there be Activity B that can be opened, and can further start more Activities. But, user should not encounter it when navigating back in task activities. The simplest solution is to set the attribute noHistory to true for that <activity> tag in AndroidManifest.xml: <activity a...
Imagine you have the following HTML: <div> <label>Name:</label> John Smith </div> And you need to locate the text "John Smith" after the label element. In this case, you can locate the label element by text and then use .next_sibling property: from ...
BeautifulSoup has a limited support for CSS selectors, but covers most commonly used ones. Use select() method to find multiple elements and select_one() to find a single element. Basic example: from bs4 import BeautifulSoup data = """ <ul> <li class="item&quo...
This example was done in order to demonstrate how you can perform a deep filter in a child array without the necessity of a custom filter. Controller: (function() { "use strict"; angular .module('app', []) .controller('mainCtrl', mainCtrl); function mainCtrl() { ...
demoApp.directive('demoDirective', function () { var directiveDefinitionObject = { multiElement: priority: terminal: scope: {}, bindToController: {}, controller: controllerAs: require: restrict: templateNamespace: template: templateU...

Page 147 of 826