Tutorial by Examples: e

In Object Oriented Programming a common task is to compose objects (values). In Functional Programming it is as common task to compose values as well as functions. We are used to compose values from our experience of other programming languages using operators like +, -, *, / and so on. Value co...
In a statically typed language like F# we work with types well-known at compile-time. We consume external data sources in a type-safe manner using type providers. However, occassionally there's need to use late binding (like dynamic in C#). For instance when working with JSON documents that have...
let seq = seq {0..10} s |> Seq.map (fun x -> x * 2) > val it : seq<int> = seq [2; 4; 6; 8; ...] Apply a function to every element of a sequence using Seq.map
Assumptions: TableView - reference to the TableView DataSource - is a class which inherits UITableViewSource DataSource.Objects - is a public List< object >(), accessible to the UIViewController private UIRefreshControl refreshControl; public override void ViewDidLoad() { base.V...
Named Types Dim someInstance As New SomeClass(argument) With { .Member1 = value1, .Member2 = value2 '... } Is equivalent to Dim someInstance As New SomeClass(argument) someInstance.Member1 = value1 someInstance.Member2 = value2 '... Anonymous Types (Option...
Arrays Dim names = {"Foo", "Bar"} ' Inferred as String() Dim numbers = {1, 5, 42} ' Inferred as Integer() Containers (List(Of T), Dictionary(Of TKey, TValue), etc.) Dim names As New List(Of String) From { "Foo", "Bar" '... ...
A for loop iterates from the starting value to the ending value inclusive. program SimpleForLoop; {$APPTYPE CONSOLE} var i : Integer; begin for i := 1 to 10 do WriteLn(i); end. Output: 1 2 3 4 5 6 7 8 9 10
You might expect a Python dictionary to be sorted by keys like, for example, a C++ std::map, but this is not the case: myDict = {'first': 1, 'second': 2, 'third': 3} print(myDict) # Out: {'first': 1, 'second': 2, 'third': 3} print([k for k in myDict]) # Out: ['second', 'third', 'first'] Py...
This example demonstrates POSIX Timer usage with CLOCK_REALTIME clock and SIGEV_THREAD notification method. #include <stdio.h> /* for puts() */ #include <string.h> /* for memset() */ #include <unistd.h> /* for sleep() */ #include <stdlib.h> /* for EXIT_SUCCESS */ #inc...
C# using OpenQA.Selenium using OpenQA.Selenium.Chrome; using System.Threading; namespace WebDriver Tests { class WebDriverWaits { static void Main() { IWebDriver driver = new ChromeDriver(@"C:\WebDriver"); driver.Na...
scrollViewDidEndDecelerating: this tells the delegate that the scroll view has ended decelerating the scrolling movement. Objective C: - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView { [self stoppedScrolling]; } - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView w...
This example shows how to define a simple model in Sails.js You can generate an empty model file by typing sails generate model car You'll find the new file Car.js in api/models/. Next, you fill in some details. modules.exports = { tableName : 'cars', connection : 'mongodb', attr...
The main app file loads any routes files in which you would like to define routes. To do so we need the following directory structure: app.js routes/index.js routes/users.js app.js var express = require('express'); var app = express(); app.use('/', require('./routes/index')); app.use('/us...
Methods that perform asynchronous operations don't need to use await if: There is only one asynchronous call inside the method The asynchronous call is at the end of the method Catching/handling exception that may happen within the Task is not necessary Consider this method that returns a Ta...
Here we consider sums of the form a + b + a + b + ... a vs. a + b + a + b + ... b To visualize these sums, imagine a section of fence alternating between posts and rails. Three scenarios are possible. Imagine a section of fence with posts at each end, connected by rails. n rails require...
Normally Android-SQLiteOpenHelper does not allow fully qualified path names where the database should be stored. So public database files are not possible. You can use the SQLiteOpenHelper with a custom path if you provide a custom ContextClass and if you have write access in the target directory. ...
Mockito provides a Matcher<T> interface along with an abstract ArgumentMatcher<T> class to verify arguments. It uses a different approach to the same use-case than the ArgumentCaptor. Additionally the ArgumentMatcher can be used in mocking too. Both use-cases make use of the Mockito.argT...
Here this will calculate the UTC time offset from current data in desired timezone. +(NSTimeInterval)getUTCOffSetIntervalWithCurrentTimeZone:(NSTimeZone *)current forDate:(NSDate *)date { NSTimeZone *utcTimeZone = [NSTimeZone timeZoneWithAbbreviation:@"UTC"]; NSInteger currentG...
Checking whether the current date contains the symbol for AM or PM Objective-C NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setLocale:[NSLocale currentLocale]]; [formatter setDateStyle:NSDateFormatterNoStyle]; [formatter setTimeStyle:NSDateFormatterShortStyle]; NSStr...

Page 559 of 1191