Tutorial by Examples

An assertion is a statement used to assert that a fact must be true when that line of code is reached. Assertions are useful for ensuring that expected conditions are met. When the condition passed to an assertion is true, there is no action. The behavior on false conditions depends on compiler fl...
C11 Static assertions are used to check if a condition is true when the code is compiled. If it isn't, the compiler is required to issue an error message and stop the compiling process. A static assertion is one that is checked at compile time, not run time. The condition must be a constant expres...
To find files/directories with a specific name, relative to pwd: $ find . -name "myFile.txt" ./myFile.txt To find files/directories with a specific extension, use a wildcard: $ find . -name "*.txt" ./myFile.txt ./myFile2.txt To find files/directories matching one of ma...
To find files, use the -type f flag $ find . -type f To find directories, use the -type d flag $ find . -type d To find block devices, use the -type b flag $ find /dev -type b To find symlinks, use the -type l flag $ find . -type l
Sometimes we will need to run commands against a lot of files. This can be done using xargs. find . -type d -print | xargs -r chmod 770 The above command will recursively find all directories (-type d) relative to . (which is your current working directory), and execute chmod 770 on them. The -...
lscount returns a time bucketed count of matching documents in the LogStash index, according to the specified filter. A trivial use of this would be to check how many documents in total have been received in the 5 minutes, and alert if it is below a certain threshold. A Bosun alert for this might ...
lsstat returns various summary stats per bucket for the specified field. The field must be numeric in elastic. rStat can be one of avg, min, max, sum, sum_of_squares, variance, std_deviation. The rest of the fields behave the same as lscount, except that there is no division based on bucketDuratio...
The Promise.resolve static method can be used to wrap values into promises. let resolved = Promise.resolve(2); resolved.then(value => { // immediately invoked // value === 2 }); If value is already a promise, Promise.resolve simply recasts it. let one = new Promise(resolve => ...
At its simplest, a unit test consists of three stages: Prepare the environment for the test Execute the code to be tested Validate the expected behaviour matches the observed behaviour These three stages are often called 'Arrange-Act-Assert', or 'Given-When-Then'. Below is example in C# tha...
#include <stdio.h> #define is_const_int(x) _Generic((&x), \ const int *: "a const int", \ int *: "a non-const int", \ default: "of other type") int main(void) { const int i = 1; int j = 1; double...
#include <stdio.h> void print_int(int x) { printf("int: %d\n", x); } void print_dbl(double x) { printf("double: %g\n", x); } void print_default() { puts("unknown argument"); } #define print(X) _Generic((X), \ int: print_int, \ double: pri...
A lambda expression provides a concise way to create simple function objects. A lambda expression is a prvalue whose result object is called closure object, which behaves like a function object. The name 'lambda expression' originates from lambda calculus, which is a mathematical formalism invented...
For lambdas with a single return statement, or multiple return statements whose expressions are of the same type, the compiler can deduce the return type: // Returns bool, because "value > 10" is a comparison which yields a Boolean result auto l = [](int value) { return value &gt...
If you specify the variable's name in the capture list, the lambda will capture it by value. This means that the generated closure type for the lambda stores a copy of the variable. This also requires that the variable's type be copy-constructible: int a = 0; [a]() { return a; // Ok, 'a' ...
On an ext filesystem, each file has a stored Access, Modification, and (Status) Change time associated with it - to view this information you can use stat myFile.txt; using flags within find, we can search for files that were modified within a certain time range. To find files that have been modifi...
To encode a string into a byte array, you can simply use the String#getBytes() method, with one of the standard character sets available on any Java runtime: byte[] bytes = "test".getBytes(StandardCharsets.UTF_8); and to decode: String testString = new String(bytes, StandardCharsets.U...
Tuples group multiple values into a single compound value. The values within a tuple can be of any type and do not have to be of the same type as each other. Tuples are created by grouping any amount of values: let tuple = ("one", 2, "three") // Values are read using index n...
Tuples can be decomposed into individual variables with the following syntax: let myTuple = (name: "Some Name", age: 26) let (first, second) = myTuple print(first) // "Some Name" print(second) // 26 This syntax can be used regardless of if the tuple has unnamed properti...
Functions can return tuples: func tupleReturner() -> (Int, String) { return (3, "Hello") } let myTuple = tupleReturner() print(myTuple.0) // 3 print(myTuple.1) // "Hello" If you assign parameter names, they can be used from the return value: func tupleReturner(...
If you want a function to be able to throw errors, you need to add the throws keyword after the parentheses that hold the arguments: func errorThrower()throws -> String {} When you want to throw an error, use the throw keyword: func errorThrower()throws -> String { if true { retur...

Page 68 of 1336