Tutorial by Examples: st

Type check: variable.isInstanceOf[Type] With pattern matching (not so useful in this form): variable match { case _: Type => true case _ => false } Both isInstanceOf and pattern matching are checking only the object's type, not its generic parameter (no type reification), except fo...
Let's say we need to add a button for each piece of loadedData array (for instance, each button should be a slider showing the data; for the sake of simplicity, we'll just alert a message). One may try something like this: for(var i = 0; i < loadedData.length; i++) jQuery("#container&q...
Let's take an example of a function which receives two arguments and returns a value indicating their sum: def two_sum(a, b): return a + b By looking at this code, one can not safely and without doubt indicate the type of the arguments for function two_sum. It works both when supplied with ...
The __info__/1 function takes one of the following atoms: :functions - Returns a keyword list of public functions along with their arities :macros - Returns a keyword list of public macros along with their arities To list the Kernel module’s functions: iex> Kernel.__info__ :functions [...
Detailed instructions on getting websphere-mq set up or installed.
Use keyword lists for 'options'-style parameters that contains multiple key-value pairs: def myfunc(arg1, opts \\ []) do # Function body end We can call the function above like so: iex> myfunc "hello", pizza: true, soda: false which is equivalent to: iex> myfunc("he...
If you are looking to run a file, such as an executable, use child_process.execFile. Instead of spawning a shell like child_process.exec would, it will directly create a new process, which is slightly more efficient than running a command. The function can be used like so: const execFile = require(...
Programs throw errors when for instance wrong input is given. Because of this, one needs to make sure that an error is thrown when actual wrong input is given. Because of that we need to check for an exact exception, for this example we will use the following exception: class WrongInputException(Ex...
A strategy pattern can be used in Javascript in many cases to replace a switch statement. It is especially helpful when the number of conditions is dynamic or very large. It allows the code for each condition to be independent and separately testable. Strategy object is simple an object with multip...
We got the following very basic element my-element saved as src/my-element.html <link rel="import" href="bower_components/polymer/polymer.html"> <dom-module id="my-element"> <template> <style> /* local styles go here */ ...
Higher-order functions can be used to ensure that system resources are disposed, even when a treatment raises an exception. The pattern used by with_output_file allows a clean separation of concerns: the higher-order with_output_file functions takes care of managing the system resources bound to fi...
List.map has the signature ('a -> 'b) -> 'a list -> 'b list which in English is a function that takes a function (we'll call this the mapping function) from one type (namely 'a) to another type (namely 'b) and a list of the first type. The function returns a list of the second type where ev...
From JavaDoc The Theories runner allows to test a certain functionality against a subset of an infinite set of data points. Running theories import org.junit.experimental.theories.Theories; import org.junit.experimental.theories.Theory; import org.junit.runner.RunWith; @RunWith(Theories...
A deadlock occurs when two competing actions wait for the other to finish, and thus neither ever does. In java there is one lock associated with each object. To avoid concurrent modification done by multiple threads on single object we can use synchronized keyword, but everything comes at a cost....
A group of non-interactive list items. <ul role="list"> <li role="listitem">One</li> <li role="listitem">Two</li> <li role="listitem">Three</li> </ul>
A widget that allows the user to select one or more items from a list of choices. <ul role="listbox"> <li>One</li> <li>Two</li> <li>Three</li> </ul> Typically, you would use JavaScript to build the multiple-selection functionali...
A single item in a list or directory. <ul role="list"> <li role="listitem">One</li> <li role="listitem">Two</li> <li role="listitem">Three</li> </ul>
A container whose content is advisory information for the user but is not important enough to justify an alert, often but not necessarily presented as a status bar. <div role="status">Online</div>
A list of tab elements, which are references to tabpanel elements. <ul role="tablist"> <li role="tab">Introduction</li> <li role="tab">Chapter 1</li> <li role="tab">Chapter 2</li> </ul>
import java.nio.charset.StandardCharsets; import java.util.Arrays; public class GetUtf8BytesFromString { public static void main(String[] args) { String str = "Cyrillic symbol Ы"; //StandardCharsets is available since Java 1.7 //for ealier version use ...

Page 94 of 369