Tutorial by Examples

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 ...
Runtime errors in JavaScript are instances of the Error object. The Error object can also be used as-is, or as the base for user-defined exceptions. It's possible to throw any type of value - for example, strings - but you're strongly encouraged to use Error or one of it's derivatives to ensure that...
Assuming a single source file named main.cpp, the command to compile and link an non-optimized executable is as follows (Compiling without optimization is useful for initial development and debugging, although -Og is officially recommended for newer GCC versions). g++ -o app -Wall main.cpp -O0 T...
Browse to File > New > Solution to bring you up the new project dialog Select Single View App and press Next Configure your app by setting your app name and organization ID, and press Next: Set your Project name and Solution name, or leave as the default name. Click Create to create...
The most basic use of a float is having text wrap around an image. The below code will produce two paragraphs and an image, with the second paragraph flowing around the image. Notice that it is always content after the floated element that flows around the floated element. HTML: <p>Lorem ips...
A simple two-column layout consists of two fixed-width, floated elements. Note that the sidebar and content area are not the same height in this example. This is one of the tricky parts with multi-column layouts using floats, and requires workarounds to make multiple columns appear to be the same he...
Events fired on DOM elements don't just affect the element they're targeting. Any of the target's ancestors in the DOM may also have a chance to react to the event. Consider the following document: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> </hea...
GHC's OverloadedLists extension allows you to construct list-like data structures with the list literal syntax. This allows you to Data.Map like this: > :set -XOverloadedLists > import qualified Data.Map as M > M.lookup "foo" [("foo", 1), ("bar", 2)] Just ...
a = 1 - Math.abs(1 - a % 2); // This will throw an error if my arithmetic above is wrong. assert a >= 0 && a <= 1 : "Calculated value of " + a + " is outside of expected bounds"; return a;
This downloads a file from the Dropbox API at the remote path /Homework/math/Prime_Numbers.txt to the local path Prime_Numbers.txt in the current folder: curl -X POST https://content.dropboxapi.com/2/files/download \ --header "Authorization: Bearer <ACCESS_TOKEN>" \ --head...
Adapted from the tutorial, this uses the SwiftyDropbox library to download a file, with a progress callback on the download method to get progress information: // Download a file let destination : (NSURL, NSHTTPURLResponse) -> NSURL = { temporaryURL, response in let fileManager = NSFileMan...
This uses the Dropbox Python SDK to download a file from the Dropbox API at the remote path /Homework/math/Prime_Numbers.txt to the local file Prime_Numbers.txt: import dropbox dbx = dropbox.Dropbox("<ACCESS_TOKEN>") with open("Prime_Numbers.txt", "wb") as f:...
Dropbox.authorizedClient!.files.download(path: path, destination: destination).response { response, error in if let (metadata, url) = response { print("*** Download file ***") print("Downloaded file name: \(metadata.name)") print("Downloaded f...
#include <stdio.h> #include <curl/curl.h> int main (int argc, char *argv[]) { CURL *curl; CURLcode res; /* In windows, this will init the winsock stuff */ curl_global_init(CURL_GLOBAL_ALL); /* get a curl handle */ curl = curl_easy_init()...
This downloads just a piece of a file, using Range Retrieval Requests, from the Dropbox API at the remote path /Homework/math/Prime_Numbers.txt to the local path Prime_Numbers.txt.partial in the current folder: curl -X GET https://content.dropboxapi.com/2/files/download \ --header "Auth...
<?php $path = 'test_php_upload.txt'; $fp = fopen($path, 'rb'); $size = filesize($path); $cheaders = array('Authorization: Bearer <ACCESS_TOKEN>', 'Content-Type: application/octet-stream', 'Dropbox-API-Arg: {"path":"/test/'.$path.'...
#include <stdio.h> #include <curl/curl.h> int main (int argc, char *argv[]) { CURL *curl; CURLcode res; /* In windows, this will init the winsock stuff */ curl_global_init(CURL_GLOBAL_ALL); /* get a curl handle */ curl = curl_easy_init()...
This uploads a file from the local path matrices.txt in the current folder to /Homework/math/Matrices.txt in the Dropbox account, and returns the metadata for the uploaded file: echo "some content here" > matrices.txt curl -X POST https://content.dropboxapi.com/2/files/upload \ ...
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...
This example uses the Dropbox .NET library to upload a file to a Dropbox account, using upload sessions for larger files: private async Task Upload(string localPath, string remotePath) { const int ChunkSize = 4096 * 1024; using (var fileStream = File.Open(localPath, FileMode.Open)) ...

Page 49 of 1336