Tutorial by Examples: ar

2.0 Guard checks for a condition, and if it is false, it enters the branch. Guard check branches must leave its enclosing block either via return, break, or continue (if applicable); failing to do so results in a compiler error. This has the advantage that when a guard is written it's not possible ...
To allow the use of in for custom classes the class must either provide the magic method __contains__ or, failing that, an __iter__-method. Suppose you have a class containing a list of lists: class ListList: def __init__(self, value): self.value = value # Create a set of al...
(Note: All examples using let are also valid for const) var is available in all versions of JavaScript, while let and const are part of ECMAScript 6 and only available in some newer browsers. var is scoped to the containing function or the global space, depending when it is declared: var x = 4; /...
You will first need to create a directory, access it in your shell and install Express using npm by running npm install express --save Create a file and name it app.js and add the following code which creates a new Express server and adds one endpoint to it (/ping) with the app.get method: const e...
A dictionary is an example of a key value store also known as Mapping in Python. It allows you to store and retrieve elements by referencing a key. As dictionaries are referenced by key, they have very fast lookups. As they are primarily used for referencing items by key, they are not sorted. crea...
Python 3.2+ has support for %z format when parsing a string into a datetime object. UTC offset in the form +HHMM or -HHMM (empty string if the object is naive). Python 3.x3.2 import datetime dt = datetime.datetime.strptime("2016-04-15T08:27:18-0500", "%Y-%m-%dT%H:%M:%S%z"...
Dates don't exist in isolation. It is common that you will need to find the amount of time between dates or determine what the date will be tomorrow. This can be accomplished using timedelta objects import datetime today = datetime.date.today() print('Today:', today) yesterday = today - date...
Parameters can be used for returning one or more values; those parameters are required to be non-const pointers or references. References: void calculate(int a, int b, int& c, int& d, int& e, int& f) { c = a + b; d = a - b; e = a * b; f = a / b; } Pointers: ...
C++11 The container std::array can bundle together a fixed number of return values. This number has to be known at compile-time and all return values have to be of the same type: std::array<int, 4> bar(int a, int b) { return { a + b, a - b, a * b, a / b }; } This replaces c style ar...
There are several ways to extract characters from a std::string and each is subtly different. std::string str("Hello world!"); operator[](n) Returns a reference to the character at index n. std::string::operator[] is not bounds-checked and does not throw an exception. The caller is...
A C++ namespace is a collection of C++ entities (functions, classes, variables), whose names are prefixed by the name of the namespace. When writing code within a namespace, named entities belonging to that namespace need not be prefixed with the namespace name, but entities outside of it must use t...
These are all equivalent, the code inside the blocks will run when the document is ready: $(function() { // code }); $().ready(function() { // code }); $(document).ready(function() { // code }); Because these are equivalent the first is the recommended form, the following is a ...
To remove an element inside an array, e.g. the element with the index 1. $fruit = array("bananas", "apples", "peaches"); unset($fruit[1]); This will remove the apples from the list, but notice that unset does not change the indexes of the remaining elements. So $fr...
var='0123456789abcdef' # Define a zero-based offset $ printf '%s\n' "${var:3}" 3456789abcdef # Offset and length of substring $ printf '%s\n' "${var:3:4}" 3456 4.2 # Negative length counts from the end of the string $ printf '%s\n' "${var:3:-5}" 3456789a...
cat < file.txt Output is same as cat file.txt, but it reads the contents of the file from standard input instead of directly from the file. printf "first line\nSecond line\n" | cat -n The echo command before | outputs two lines. The cat command acts on the output to add line num...
# Length of a string $ var='12345' $ echo "${#var}" 5 Note that it's the length in number of characters which is not necessarily the same as the number of bytes (like in UTF-8 where most characters are encoded in more than one byte), nor the number of glyphs/graphemes (some of which ...
CREATE TABLE Employees ( Id int NOT NULL, PRIMARY KEY (Id), ... ); This will create the Employees table with 'Id' as its primary key. The primary key can be used to uniquely identify the rows of a table. Only one primary key is allowed per table. A key can also be composed by one...
This will draw a line at the bottom of every view but the last to act as a separator between items. public class SeparatorDecoration extends RecyclerView.ItemDecoration { private final Paint mPaint; private final int mAlpha; public SeparatorDecoration(@ColorInt int color, float w...
The class template std::shared_ptr defines a shared pointer that is able to share ownership of an object with other shared pointers. This contrasts to std::unique_ptr which represents exclusive ownership. The sharing behavior is implemented through a technique known as reference counting, where the...
Instances of std::weak_ptr can point to objects owned by instances of std::shared_ptr while only becoming temporary owners themselves. This means that weak pointers do not alter the object's reference count and therefore do not prevent an object's deletion if all of the object's shared pointers are ...

Page 12 of 218