Tutorial by Examples: ast

To join all of an array's elements into a string, you can use the join method: console.log(["Hello", " ", "world"].join("")); // "Hello world" console.log([1, 800, 555, 1234].join("-")); // "1-800-555-1234" As you can see in ...
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 ...
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(...
A stub is a light weight test double that provides canned responses when methods are called. Where a class under test relies on an interface or base class an alternative 'stub' class can be implemented for testing which conforms to the interface. So, assuming the following interface, public inter...
The terms Mock and Stub can often become confused. Part of the reason for this is that many mocking frameworks also provide support for creating Stubs without the verification step associated with Mocking. Rather than writing a new class to implement a stub as in the "Using a stub to supply c...
The first argument of re.match() is the regular expression, the second is the string to match: import re pattern = r"123" string = "123zzb" re.match(pattern, string) # Out: <_sre.SRE_Match object; span=(0, 3), match='123'> match = re.match(pattern, string) ma...
' Omitting the 4th and 5th argument ("xpos" and "ypos") will result in the prompt ' being display center of the parent screen exampleString = InputBox("What is your name?", "Name Check", "Jon Skeet", 2500, 2000) WScript.Echo "Your name ...
Number('0') === 0 Number('0') will convert the string ('0') into a number (0) A shorter, but less clear, form: +'0' === 0 The unary + operator does nothing to numbers, but converts anything else to a number. Interestingly, +(-12) === -12. parseInt('0', 10) === 0 parseInt('0', 10) will c...
String(0) === '0' String(0) will convert the number (0) into a string ('0'). A shorter, but less clear, form: '' + 0 === '0'
3.0 Check if a string consists in exactly 8 digits: $ date=20150624 $ [[ $date =~ ^[0-9]{8}$ ]] && echo "yes" || echo "no" yes $ date=hello $ [[ $date =~ ^[0-9]{8}$ ]] && echo "yes" || echo "no" no
Performs an explicit conversion into the given type from the value resulting from evaluating the given expression. int x = 3; int y = 4; printf("%f\n", (double)x / y); /* Outputs "0.750000". */ Here the value of x is converted to a double, the division promotes the value of...
std::map and std::multimap both can be initialized by providing key-value pairs separated by comma. Key-value pairs could be provided by either {key, value} or can be explicitly created by std::make_pair(key, value). As std::map does not allow duplicate keys and comma operator performs right to left...
main = do input <- getContents putStr input Input: This is an example sentence. And this one is, too! Output: This is an example sentence. And this one is, too! Note: This program will actually print parts of the output before all of the input has been fully read in. This m...
To find a character or another string, you can use std::string::find. It returns the position of the first character of the first match. If no matches were found, the function returns std::string::npos std::string str = "Curiosity killed the cat"; auto it = str.find("cat"); ...
In C++, threads are created using the std::thread class. A thread is a separate flow of execution; it is analogous to having a helper perform one task while you simultaneously perform another. When all the code in the thread is executed, it terminates. When creating a thread, you need to pass somet...
// Java: IntStream.range(1, 4) .mapToObj(i -> "a" + i) .forEach(System.out::println); // a1 // a2 // a3 // Kotlin: (inclusive range) (1..3).map { "a$it" }.forEach(::println)
string s = "Foo"; string paddedLeft = s.PadLeft(5); // paddedLeft = " Foo" (pads with spaces by default) string paddedRight = s.PadRight(6, '+'); // paddedRight = "Foo+++" string noPadded = s.PadLeft(2); // noPadded = "Foo" (original string...
public struct Vector { public int X; public int Y; public int Z; } public struct Point { public decimal x, y; public Point(decimal pointX, decimal pointY) { x = pointX; y = pointY; } } struct instance fields can be set via a p...
Any fold can be run in the opposite direction with the help of the Dual monoid, which flips an existing monoid so that aggregation goes backwards. newtype Dual a = Dual { getDual :: a } instance Monoid m => Monoid (Dual m) where mempty = Dual mempty (Dual x) `mappend` (Dual y) = Dua...
A traversal can be run in the opposite direction with the help of the Backwards applicative functor, which flips an existing applicative so that composed effects take place in reversed order. newtype Backwards f a = Backwards { forwards :: f a } instance Applicative f => Applicative (Backward...

Page 3 of 26