Tutorial by Examples: and

To spawn a new process in which you need unbuffered output (e.g. long-running processes which might print output over a period of time rather than printing and exiting immediately), use child_process.spawn(). This method spawns a new process using a given command and an array of arguments. The retu...
You have to keep the operator precedence in mind when using await keyword. Imagine that we have an asynchronous function which calls another asynchronous function, getUnicorn() which returns a Promise that resolves to an instance of class Unicorn. Now we want to get the size of the unicorn using th...
The Protractor API allows CSS element locators to use the jQuery-like shortcut notation $(). Normal CSS Element Locator: element(by.css('h1.documentation-text[ng-bind="title"]')); element(by.css('[ng-click="submit"])); Shortcut $() CSS Element Locator: $('h1.documentatio...
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...
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...
NSSet *set = [NSSet set]; NSArray *array = [NSArray array]; NSArray *fromSet = [set allObjects]; NSSet *fromArray = [NSSet setWithArray:array];
Tuples can be compared based on their elements. As an example, an enumerable whose elements are of type Tuple can be sorted based on comparisons operators defined on a specified element: List<Tuple<int, string>> list = new List<Tuple<int, string>>(); list.Add(new Tuple<...
To use the IronPython command line, open ipy.exe or ipy64.exe. Both files are located in the path that was selected during installation. By default they will be located at C:\Program Files\IronPython 2.7\. Then start writing your statements directly in the IronPython command line. For example: pr...
Carousel components can be instantiated via jQuery with the function $('.carousel').carousel(options), where $('.carousel') is a top-level reference to the specific carousel and options is a Javascript object specifying the carousel's default attributes. The options object allows for multiple prope...
The arc4random_uniform() function is the simplest way to get high-quality random integers. As per the manual: arc4random_uniform(upper_bound) will return a uniformly distributed random number less than upper_bound. arc4random_uniform() is recommended over constructions like ''arc4random() % uppe...
The following code demonstrates usage of arc4random_uniform() to generate a random integer between 3 and 12: uint32_t randomIntegerWithinRange = arc4random_uniform(10) + 3; // A random integer between 3 and 12 This works to create a range because arc4random_uniform(10) returns an integer between...
hash( (1, 2) ) # ok hash( ([], {"hello"}) # not ok, since lists and sets are not hashabe Thus a tuple can be put inside a set or as a key in a dict only if each of its elements can. { (1, 2) } # ok { ([], {"hello"}) ) # not ok
C# allows user-defined types to control assignment and casting through the use of the explicit and implicit keywords. The signature of the method takes the form: public static <implicit/explicit> operator <ResultingType>(<SourceType> myType) The method cannot take any more argu...
To generate random permutation of 5 numbers: sample(5) # [1] 4 5 3 1 2 To generate random permutation of any vector: sample(10:15) # [1] 11 15 12 10 14 13 One could also use the package pracma randperm(a, k) # Generates one random permutation of k of the elements a, if a is a vector, # ...
The Switch statement works very well with Enum values enum CarModel { case Standard, Fast, VeryFast } let car = CarModel.Standard switch car { case .Standard: print("Standard") case .Fast: print("Fast") case .VeryFast: print("VeryFast") } Since we ...
WITH CTE (StudentId, Fname, LName, DOB, RowCnt) as ( SELECT StudentId, FirstName, LastName, DateOfBirth as DOB, SUM(1) OVER (Partition By FirstName, LastName, DateOfBirth) as RowCnt FROM tblStudent ) SELECT * from CTE where RowCnt > 1 ORDER BY DOB, LName This example uses a Common Table ...
Once the instance of the BackgroundWorker has been declared, it must be given properties and event handlers for the tasks it performs. /* This is the backgroundworker's "DoWork" event handler. This method is what will contain all the work you wish to have your progra...
As Handlers are used to send Messages and Runnables to a Thread's message queue it's easy to implement event based communication between multiple Threads. Every Thread that has a Looper is able to receive and process messages. A HandlerThread is a Thread that implements such a Looper, for example th...
One (or two) of the coolest new features in recent Xcode releases are the IBInspectable properties and IBDesignable UIViews. These have nothing to do with the functionality of your application but instead impact the developer experience in Xcode. The goal is to be able to visually inspect custom v...

Page 22 of 153