Tutorial by Examples: er

Code that uses generics has many benefits over non-generic code. Below are the main benefits Stronger type checks at compile time A Java compiler applies strong type checking to generic code and issues errors if the code violates type safety. Fixing compile-time errors is easier than fixing runt...
Example uses basic HTTP syntax. Any <#> in the example should be removed when copying it. You can use the _cat APIs to get a human readable, tabular output for various reasons. GET /_cat/health?v <1> The ?v is optional, but it implies that you want "verbose" output. _...
To filter a slice without allocating a new underlying array: // Our base slice slice := []int{ 1, 2, 3, 4 } // Create a zero-length slice with the same underlying array tmp := slice[:0] for _, v := range slice { if v % 2 == 0 { // Append desired values to slice tmp = append(tmp, ...
use std::error::Error; use std::fmt; use std::convert::From; use std::io::Error as IoError; use std::str::Utf8Error; #[derive(Debug)] // Allow the use of "{:?}" format specifier enum CustomError { Io(IoError), Utf8(Utf8Error), Other, } // Allow the use of "{...
fn foo<'a>(x: &'a u32) { // ... } This specifies that foo has lifetime 'a, and the parameter x must have a lifetime of at least 'a. Function lifetimes are usually omitted through lifetime elision: fn foo(x: &u32) { // ... } In the case that a function takes multiple ...
The * operator can be used to unpack variables and arrays so that they can be passed as individual arguments to a method. This can be used to wrap a single object in an Array if it is not already: def wrap_in_array(value) [*value] end wrap_in_array(1) #> [1] wrap_in_array([1, 2, 3]) ...
Instead of requesting an ILoggerFactory and creating an instance of ILogger explicitly, you can request an ILogger (where T is the class requesting the logger). public class TodoController : Controller { private readonly ILogger _logger; public TodoController(ILogger<TodoController...
Using iris dataset: import sklearn.datasets iris_dataset = sklearn.datasets.load_iris() X, y = iris_dataset['data'], iris_dataset['target'] Data is split into train and test sets. To do this we use the train_test_split utility function to split both X and y (data and target vectors) randomly w...
Different operations with data are done using special classes. Most of the classes belong to one of the following groups: classification algorithms (derived from sklearn.base.ClassifierMixin) to solve classification problems regression algorithms (derived from sklearn.base.RegressorMixin) to so...
A Service is a component which runs in the background (on the UI thread) without direct interaction with the user. An unbound Service is just started, and is not bound to the lifecycle of any Activity. To start a Service you can do as shown in the example below: // This Intent will be used to star...
await operator and async keyword come together: The asynchronous method in which await is used must be modified by the async keyword. The opposite is not always true: you can mark a method as async without using await in its body. What await actually does is to suspend execution of the code ...
1) BASIC SIMPLE WAY Database-driven applications often need data pre-seeded into the system for testing and demo purposes. To make such data, first create the seeder class ProductTableSeeder use Faker\Factory as Faker; use App\Product; class ProductTableSeeder extends DatabaseSeeder { pub...
The zero value of slice is nil, which has the length and capacity 0. A nil slice has no underlying array. But there are also non-nil slices of length and capacity 0, like []int{} or make([]int, 5)[5:]. Any type that have nil values can be converted to nil slice: s = []int(nil) To test whether a...
The Python Standard Library includes an interactive debugging library called pdb. pdb has extensive capabilities, the most commonly used being the ability to 'step-through' a program. To immediately enter into step-through debugging use: python -m pdb <my_file.py> This will start the debu...
PHP 7 introduces a new kind of operator, which can be used to compare expressions. This operator will return -1, 0 or 1 if the first expression is less than, equal to, or greater than the second expression. // Integers print (1 <=> 1); // 0 print (1 <=> 2); // -1 print (2 <=> 1...
setTimeout Executes a function, after waiting a specified number of milliseconds. used to delay the execution of a function. Syntax : setTimeout(function, milliseconds) or window.setTimeout(function, milliseconds) Example : This example outputs "hello" to the console after 1 secon...
To access functions and properties of nullable types, you have to use special operators. The first one, ?., gives you the property or function you're trying to access, or it gives you null if the object is null: val string: String? = "Hello World!" print(string.length) // Compile erro...
class Person { public string FirstName { get; set; } public string LastName { get; set; } } class Pet { public string Name { get; set; } public Person Owner { get; set; } } public static void Main(string[] args) { var magnus = new Person { FirstName = "Magnus...
The unary plus (+) precedes its operand and evaluates to its operand. It attempts to convert the operand to a number, if it isn't already. Syntax: +expression Returns: a Number. Description The unary plus (+) operator is the fastest (and preferred) method of converting something into a n...
The delete operator deletes a property from an object. Syntax: delete object.property delete object['property'] Returns: If deletion is successful, or the property did not exist: true If the property to be deleted is an own non-configurable property (can't be deleted): false in non...

Page 82 of 417