Tutorial by Examples: ch

It's possible to treat multiple, distinct values the same way, using |: enum Colour { Red, Green, Blue, Cyan, Magenta, Yellow, Black } enum ColourModel { RGB, CMYK } // let's take an example colour let colour = Colour::Red; let model = match ...
Patterns can be matched based on values independent to the value being matched using if guards: // Let's imagine a simplistic web app with the following pages: enum Page { Login, Logout, About, Admin } // We are authenticated let is_authenticated = true; // But we aren't admins...
To select the children of an element you can use the children() method. <div class="parent"> <h2>A headline</h2> <p>Lorem ipsum dolor sit amet...</p> <p>Praesent quis dolor turpis...</p> </div> Change the color of all the ...
index.html <!doctype html> <html> <head> <title>D3 Sample</title> </head> <body> <!-- This will serve as a container for our chart. This does not have to be a div, and can in fact, just be the body if you want. --> <div id=...
This thread-safe version of a singleton was necessary in the early versions of .NET where static initialization was not guaranteed to be thread-safe. In more modern versions of the framework a statically initialized singleton is usually preferred because it is very easy to make implementation mistak...
<?php foreach ($collection as $item): do_something($item); endforeach; ?> <?php foreach ($collection as $item): ?> <p>Do something in HTML with <?php echo $item; ?></p> <?php endforeach; ?>
<?php switch ($condition): case $value: do_something(); break; default: do_something_else(); break; endswitch; ?> <?php switch ($condition): ?> <?php case $value: /* having whitespace before your cases will cause an error */ ?&g...
Let's create our own error type for this example. 2.2 enum CustomError: ErrorType { case SomeError case AnotherError } func throwing() throws { throw CustomError.SomeError } 3.0 enum CustomError: Error { case someError case anotherError } func throwing() thr...
If you are using the default bash prompt on Linux, you should see the name of the virtual environment at the start of your prompt. (my-project-env) user@hostname:~$ which python /home/user/my-project-env/bin/python
Now that the routes are set up, we need some way to actually change routes. This example will show how to change routes using the template, but it is possible to change routes in TypeScript. Here is one example (without binding): <a routerLink="/home">Home</a> If the user...
git cherry-pick <commit-A>..<commit-B> will place every commit after A and up to and including B on top of the currently checked-out branch. git cherry-pick <commit-A>^..<commit-B> will place commit A and every commit up to and including B on top of the currently checked-out...
execute the following command to insert the text into a view with a focus (if it supports text input) 6.0 Send text on SDK 23+ adb shell "input keyboard text 'Paste text on Android Device'" If already connected to your device via adb: input text 'Paste text on Android Device' 6...
General syntax git push <remotename> <object>:<remotebranchname> Example git push origin master:wip-yourname Will push your master branch to the wip-yourname branch of origin (most of the time, the repository you cloned from). Delete remote branch Deleting the remote br...
Note that some syntax elements have different behavior depending on the expression. SyntaxDescription?Match the preceding character or subexpression 0 or 1 times. Also used for non-capturing groups, and named capturing groups.*Match the preceding character or subexpression 0 or more times.+Match th...
Let's say you have a simple myblog app with the following model: from django.conf import settings from django.utils import timezone class Article(models.Model): title = models.CharField(max_length=70) slug = models.SlugField(max_length=70, unique=True) author = models.ForeignKe...
You can create a tuple and use a switch like so: var str: String? = "hi" var x: Int? = 5 switch (str, x) { case (.Some,.Some): print("Both have values") case (.Some, nil): print("String has a value") case (nil, .Some): print("Int has a value&...
If you want to measure benchmarks add a testing method like this: sum.go: package sum // Sum calculates the sum of two integers func Sum(a, b int) int { return a + b } sum_test.go: package sum import "testing" func BenchmarkSum(b *testing.B) { for i := 0; i < ...
You can use Optional Chaining in order to call a method, access a property or subscript an optional. This is done by placing a ? between the given optional variable and the given member (method, property or subscript). struct Foo { func doSomething() { print("Hello World!") ...
Array.isArray(obj) returns true if the object is an Array, otherwise false. Array.isArray([]) // true Array.isArray([1, 2, 3]) // true Array.isArray({}) // false Array.isArray(1) // false In most cases you can instanceof to check if an object is an Array. []...
This technique works even when the container's dimensions are unknown. Set up a "ghost" element inside the container to be centered that is 100% height, then use vertical-align: middle on both that and the element to be centered. CSS /* This parent can be any width and height */ .block...

Page 12 of 109