Tutorial by Examples: at

Factorials can be computed at compile-time using template metaprogramming techniques. #include <iostream> template<unsigned int n> struct factorial { enum { value = n * factorial<n - 1>::value }; }; template<> struct factorial<0> { ...
In MATLAB, the most basic data type is the numeric array. It can be a scalar, a 1-D vector, a 2-D matrix, or an N-D multidimensional array. % a 1-by-1 scalar value x = 1; To create a row vector, enter the elements inside brackets, separated by spaces or commas: % a 1-by-4 row vector v = [1, 2...
The Implicit Grant flow is best suited for Web applications. It's easily integrated into a website using JavaScript and doesn't require a server to store the authorization code to retrieve a token. You'll first send the user to the Twitch authorization endpoint. This URL is made up of a the base au...
The second step to creating a subscription for a user is to create and execute a billing agreement, based on an existing activated billing plan. This example assumes that you have already gone through and activated a billing plan in the previous example, and have an ID for that billing plan to refer...
When creating a subscription for a user, you first need to create and activate a billing plan that a user is then subscribed to using a billing agreement. The full process for creating a subscription is detailed in the remarks of this topic. Within this example, we're going to be using the PayPal N...
HTML comments can be used to leave notes to yourself or other developers about a specific point in code. They can be initiated with <!-- and concluded with -->, like so: <!-- I'm an HTML comment! --> They can be incorporated inline within other content: <h1>This part will be d...
// This creates an array with 5 values. const int array[] = { 1, 2, 3, 4, 5 }; #ifdef BEFORE_CPP11 // You can use `sizeof` to determine how many elements are in an array. const int* first = array; const int* afterLast = first + sizeof(array) / sizeof(array[0]); // Then you can iterate ov...
An if statement checks whether a Bool condition is true: let num = 10 if num == 10 { // Code inside this block only executes if the condition was true. print("num is 10") } let condition = num == 10 // condition's type is Bool if condition { print("num is 10&...
By default, a Date object is created as local time. This is not always desirable, for example when communicating a date between a server and a client that do not reside in the same timezone. In this scenario, one doesn't want to worry about timezones at all until the date needs to be displayed in lo...
A very simple way to import data from many common file formats is with rio. This package provides a function import() that wraps many commonly used data import functions, thereby providing a standard interface. It works simply by passing a file name or URL to import(): import("example.csv&quot...
Java SE 7 As the try-catch-final statement example illustrates, resource cleanup using a finally clause requires a significant amount of "boiler-plate" code to implement the edge-cases correctly. Java 7 provides a much simpler way to deal with this problem in the form of the try-with-res...
Employ the EAFP coding style and try to open it. import errno try: with open(path) as f: # File exists except IOError as e: # Raise the exception if it is not ENOENT (No such file or directory) if e.errno != errno.ENOENT: raise # No such file or directory ...
Convert to String var date1 = new Date(); date1.toString(); Returns: "Fri Apr 15 2016 07:48:48 GMT-0400 (Eastern Daylight Time)" Convert to Time String var date1 = new Date(); date1.toTimeString(); Returns: "07:48:48 GMT-0400 (Eastern Daylight Time)" Conve...
The and-operator (&&) and the or-operator (||) employ short-circuiting to prevent unnecessary work if the outcome of the operation does not change with the extra work. In x && y, y will not be evaluated if x evaluates to false, because the whole expression is guaranteed to be false....
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...
The $_SESSION variable is an array, and you can retrieve or manipulate it like a normal array. <?php // Starting the session session_start(); // Storing the value in session $_SESSION['id'] = 342; // conditional usage of session values that may have been set in a previous session if(!i...
You can concatenate std::strings using the overloaded + and += operators. Using the + operator: std::string hello = "Hello"; std::string world = "world"; std::string helloworld = hello + world; // "Helloworld" Using the += operator: std::string hello = "Hel...
Use Case CASE can be used in conjunction with SUM to return a count of only those items matching a pre-defined condition. (This is similar to COUNTIF in Excel.) The trick is to return binary results indicating matches, so the "1"s returned for matching entries can be summed for a count o...
in myapp/context_processors.py: from django.conf import settings def debug(request): return {'DEBUG': settings.DEBUG} in settings.py: TEMPLATES = [ { ... 'OPTIONS': { 'context_processors': [ ... 'myapp.context_processor...

Page 15 of 442