Tutorial by Examples

zip takes two lists and returns a list of corresponding pairs: zip [] _ = [] zip _ [] = [] zip (a:as) (b:bs) = (a,b) : zip as bs > zip [1,3,5] [2,4,6] > [(1,2),(3,4),(5,6)] Zipping two lists with a function: zipWith f [] _ = [] zipWith f _ [] =...
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 ...
Convert in uppercase the string argument Syntax: UPPER(str) UPPER('fOoBar') -- 'FOOBAR' UCASE('fOoBar') -- 'FOOBAR'
To generalize type_trait creation:based on SFINAE there are experimental traits detected_or, detected_t, is_detected. With template parameters typename Default, template <typename...> Op and typename ... Args: is_detected: alias of std::true_type or std::false_type depending of the validi...
debug() and debugonce() won't work well in the context of most Shiny debugging. However, browser() statements inserted in critical places can give you a lot of insight into how your Shiny code is (not) working. See also: Debugging using browser() Showcase mode Showcase mode displays your app alo...
To concatenate the value of two or more variables into a single string and print it as the output, we need to make use of interpolation. The following Less code, #demo:after { @var1: Hello; @var2: World!!!; content: "@{var1} @{var2}"; } when compiled would set "Hello Wo...
Drawing to canvas isn't just limited to shapes and images. You can also draw text to the canvas. To draw text on the canvas, get a reference to the canvas and then call the fillText method on the context. var canvas = document.getElementById('canvas'); var ctx = canvas.getContext('2d'); ctx.fill...
The default font formatting provided by the fillText and strokeText methods isn't very aesthetically appealing. Fortunately the canvas API provides properties for formatting text. Using the font property you can specify: font-style font-variant font-weight font-size / line-height font-family...
Native Canvas API does not have a method to wrap text onto the next line when a desired maximum width is reached. This example wraps text into paragraphs. function wrapText(text, x, y, maxWidth, fontSize, fontFace){ var firstY=y; var words = text.split(' '); var line = ''; var lineHeigh...
This example draws text paragraphs into any portions of the canvas that have opaque pixels. It works by finding the next block of opaque pixels that is large enough to contain the next specified word and filling that block with the specified word. The opaque pixels can come from any source: Path d...
This example fills text with a specified image. Important! The specified image must be fully loaded before calling this function or the drawing will fail. Use image.onload to be sure the image is fully loaded. function drawImageInsideText(canvas,x,y,img,text,font){ var c=canvas.cloneNode();...
Classes, structs, enums and all their methods are internal by default. This means they can be only accessed from the same module. The test cases are in a different target an this means they are in a different module. To be able to access the method you want to test, you need to import the module to ...
If you want to add a Drawable be shown during the load, you can add a placeholder: Glide.with(context) .load(yourUrl) .placeholder(R.drawable.placeholder) .into(imageView); If you want a Drawable to be shown if the load fails for any reason: Glide.with(context) .load(yourUrl...
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...
Some attributes are directly accessible as properties of the element (e.g. alt, href, id, title and value). document.querySelector("a").href = "#top"; Other attributes, including data-attributes can be set as follows: document.querySelector("a").setAttribute("...
To remove an attribute, including directly accessible properties document.querySelector("a").removeAttribute("title"); Data attributes can also be removed as follows (modern browsers): // remove "data-foo" attribute delete document.querySelector("a").dat...
// Add observer let observer = NSNotificationCenter.defaultCenter().addObserverForName("nameOfTheNotification", object: nil, queue: nil) { (notification) in // Do operations with the notification in this block } // Remove observer NSNotificationCenter.defaultCenter().removeObser...
In its simplest form supported by all versions of bash, case statement executes the case that matches the pattern. ;; operator breaks after the first match, if any. #!/bin/bash var=1 case $var in 1) echo "Antartica" ;; 2) echo "Brazil" ;; 3) echo "Cat&qu...
4.0 Since bash 4.0, a new operator ;& was introduced which provides fall through mechanism. #!/bin/bash var=1 case $var in 1) echo "Antartica" ;& 2) echo "Brazil" ;& 3) echo "Cat" ;& esac Outputs: Antartica Brazil Cat ...
4.0 Since Bash 4.0, another operator ;;& was introduced which also provides fall through only if the patterns in subsequent case statement(s), if any, match. #!/bin/bash var=abc case $var in a*) echo "Antartica" ;;& xyz) echo "Brazil" ;;& *b*) ...

Page 725 of 1336