Tutorial by Examples: c

The where statement may be used within a switch case match to add additional criteria required for a positive match. The following example checks not only for the range, but also if the number is odd or even: switch (temperature) { case 0...49 where temperature % 2 == 0: print(&quot...
@interface MyObject : MySuperclass @property (copy) void (^blockProperty)(NSString *string); @end When assigning, since self retains blockProperty, block should not contain a strong reference to self. Those mutual strong references are called a "retain cycle" and will prevent the...
Key Value Coding is integrated into NSObject using NSKeyValueCoding protocol. What this means? It means that any id object is capable of calling valueForKey method and its various variants like valueForKeyPath etc. ' It also means that any id object can invoke setValue method and its various vari...
The clone() method is used to create and return a copy of an object. This method arguable should be avoided as it is problematic and a copy constructor or some other approach for copying should be used in favour of clone(). For the method to be used all classes calling the method must implement the...
A std::vector automatically increases its capacity upon insertion as needed, but it never reduces its capacity after element removal. // Initialize a vector with 100 elements std::vector<int> v(100); // The vector's capacity is always at least as large as its size auto const old_capacity...
At its simplest, a property is a function which returns a Bool. prop_reverseDoesNotChangeLength xs = length (reverse xs) == length xs A property declares a high-level invariant of a program. The QuickCheck test runner will evaluate the function with 100 random inputs and check that the result is...
Classes can be created dynamically through the use of Class.new. # create a new class dynamically MyClass = Class.new # instantiate an object of type MyClass my_class = MyClass.new In the above example, a new class is created and assigned to the constant MyClass. This class can be instanti...
You can use an instance of an object to form your parameters public class SearchParameters { public string SearchString { get; set; } public int Page { get; set; } } var template= new SearchParameters { SearchString = "Dapper", Page = 1 }; var p = new DynamicParameters...
R is able to access the current date, time and time zone: Sys.Date() # Returns date as a Date object ## [1] "2016-07-21" Sys.time() # Returns date & time at current locale as a POSIXct object ## [1] "2016-07-21 10:04:39 CDT" as.numeric(Sys...
# test date-time object options(digits.secs = 3) d = as.POSIXct("2016-08-30 14:18:30.58", tz = "UTC") format(d,"%S") # 00-61 Second as integer ## [1] "30" format(d,"%OS") # 00-60.99… Second as fractional ## [1] "30.579" for...
The functions for parsing a string into POSIXct and POSIXlt take similar parameters and return a similar-looking result, but there are differences in how that date-time is stored; see "Remarks." as.POSIXct("11:38", # time string format = "...
The quickCheck function tests a property on 100 random inputs. ghci> quickCheck prop_reverseDoesNotChangeLength +++ OK, passed 100 tests. If a property fails for some input, quickCheck prints out a counterexample. prop_reverseIsAlwaysEmpty xs = reverse xs == [] -- plainly not true for all ...
Ruby has many types of enumerators but the first and most simple type of enumerator to start with is each. We will print out even or odd for each number between 1 and 10 to show how each works. Basically there are two ways to pass so called blocks. A block is a piece of code being passed which will...
To do an insert on specific columns (as opposed to all of them) you must specify the columns you want to update. INSERT INTO USERS (FIRST_NAME, LAST_NAME) VALUES ('Stephen', 'Jiang'); This will only work if the columns that you did not list are nullable, identity, timestamp data type or compute...
If you wish to copy the contents of a slice into an initially empty slice, following steps can be taken to accomplish it- Create the source slice: var sourceSlice []interface{} = []interface{}{"Hello",5.10,"World",true} Create the destination slice, with: Length =...
The canvas element was introduced in HTML5 for drawing graphics. <canvas id="myCanvas"> Cannot display graphic. Canvas is not supported by your browser (IE<9) </canvas> The above will create a transparent HTML<canvas> element of 300×150 px in size. You can us...
Pipes may be chained. <p>Today is {{ today | date:'fullDate' | uppercase}}.</p>
my.pipe.ts import { Pipe, PipeTransform } from '@angular/core'; @Pipe({name: 'myPipe'}) export class MyPipe implements PipeTransform { transform(value:any, args?: any):string { let transformedValue = value; // implement your transformation logic here return transformedValue; }...
Fixed precision and scale decimal numbers. DECIMAL and NUMERIC are functionally equivalent. Syntax: DECIMAL ( precision [ , scale] ) NUMERIC ( precision [ , scale] ) Examples: SELECT CAST(123 AS DECIMAL(5,2)) --returns 123.00 SELECT CAST(12345.12 AS NUMERIC(10,5)) --returns 12345.12000
String data types of either fixed length or variable length. Syntax: CHAR [ ( n_chars ) ] VARCHAR [ ( n_chars ) ] Examples: SELECT CAST('ABC' AS CHAR(10)) -- 'ABC ' (padded with spaces on the right) SELECT CAST('ABC' AS VARCHAR(10)) -- 'ABC' (no padding due to variable character) SELE...

Page 86 of 826