Tutorial by Examples: er

// Integral types as hex string.Format("Hexadecimal: byte2: {0:x2}; byte4: {0:X4}; char: {1:x2}", 123, (int)'A'); // Integers with thousand separators string.Format("Integer, thousand sep.: {0:#,#}; fixed length: >{0,10:#,#}<", 1234567); // Integer with leading zero...
Boxed value types can only be unboxed into their original Type, even if a conversion of the two Types is valid, e.g.: object boxedInt = (int)1; // int boxed in an object long unboxedInt1 = (long)boxedInt; // invalid cast This can be avoided by first unboxing into the original Type, e.g.: lon...
This example shows how to check permissions at runtime in Android 6 and later. public static final int MULTIPLE_PERMISSIONS = 10; // code you want. String[] permissions = new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA, Manifest.permission.ACC...
Examples below are given in Ruby, but same matchers should be available in any modern language. Let’s say we have the string "AℵNaïve", produced by Messy Artificial Intelligence. It consists of letters, but generic \w matcher won’t match much: ▶ "AℵNaïve"[/\w+/] #⇒ "A&q...
All C functions are in actuality pointers to a spot in the program memory where some code exists. The main use of a function pointer is to provide a "callback" to other functions (or to simulate classes and objects). The syntax of a function, as defined further down on this page is: retu...
public static void Main() { var xml = new XmlDocument(); var root = xml.CreateElement("element"); // Creates an attribute, so the element will now be "<element attribute='value' />" root.SetAttribute("attribute", "value"); ...
ALTER TABLE Employees ALTER COLUMN StartingDate DATETIME NOT NULL DEFAULT (GETDATE()) This query will alter the column datatype of StartingDate and change it from simple date to datetime and set default to current date.
Swift import SystemConfiguration /// Class helps to code reuse in handling internet network connections. class NetworkHelper { /** Verify if the device is connected to internet network. - returns: true if is connected to any internet network, false if is not co...
To generate true random values that can be used for cryptography std::random_device has to be used as generator. #include <iostream> #include <random> int main() { std::random_device crypto_random_generator; std::uniform_int_distribution<int> int_distribution(0,9); ...
A pseudo-random number generator generates values that can be guessed based on previously generated values. In other words: it is deterministic. Do not use a pseudo-random number generator in situations where a true random number is required. #include <iostream> #include <random> in...
The random number generator can (and should) be used for multiple distributions. #include <iostream> #include <random> int main() { std::default_random_engine pseudo_random_generator; std::uniform_int_distribution<int> int_distribution(0, 9); std::uniform_real_dis...
[a-b] where a and b are digits in the range 0 to 9 [3-7] will match a single digit in the range 3 to 7. Matching multiple digits \d\d will match 2 consecutive digits \d+ will match 1 or more consecutive digits \d* will match 0 or more consecutive digits \d{3} will ma...
By default, Interface Builder doesn't accept the CGColor datatype, so to allow adding a CGColor using user defined attributes in interface builder; one may want to use an extension like this: Swift Extension : extension CALayer { func borderUIColor() -> UIColor? { return borderCol...
NSSet *set = [NSSet set]; NSArray *array = [NSArray array]; NSArray *fromSet = [set allObjects]; NSSet *fromArray = [NSSet setWithArray:array];
References behaves similarly, but not entirely like const pointers. A reference is defined by suffixing an ampersand & to a type name. int i = 10; int &refi = i; Here, refi is a reference bound to i. References abstracts the semantics of pointers, acting like an alias to the underlying...
The strchr and strrchr functions find a character in a string, that is in a NUL-terminated character array. strchr return a pointer to the first occurrence and strrchr to the last one. #include <stdio.h> #include <stdlib.h> #include <string.h> int main(void) { char toSe...
In its most basic form, an object that implements IEnumerable represents a series of objects. The objects in question can be iterated using the c# foreach keyword. In the example below, the object sequenceOfNumbers implements IEnumerable. It represents a series of integers. The foreach loop iterate...
This example limits SELECT result to 15 percentage of total row count. SELECT TOP 15 PERCENT * FROM table_name
$orderid = 12345; $order = Mage::getModel('sales/order')->load($orderid); The above code is roughly analogous to the following SQL query. select * from sales_flat_order where entity_id=12345;
$incrementid = 100000000; $order = Mage::getModel('sales/order')->loadByIncrementId($incrementid); The above code is roughly analogous to the following SQL query. select * from sales_flat_order where increment_id=100000000; The increment_id is the customer facing order identifier, whereas...

Page 60 of 417