Tutorial by Examples: c

Normally your tests should be created in such a way that execution order is no concern. However there is always going to be an edge case were you need to break that rule. The one scenario I came across was with R.NET whereby in a given process you can only initialize one R Engine and once disposed ...
let sel = document.getSelection(); sel.removeAllRanges();
let sel = document.getSelection(); let myNode = document.getElementById('element-to-select'); let range = document.createRange(); range.selectNodeContents(myNode); sel.addRange(range); It may be necessary to first remove all the ranges of the previous selection, as most browsers don't s...
let sel = document.getSelection(); let text = sel.toString(); console.log(text); // logs what the user selected Alternatively, since the toString member function is called automatically by some functions when converting the object to a string, you don't always have to call it yourself. console...
To create a custom template we first need to create php file in a theme directory. You can name it almost any way you want. For this example we will create example.php One and only thing we need to define inside our example.php, to be recognized by WordPress as a template, is template name. We do t...
Let's extend our template from above and include content from header.php and footer.php Including header: We will include header right after Template name comment There are two common ways to do this. Both are right and work same, it's just about your style and how code looks First way: <?ph...
We will further extend our template and include title of the page and a content <?php /* Template Name: Example */ get_header(); the_title(); the_content(); get_footer(); And if you want you can wrap them with HTML elements like this <?php /* Template Name: Example *...
Values can be given names using let: # let a = 1;; val a : int = 1 You can use similar syntax to define a function. Just provide additional parameters for the arguments. # let add arg1 arg2 = arg1 + arg2;; val add : int -> int -> int = <fun> We can call it like this: # add 1...
The function keyword automatically has pattern matching when you define the body of your function. Observe it below: # let foo = function 0 -> "zero" | 1 -> "one" | 2 -> "couple" | 3 -> "few" | _ -> "many";; val foo : int -&gt...
Classes, structures, and enumerations can define subscripts, which are shortcuts for accessing the member elements of a collection, list, or sequence. Example struct DaysOfWeek { var days = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri"...
A defer statement in Go is simply a function call marked to be executed at a later time. Defer statement is an ordinary function call prefixed by the keyword defer. defer someFunction() A deferred function is executed once the function that contains the defer statement returns. Actual call to th...
Standard enumerations allow users to declare a useful name for a set of integers. The names are collectively referred to as enumerators. An enumeration and its associated enumerators are defined as follows: enum myEnum { enumName1, enumName2, }; An enumeration is a type, one which is...
A common use for enumerators is for switch statements and so they commonly appear in state machines. In fact a useful feature of switch statements with enumerations is that if no default statement is included for the switch, and not all values of the enum have been utilized, the compiler will issue ...
If targeting Flash Player 11+, the built-in removeChildren method is the best way to remove all children: removeChildren(); //a start and end index can be passed For legacy applications, the same can be accomplished with a loop: while (numChildren > 0) { removeChildAt(0); }
Enums in Swift are much more powerful than some of their counterparts in other languages, such as C. They share many features with classes and structs, such as defining initialisers, computed properties, instance methods, protocol conformances and extensions. protocol ChangesDirection { mutati...
package { import flash.events.TimerEvent; import flash.utils.Timer; public class CountdownTimer extends Timer { public var time:Number = 0; public function CountdownTimer(time:Number = Number.NEGATIVE_INFINITY, delay:Number = 1000) { super(delay, repeatCount); ...
Using functions that take in and execute closures can be extremely useful for sending a block of code to be executed elsewhere. We can start by allowing our function to take in an optional closure that will (in this case) return Void. func closedFunc(block: (()->Void)? = nil) { print("...
Note: Everything below applies to the str.format method, as well as the format function. In the text below, the two are interchangeable. For every value which is passed to the format function, Python looks for a __format__ method for that argument. Your own custom class can therefore have th...
// RawRepresentable has an associatedType RawValue. // For this struct, we will make the compiler infer the type // by implementing the rawValue variable with a type of String // // Compiler infers RawValue = String without needing typealias // struct NotificationName: RawRepresentable { ...
A protocol may specify that only a class can implement it through using the class keyword in its inheritance list. This keyword must appear before any other inherited protocols in this list. protocol ClassOnlyProtocol: class, SomeOtherProtocol { // Protocol requirements } If a non-class typ...

Page 219 of 826