Tutorial by Examples: di

Let's assume you have a file lyrics.txt which contains the following data: summer has come and passed the innocent can never last wake me up when september ends Read the entire file at a time By using file:read_file(File), you can read the entire file. It's an atomic operation: 1> file:re...
There are no build-in methods for intersection and difference in Sets, but you can still achieve that but converting them to arrays, filtering, and converting back to Sets: var set1 = new Set([1, 2, 3, 4]), set2 = new Set([3, 4, 5, 6]); const intersection = new Set(Array.from(set1).filter(x...
Prelude often defines functions whose names are used elsewhere. Not hiding such imports (or using qualified imports where clashes occur) will cause compilation errors. Data.Stream defines functions named map, head and tail which normally clashes with those defined in Prelude. We can hide those impo...
C99 Macros with variadic args: Let's say you want to create some print-macro for debugging your code, let's take this macro as an example: #define debug_print(msg) printf("%s:%d %s", __FILE__, __LINE__, msg) Some examples of usage: The function somefunc() returns -1 if failed and 0 ...
View loading In a test for a view controller you want sometimes to trigger the execution of loadView() or viewDidLoad(). This can be done by accessing the view. Let's say you have view controller instance in your test called sut (system under test), then the code would look like this: XCTAssertNot...
C99 C99 introduced the concept of designated initializers. These allow you to specify which elements of an array, structure or union are to be initialized by the values following. Designated initializers for array elements For a simple type like plain int: int array[] = { [4] = 29, [5] = 31, [1...
Calculating the factorial of a number is a classic example of a recursive function. Missing the Base Condition: #include <stdio.h> int factorial(int n) { return n * factorial(n - 1); } int main() { printf("Factorial %d = %d\n", 3, factorial(3)); return 0;...
Hi everyone! This is a demo I love running for people that get started with BigQuery. So let's run some simple queries to get you started. Setup You will need a Google Cloud project: Go to http://bigquery.cloud.google.com/. If it tells you to create a project, follow the link to create a proje...
Observable.combineLatest(firstName.rx_text, lastName.rx_text) { $0 + " " + $1 } .map { "Greetings, \($0)" } .bindTo(greetingLabel.rx_text) Using the combineLatest operator every time an item is emitted by either of two Observables, combine the latest item emitted by each Obs...
const url = 'http://api.stackexchange.com/2.2/questions?site=stackoverflow&tagged=javascript'; const questionList = document.createElement('ul'); document.body.appendChild(questionList); const responseData = fetch(url).then(response => response.json()); responseData.then(({item...
There are many querying operations on maps. member :: Ord k => k -> Map k a -> Bool yields True if the key of type k is in Map k a: > Map.member "Alex" $ Map.singleton "Alex" 31 True > Map.member "Jenny" $ Map.empty False notMember is similar: &g...
This is very similar to using an Application subclass and overriding the attachBaseContext() method. However, using this method, you don't need to override attachBaseContext() as this is already done in the MultiDexApplication superclass. Extend MultiDexApplication instead of Application: package...
First, let's see three different ways of extracting data from a file. string fileText = File.ReadAllText(file); string[] fileLines = File.ReadAllLines(file); byte[] fileBytes = File.ReadAllBytes(file); On the first line, we read all the data in the file as a string. On the second line, we r...
Generally execute() command is used for fire and forget calls (without need of analyzing the result) and submit() command is used for analyzing the result of Future object. We should be aware of key difference of Exception Handling mechanisms between these two commands. Exceptions from submit() ar...
Images and files can be uploaded/submitted to server by setting enctype attribute of form tag to multipart/form-data. enctype specifies how form data would be encoded while submitting to the server. Example <form method="post" enctype="multipart/form-data" action="uplo...
#include <iostream> #include <string> int main() { const char * C_String = "This is a line of text w"; const char * C_Problem_String = "This is a line of text ኚ"; std::string Std_String("This is a second line of text w"); std::string...
display: inline-block; The display property with the value of inline-block is not supported by Internet Explorer 6 and 7. A work-around for this is: zoom: 1; *display: inline; The zoom property triggers the hasLayout feature of elements, and it is available only in Internet Explorer. The *di...
The Collections class provides a way to make a list unmodifiable: List<String> ls = new ArrayList<String>(); List<String> unmodifiableList = Collections.unmodifiableList(ls); If you want an unmodifiable list with one item you can use: List<String> unmodifiableList = Col...
The Collections class allows for you to move objects around in the list using various methods (ls is the List): Reversing a list: Collections.reverse(ls); Rotating positions of elements in a list The rotate method requires an integer argument. This is how many spots to move it along the line b...
Starting with Java 8, you can use lambda expressions & predicates. Example: Use a lambda expressions & a predicate to get a certain value from a list. In this example every person will be printed out with the fact if they are 18 and older or not. Person Class: public class Person { p...

Page 92 of 164