Tutorial by Examples

The return type of a method can depend on the type of the parameter. In this example, x is the parameter, A is the type of x, which is known as the type parameter. def f[A](x: A): A = x f(1) // 1 f("two") // "two" f[Float](3) // 3.0F Scala will use type infe...
// Create a block with an asynchronous action var block = new ActionBlock<string>(async hostName => { IPAddress[] ipAddresses = await Dns.GetHostAddressesAsync(hostName); Console.WriteLine(ipAddresses[0]); }); block.Post("google.com"); // Post items to the block's ...
var httpClient = new HttpClient(); // Create a block the accepts a uri and returns its contents as a string var downloaderBlock = new TransformBlock<string, string>( async uri => await httpClient.GetStringAsync(uri)); // Create a block that accepts the content and prints it to t...
jQuery makes handling jSON responses painless, but a bit more work is required when a given request wishes you to send data in JSON format: $.ajax("/json-consuming-route", { data: JSON.stringify({author: {name: "Bullwinkle J. Moose", ...
If you have several objects of monadic types, we can achieve combinations of the values using a 'for comprehension': for { x <- Option(1) y <- Option("b") z <- List(3, 4) } { // Now we can use the x, y, z variables println(x, y, z) x // the last expre...
There are two Dockerfile directives to specify what command to run by default in built images. If you only specify CMD then docker will run that command using the default ENTRYPOINT, which is /bin/sh -c. You can override either or both the entrypoint and/or the command when you start up the built im...
Requirements: 64-bit version of Windows 7 or higher on a machine which supports Hardware Virtualization Technology, and it is enabled. While the docker binary can run natively on Windows, to build and host containers you need to run a Linux virtual machine on the box. 1.12.0 Since version 1.12 y...
Docker is supported on the following 64-bit versions of Ubuntu Linux: Ubuntu Xenial 16.04 (LTS) Ubuntu Wily 15.10 Ubuntu Trusty 14.04 (LTS) Ubuntu Precise 12.04 (LTS) A couple of notes: The following instructions involve installation using Docker packages only, and this ensures obtaining...
The typical way to begin writing webservers in golang is to use the standard library net/http module. There is also a tutorial for it here. The following code also uses it. Here is the simplest possible HTTP server implementation. It responds "Hello World" to any HTTP request. Save the...
HandleFunc registers the handler function for the given pattern in the server mux (router). You can pass define an anonymous function, as we have seen in the basic Hello World example: http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "Hello, w...
The simplest way to create an error is by using the errors package. errors.New("this is an error") If you want to add additional information to an error, the fmt package also provides a useful error creation method: var f float64 fmt.Errorf("error with some additional informatio...
In Go, an error is represented by any value that can describe itself as string. Any type that implement the built-in error interface is an error. // The error interface is represented by a single // Error() method, that returns a string representation of the error type error interface { Erro...
In Go you don't raise an error. Instead, you return an error in case of failure. // This method can fail func DoSomething() error { // functionThatReportsOK is a side-effecting function that reports its // state as a boolean. NOTE: this is not a good practice, so this example // tur...
In Go errors can be returned from a function call. The convention is that if a method can fail, the last returned argument is an error. func DoAndReturnSomething() (string, error) { if os.Getenv("ERROR") == "1" { return "", errors.New("The method fai...
Any Chrome extension starts as an unpacked extension: a folder containing the extension's files. One file it must contain is manifest.json, which describes the basic properties of the extension. Many of the properties in that file are optional, but here is an absolute minimum manifest.json file: ...
The getAll() method retrieves all values from the preferences. We can use it, for instance, to log the current content of the SharedPreferences: private static final String PREFS_FILE = "MyPrefs"; public static void logSharedPreferences(final Context context) { SharedPreferences s...
/// <summary> /// This interface can do Foo /// </summary> public interface ICanDoFoo { // ... } /// <summary> /// This Bar class implements ICanDoFoo interface /// </summary> public class Bar : ICanDoFoo { // ... } Result Interface summary Clas...
Yii2 can be installed in two ways. They are Installing via Composer Installing from an Archive File Installing via Composer Installing Composer If you do not already have Composer installed, you may do so by following the instructions at getcomposer.org. On Linux and Mac OS X, you'll run th...
Use pip to install Flask in a virtualenv. pip install flask Step by step instructions for creating a virtualenv for your project: mkdir project && cd project python3 -m venv env # or `virtualenv env` for Python 2 source env/bin/activate pip install flask Never use sudo pip in...
Rename the branch you have checked out: git branch -m new_branch_name Rename another branch: git branch -m branch_you_want_to_rename new_branch_name

Page 102 of 1336