Tutorial by Examples

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...
println("Hello, World!") To run Julia, first get the interpreter from the website’s download page. The current stable release is v0.5.0, and this version is recommended for most users. Certain package developers or power users may choose to use the nightly build, which is far less stabl...
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...
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 type std::tuple can bundle any number of values, potentially including values of different types, into a single return object: std::tuple<int, int, int, int> foo(int a, int b) { // or auto (C++14) return std::make_tuple(a + b, a - b, a * b, a / b); } In C++17, a braced init...
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...
Use std::string::substr to split a string. There are two variants of this member function. The first takes a starting position from which the returned substring should begin. The starting position must be valid in the range (0, str.length()]: std::string str = "Hello foo, bar and world!"...
Replace by position To replace a portion of a std::string you can use the method replace from std::string. replace has a lot of useful overloads: //Define string std::string str = "Hello foo, bar and world!"; std::string alternate = "Hello foobar"; //1) str.replace(6, 3,...
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...
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...
var fs = require('fs'); // Save the string "Hello world!" in a file called "hello.txt" in // the directory "/tmp" using the default encoding (utf8). // This operation will be completed in background and the callback // will be called when it is either done or fail...
Use the filesystem module for all file operations: const fs = require('fs'); With Encoding In this example, read hello.txt from the directory /tmp. This operation will be completed in the background and the callback occurs on completion or failure: fs.readFile('/tmp/hello.txt', { encoding: '...
const fs = require('fs'); // Read the contents of the directory /usr/local/bin asynchronously. // The callback will be invoked once the operation has either completed // or failed. fs.readdir('/usr/local/bin', (err, files) => { // On error, show it and return if(err) return console.er...
Display a message to the output console. Using SQL Server Management Studio, this will be displayed in the messages tab, rather than the results tab: PRINT 'Hello World!';
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...
project/jni/main.c #include <stdio.h> #include <unistd.h> int main(void) { printf("Hello world!\n"); return 0; } project/jni/Android.mk LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := hello_world LOCAL_SRC_FILES := main.c include $(BU...

Page 59 of 1336