Tutorial by Examples: ai

The remainder / modulus operator (%) returns the remainder after (integer) division. console.log( 42 % 10); // 2 console.log( 42 % -10); // 2 console.log(-42 % 10); // -2 console.log(-42 % -10); // -2 console.log(-40 % 10); // -0 console.log( 40 % 10); // 0 This operator returns th...
Place this code in a file named HelloWorld.scala: object Hello { def main(args: Array[String]): Unit = { println("Hello World!") } } Live demo To compile it to bytecode that is executable by the JVM: $ scalac HelloWorld.scala To run it: $ scala Hello When the Scala...
This example assumes Ruby and Ruby on Rails have already been installed properly. If not, you can find how to do it here. Open up a command line or terminal. To generate a new rails application, use rails new command followed by the name of your application: $ rails new my_app If you want to c...
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...
var re = /[a-z]+/; if (re.test("foo")) { console.log("Match exists."); } The test method performs a search to see if a regular expression matches a string. The regular expression [a-z]+ will search for one or more lowercase letters. Since the pattern matches the string,...
You can compare multiple items with multiple comparison operators with chain comparison. For example x > y > z is just a short form of: x > y and y > z This will evaluate to True only if both comparisons are True. The general form is a OP b OP c OP d ... Where OP represents ...
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 &quot...
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...
class MyClass { func sayHi() { print("Hello") } deinit { print("Goodbye") } } When a closure captures a reference type (a class instance), it holds a strong reference by default: let closure: () -> Void do { let obj = MyClass() // Captures a strong re...
The following snippet encodes the data stored in d into JSON and stores it in a file (replace filename with the actual name of the file). import json d = { 'foo': 'bar', 'alice': 1, 'wonderland': [1, 2, 3] } with open(filename, 'w') as f: json.dump(d, f)
One of the most commonly used events is waiting for the document to have loaded, including both script files and images. The load event on document is used for this. document.addEventListener('load', function() { console.log("Everything has now loaded!"); }); Sometimes you try to ...
The <main> element contains the main content for your web page. This content is unique to the individual page, and should not appear elsewhere on the site. Repeating content like headers, footers, navigation, logos, etc., is placed outside the element. The <main> element should only e...
It is possible to emulate container types, which support accessing values by key or index. Consider this naive implementation of a sparse list, which stores only its non-zero elements to conserve memory. class sparselist(object): def __init__(self, size): self.size = size se...
Jsoup can be used to extract links and email address from a webpage, thus "Web email address collector bot" First, this code uses a Regular expression to extract the email addresses, and then uses methods provided by Jsoup to extract the URLs of links on the page. public class JSoupTest {...
You can filter what routes are available using constraints. There are several ways to use constraints including: segment constraints, request based constraints advanced constraints For example, a requested based constraint to only allow a specific IP address to access a route: constraints(...
Right after you install Git, the first thing you should do is set your username and email address. From a shell, type: git config --global user.name "Mr. Bean" git config --global user.email [email protected] git config is the command to get or set options --global means that the ...
Dropbox.authorizedClient!.files.getMetadata(path: "/test.jpg", includeMediaInfo: true).response { response, error in if let result = response as? Files.FileMetadata { print(result.name) if result.mediaInfo != nil { switch result.mediaInfo! as Files.Med...
curl -X POST https://api.dropboxapi.com/2/files/get_metadata \ --header "Authorization: Bearer <ACCESS_TOKEN>" \ --header "Content-Type: application/json" \ --data "{\"path\": \"/test.jpg\",\"include_media_info\": true}&quot...
git reset <filePath>
In order to begin building with PayPal APIs, you have to create an application to obtain a client ID and secret. Go to https://developer.paypal.com/developer/applications/, sign in, and click on "Create App", as shown below: Next, enter an application name, select the sandbox testing a...

Page 2 of 47