Tutorial by Examples

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...
In development, you may find that using require() on the same module multiple times always returns the same module, even if you have made changes to that file. This is because modules are cached the first time they are loaded, and any subsequent module loads will load from the cache. To get around ...
Some of the additional attributes are parsed by the npm website like repository, bugs or homepage and shown in the infobox for this packages { "main": "server.js", "repository" : { "type": "git", "url": "git+https:/...
Enums can be mutable, this is another way to obtain a singleton behavior: enum class Planet(var population: Int = 0) { EARTH(7 * 100000000), MARS(); override fun toString() = "$name[population=$population]" } println(Planet.MARS) // MARS[population=0] Planet.MARS.p...
We use this model from the first example: class Person(models.Model): name = models.CharField(max_length=50) description = models.TextField() class Club(models.Model): name = models.CharField(max_length=50) members = models.ManyToManyField(Person) Add Tom and Bill to the N...
repeat(10) { i -> println("This line will be printed 10 times") println("We are on the ${i + 1}. loop iteration") }
You can loop over any iterable by using the standard for-loop: val list = listOf("Hello", "World", "!") for(str in list) { print(str) } Lots of things in Kotlin are iterable, like number ranges: for(i in 0..9) { print(i) } If you need an index while...
While and do-while loops work like they do in other languages: while(condition) { doSomething() } do { doSomething() } while (condition) In the do-while loop, the condition block has access to values and variables declared in the loop body.
Break and continue keywords work like they do in other languages. while(true) { if(condition1) { continue // Will immediately start the next iteration, without executing the rest of the loop body } if(condition2) { break // Will exit the loop completely } } ...
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...
Polymer prodives a lot of well built elements for you to use in your app. Browse them in their Element Catalog. Let's go through the workflow of using an element by including paper-input (Documentation) Download the Element To Download an element there are two ways: Bower The convinient way is...
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 */ ...
The following example is an introduction to: Template compilation using underscore Accessing variables in a template Creating a view Rendering a view Showing a view <html> <head> <script src="https://code.jquery.com/jquery-3.1.0.min.js"></script> ...
Occasionally, we may want to display dialogs with more than one pane of content. jQuery UI offers tabs that can be used in tandem with a dialog to make this possible. While it may be more common to have tabs within a dialog's content container, this example will demonstrate how to make a list of t...
Higher-order functions can be used to implement generic algorithms, giving up the responsibility of providing final details to the user. For instance List.sort expects a comparison function, which allows to implement various ways of sorting. Here we implement case-insensitive sorting of strings: le...
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...
The ls command has several options that can be used together to show more information. Details/Rights The l option shows the file permissions, size, and last modified date. So if the root directory contained a dir called test and a file someFile the command: user@linux-computer:~$ ls -l Would ...
Most modern distributions will come with BASH (Bourne Again SHell) pre-installed and configured as a default shell. The command (actually an executable binary, an ELF) that is responsible for changing shells in Linux is chsh (change shell). We can first check which shells are already installed and...
Observables are broadly categorised as Hot or Cold, depending on their emission behaviour. A Cold Observable is one which starts emitting upon request(subscription), whereas a Hot Observable is one that emits regardless of subscriptions. Cold Observable /* Demonstration of a Cold Observable */ Ob...

Page 346 of 1336