Tutorial by Examples

Local variables are defined within a function, method, or closure: func printSomething() { let localString = "I'm local!" print(localString) } func printSomethingAgain() { print(localString) // error } Global variables are defined outside of a function, method, or c...
Type properties are properties on the type itself, not on the instance. They can be both stored or computed properties. You declare a type property with static: struct Dog { static var noise = "Bark!" } print(Dog.noise) // Prints "Bark!" In a class, you can use the c...
The following is handy to have in build logs that identifies the build machine, and some parameters; simply make you main task depend on this task to print it before every build. <!-- Print Environment Info --> <target name="environment"> <!-- Get the current ti...
Mathematical operations on values other than numbers return NaN. "a" + 1 "b" * 3 "cde" - "e" [1, 2, 3] * 2 An exception: Single-number arrays. [2] * [3] // Returns 6 Also, remember that the + operator concatenates strings. "a" + "b&...
Generally, Math functions that are given non-numeric arguments will return NaN. Math.floor("a") The square root of a negative number returns NaN, because Math.sqrt does not support imaginary or complex numbers. Math.sqrt(-1)
window.isNaN() The global function isNaN() can be used to check if a certain value or expression evaluates to NaN. This function (in short) first checks if the value is a number, if not tries to convert it (*), and then checks if the resulting value is NaN. For this reason, this testing method may ...
- (void)methodWithBlock:(returnType (^)(paramType1, paramType2, ...))name;
Following ways can be used for joining lists without modifying source list(s). First approach. Has more lines but easy to understand List<String> newList = new ArrayList<String>(); newList.addAll(listOne); newList.addAll(listTwo); Second approach. Has one less line but less readab...
In order to compare the equality of custom classes, you can override == and != by defining __eq__ and __ne__ methods. You can also override __lt__ (<), __le__ (<=), __gt__ (>), and __ge__ (>). Note that you only need to override two comparison methods, and Python can handle the rest (== ...
Output buffering allows you to store any textual content (Text, HTML) in a variable and send to the browser as one piece at the end of your script. By default, php sends your content as it interprets it. <?php // Turn on output buffering ob_start(); // Print some output to the buffer (via...
You can nest output buffers and fetch the level for them to provide different content using the ob_get_level() function. <?php $i = 1; $output = null; while( $i <= 5 ) { // Each loop, creates a new output buffering `level` ob_start(); print "Current nest level: &quo...
In this example, we have an array containing some data. We capture the output buffer in $items_li_html and use it twice in the page. <?php // Start capturing the output ob_start(); $items = ['Home', 'Blog', 'FAQ', 'Contact']; foreach($items as $item): // Note we're about to step &q...
ob_start(); $user_count = 0; foreach( $users as $user ) { if( $user['access'] != 7 ) { continue; } ?> <li class="users user-<?php echo $user['id']; ?>"> <a href="<?php echo $user['link']; ?>"> <?php echo $user...
<?php ob_start(); ?> <html> <head> <title>Example invoice</title> </head> <body> <h1>Invoice #0000</h1> <h2>Cost: £15,000</h2> ... </body> </html> <?php...
import multiprocessing def fib(n): """computing the Fibonacci in an inefficient way was chosen to slow down the CPU.""" if n <= 2: return 1 else: return fib(n-1)+fib(n-2) p = multiprocessing.Pool() print(p.map(fib,[38,37,3...
If you have already added a file to your Git repository and now want to stop tracking it (so that it won't be present in future commits), you can remove it from the index: git rm --cached <file> This will remove the file from the repository and prevent further changes from being tracked by...
Using the threading module, a new thread of execution may be started by creating a new threading.Thread and assigning it a function to execute: import threading def foo(): print "Hello threading!" my_thread = threading.Thread(target=foo) The target parameter references the fun...
The form for a link in markdown is as follows. [Shown Text](Link) For example, This will take you to Example.com is created with [This will take you to Example.com](http://www.example.com)
By adding > in front of a line, you can create quoted text! > I am a quote I am a quote!
A block that performs addition of two double precision numbers, assigned to variable addition: double (^addition)(double, double) = ^double(double first, double second){ return first + second; }; The block can be subsequently called like so: double result = addition(1.0, 2.0); // result =...

Page 65 of 1336