Tutorial by Examples

The following example demonstrates a simple HTTP GET request. http.get() returns an Observable which has the method subscribe. This one appends the returned data to the posts array. var posts = [] getPosts(http: Http):void { this.http.get(`https://jsonplaceholder.typicode.com/posts`) ...
It may be a good idea to encapsulate the HTTP handling logic in its own class. The following class exposes a method for getting Posts. It calls the http.get() method and calls .map on the returned Observable to convert the Response object to a Post object. import {Injectable} from "@angular/co...
One common scenario is to wait for a number of requests to finish before continuing. This can be accomplished using the forkJoin method. In the following example, forkJoin is used to call two methods that return Observables. The callback specified in the .subscribe method will be called when both O...
The first step in accessing a data source via ADO is creating an ADO Connection object. This is typically done using a connection string to specify the data source parameters, although it is also possible to open a DSN connection by passing the DSN, user ID, and password to the .Open method. Note t...
Queries can be performed in two ways, both of which return an ADO Recordset object which is a collection of returned rows. Note that both of the examples below use the OpenDatabaseConnection function from the Making a connection to a data source example for the purpose of brevity. Remember that the...
ADO connections can be used to perform pretty much any database function that the provider supports via SQL. In this case it isn't always necessary to use the Recordset returned by the Execute function, although it can be useful for obtaining key assignments after INSERT statements with @@Identity o...
Any time SQL executed through an ADO connection needs to contain user input, it is considered best practice to parameterize it in order to minimize the chance of SQL injection. This method is also more readable than long concatenations and facilitates more robust and maintainable code (i.e. by using...
The following example utilizes the tm text mining package to scrape and mine text data from the web to build word clouds with symbolic shading and ordering. require(RWeka) require(tau) require(tm) require(tm.plugin.webmining) require(wordcloud) # Scrape Google Finance -----------------------...
Const string1 As String = "foo" Const string2 As String = "bar" Const string3 As String = "fizz" Dim concatenatedString As String 'Concatenate two strings concatenatedString = string1 & string2 'concatenatedString = "foobar" 'Concatenate three s...
'Declare and assign a string array Dim widgetNames(2) As String widgetNames(0) = "foo" widgetNames(1) = "bar" widgetNames(2) = "fizz" 'Concatenate with Join and separate each element with a 3-character string concatenatedString = VBA.Strings.Join(widgetNames, &q...
Python uses internal caching for a range of integers to reduce unnecessary overhead from their repeated creation. In effect, this can lead to confusing behavior when comparing integer identities: >>> -8 is (-7 - 1) False >>> -3 is (-2 - 1) True and, using another example: ...
Dim lineOfHyphens As String 'Assign a string with 80 repeated hyphens lineOfHyphens = String$(80, "-")
Dim stringOfSpaces As String 'Assign a string with 255 repeated spaces using Space$ stringOfSpaces = Space$(255) 'Assign a string with 255 repeated spaces using String$ stringOfSpaces = String$(255, " ")
The purpose of this example is to show how we can realize the Strategy pattern using Java 8 functional interfaces. We will start with a simple use case codes in classic Java, and then recode it in the Java 8 way. The example problem we using is a family of algorithms (strategies) that describe dif...
from module.submodule import function This imports function from module.submodule.
To generate documentation in HTML format from @doc and @moduledoc attributes in your source code, add ex_doc and a markdown processor, right now ExDoc supports Earmark, Pandoc, Hoedown and Cmark, as dependencies into your mix.exs file: # config/mix.exs def deps do [{:ex_doc, "~> 0.11&...
from datetime import timedelta from django.utils import timezone from psycopg2.extras import DateTimeTZRange # To create a "period" object we will use psycopg2's DateTimeTZRange # which takes the two datetime bounds as arguments period_start = timezone.now() period_end = period_s...
Use assert_raise to test if an exception was raised. assert_raise takes in an Exception and a function to be executed. test "invalid block size" do assert_raise(MerkleTree.ArgumentError, (fn() -> MerkleTree.new ["a", "b", "c"] end)) end Wrap a...
import Session Class use yii\web\Session; Create a session $session = Yii::$app->session; $session->open(); // open a session $session->close(); // close a session Store the value in session variable. $session = Yii::$app->session; $session->set('name', 'stack'); OR ...
# lib/mix/tasks/mytask.ex defmodule Mix.Tasks.MyTask do use Mix.Task @shortdoc "A simple mix task" def run(_) do IO.puts "YO!" end end Compile and run: $ mix compile $ mix my_task "YO!"

Page 476 of 1336