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
In order to specify which version of python the Linux shell should use the first line of Python scripts can be a shebang line, which starts with #!:
#!/usr/bin/python
If you are in a virtual environment, then python myscript.py will use the Python from your virtual environment, but ./myscript.py...
To help to maintain clean code, Rails follows the principle of DRY.
It involves whenever possible, re-using as much code as possible rather than duplicating similar code in multiple places (for example, using partials). This reduces errors, keeps your code clean and enforces the principle of writin...
In Rails, you find yourself looking at controllers, views, and models for your database.
To reduce the need for heavy configuration, Rails implements rules to ease up working with the application. You may define your own rules but for the beginning (and for later on) it's a good idea to stick to co...
By default, the various Collection types are not thread-safe.
However, it's fairly easy to make a collection thread-safe.
List<String> threadSafeList = Collections.synchronizedList(new ArrayList<String>());
Set<String> threadSafeSet = Collections.synchronizedSet(new HashSet<S...
Given the following history, imagine you make a change that you want to squash into the commit bbb2222 A second commit:
$ git log --oneline --decorate
ccc3333 (HEAD -> master) A third commit
bbb2222 A second commit
aaa1111 A first commit
9999999 Initial commit
Once you've made your change...
The default value for an enum is zero. If an enum does not define an item with a value of zero, its default value will be zero.
public class Program
{
enum EnumExample
{
one = 1,
two = 2
}
public void Main()
{
var e =...
Now that the routes are defined, we need to let our application know about the routes.
To do this, bootstrap the provider we exported in the previous example.
Find your bootstrap configuration (should be in main.ts, but your mileage may vary).
//main.ts
import {bootstrap} from '@angular/platfo...
Now that the router is configured and our app knows how to handle the routes, we need to show the actual components that we configured.
To do so, configure your HTML template/file for your top-level (app) component like so:
//app.ts
import {Component} from '@angular/core';
import {Router, ROUT...
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...
NOTE: This example is based on the 3.0.0.-beta.2 release of the @angular/router. At the time of writing, this is the latest version of the router.
To use the router, define routes in a new TypeScript file like such
//app.routes.ts
import {provideRouter} from '@angular/router';
import {Home} ...
Imaginary numbers in Python are represented by a "j" or "J" trailing the target number.
1j # Equivalent to the square root of -1.
1j * 1j # = (-1+0j)
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...
The @import CSS at-rule is used to import style rules from other style sheets. These rules must precede all other types of rules, except @charset rules; as it is not a nested statement, @import cannot be used inside conditional group at-rules.
@import.
How to use @import
You can use @import rule ...
To generate a controller (for example Posts), navigate to your project directory from a command line or terminal, and run:
$ rails generate controller Posts
You can shorten this code by replacing generate with g, for example:
$ rails g controller Posts
If you open up the newly generated app/...
Python uses indentation to define control and loop constructs. This contributes to Python's readability, however, it requires the programmer to pay close attention to the use of whitespace. Thus, editor miscalibration could result in code that behaves in unexpected ways.
Python uses the colon symbo...
docker rm can be used to remove a specific containers like this:
docker rm <container name or id>
To remove all containers you can use this expression:
docker rm $(docker ps -qa)
By default docker will not delete a container that is running. Any container that is running will produce a...
Browsers have a default set of CSS styles they use for rendering elements. Some of these styles can even be customised using the browser's settings to change default font face and size definitions, for example. The styles contain the definition of which elements are supposed to be block-level or inl...