PHP can be used to add content to HTML files. While HTML is processed directly by a web browser, PHP scripts are executed by a web server and the resulting HTML is sent to the browser.
The following HTML markup contains a PHP statement that will add Hello World! to the output:
<!DOCTYPE html>...
In some cases, when working with a web server, overriding the web server's default content type may be required. There may be cases where you need to send data as plain text, JSON, or XML, for example.
The header() function can send a raw HTTP header. You can add the Content-Type header to notify t...
Alternatively, you can use the Interactive Ruby Shell (IRB) to immediately execute the Ruby statements you previously wrote in the Ruby file.
Start an IRB session by typing:
$ irb
Then enter the following command:
puts "Hello World"
This results in the following console output (in...
Functions can return a value that you can use directly:
def give_me_five():
return 5
print(give_me_five()) # Print the returned value
# Out: 5
or save the value for later use:
num = give_me_five()
print(num) # Print the saved returned value
# Out: 5
or use the value f...
The then method of a promise returns a new promise.
const promise = new Promise(resolve => setTimeout(resolve, 5000));
promise
// 5 seconds later
.then(() => 2)
// returning a value from a then callback will cause
// the new promise to resolve with this value
.then...
Assuming you set the upstream (as in the "setting an upstream repository")
git fetch remote-name
git merge remote-name/branch-name
The pull command combines a fetch and a merge.
git pull
The pull with --rebase flag command combines a fetch and a rebase instead of merge.
git pull ...
Instead of importing the complete module you can import only specified names:
from random import randint # Syntax "from MODULENAME import NAME1[, NAME2[, ...]]"
print(randint(1, 10)) # Out: 5
from random is needed, because the python interpreter has to know from which resource it...
#include <stdio.h>
enum Op
{
ADD = '+',
SUB = '-',
};
/* add: add a and b, return result */
int add(int a, int b)
{
return a + b;
}
/* sub: subtract b from a, return result */
int sub(int a, int b)
{
return a - b;
}
/* getmath: return the appropriate m...
from module_name import *
for example:
from math import *
sqrt(2) # instead of math.sqrt(2)
ceil(2.7) # instead of math.ceil(2.7)
This will import all names defined in the math module into the global namespace, other than names that begin with an underscore (which indicates that the wri...
The Promise.all() static method accepts an iterable (e.g. an Array) of promises and returns a new promise, which resolves when all promises in the iterable have resolved, or rejects if at least one of the promises in the iterable have rejected.
// wait "millis" ms, then resolve with "...
The Promise.race() static method accepts an iterable of Promises and returns a new Promise which resolves or rejects as soon as the first of the promises in the iterable has resolved or rejected.
// wait "milliseconds" milliseconds, then resolve with "value"
function resolve(va...
def input_number(msg, err_msg=None):
while True:
try:
return float(raw_input(msg))
except ValueError:
if err_msg is not None:
print(err_msg)
def input_number(msg, err_msg=None):
while True:
try:
return ...
The following snippet opens a JSON encoded file (replace filename with the actual name of the file) and returns the object that is stored in the file.
import json
with open(filename, 'r') as f:
d = json.load(f)
6
Exceptions are to synchronous code what rejections are to promise-based asynchronous code. If an exception is thrown in a promise handler, its error will be automatically caught and used to reject the promise instead.
Promise.resolve(5)
.then(result => {
throw new Error("I ...
This uses the SwiftyDropbox library to upload a file from a NSData to the Dropbox account, using upload sessions for larger files, handling every error case:
import UIKit
import SwiftyDropbox
class ViewController: UIViewController {
// replace this made up data with the real data
le...