Tutorial by Examples

${#array[@]} gives the length of the array ${array[@]}: array=('first element' 'second element' 'third element') echo "${#array[@]}" # gives out a length of 3 This works also with Strings in single elements: echo "${#array[0]}" # gives out the lenght of the string at ele...
The function is_array() returns true if a variable is an array. $integer = 1337; $array = [1337, 42]; is_array($integer); // false is_array($array); // true You can type hint the array type in a function to enforce a parameter type; passing anything else will result in a fatal error. funct...
Content has been moved back to good 'ol JSP wiki page
slice1 := []string{"!"} slice2 := []string{"Hello", "world"} slice := append(slice1, slice2...) Run in the Go Playground
foo = 1 bar = 'bar' baz = 3.14 You can use str.format to format output. Bracket pairs are replaced with arguments in the order in which the arguments are passed: print('{}, {} and {}'.format(foo, bar, baz)) # Out: "1, bar and 3.14" Indexes can also be specified inside the bracket...
This Makefile will cross compile and zip up executables for Windows, Mac and Linux (ARM and x86). # Replace demo with your desired executable name appname := demo sources := $(wildcard *.go) build = GOOS=$(1) GOARCH=$(2) go build -o build/$(appname)$(3) tar = cd build && tar -cvzf $...
From your project directory, run the go build command and specify the operating system and architecture target with the GOOS and GOARCH environment variables: Compiling for Mac (64-bit): GOOS=darwin GOARCH=amd64 go build Compiling for Windows x86 processor: GOOS=windows GOARCH=386 go build ...
A while loop executes statements repeatedly until the given condition evaluates to false. This control statement is used when it is not known, in advance, how many times a block of code is to be executed. For example, to print all the numbers from 0 up to 9, the following code can be used: int i =...
Case statements can be combined with if expressions to provide extra logic when pattern matching. def checkSign(x: Int): String = { x match { case a if a < 0 => s"$a is a negative number" case b if b > 0 => s"$b is a positive number" case c ...
This type of Singleton is thread safe, and prevents unnecessary locking after the Singleton instance has been created. Java SE 5 public class MySingleton { // instance of class private static volatile MySingleton instance = null; // Private constructor private MySingleton()...
A namespace declaration can look as follows: namespace MyProject; - Declare the namespace MyProject namespace MyProject\Security\Cryptography; - Declare a nested namespace namespace MyProject { ... } - Declare a namespace with enclosing brackets. It is recommended to only declare a single na...
As shown in Declaring Namespaces, we can define a class in a namespace as follows: namespace MyProject\Shapes; class Rectangle { ... } To reference this class the full path (including the namespace) needs to be used: $rectangle = new MyProject\Shapes\Rectangle(); This can be shortened by ...
You can split a String on a particular delimiting character or a Regular Expression, you can use the String.split() method that has the following signature: public String[] split(String regex) Note that delimiting character or regular expression gets removed from the resulting String Array. Exa...
Using the Reflection API, it is possible to change or get the value of a field at runtime. For example, you could use it in an API to retrieve different fields based on a factor, like the OS. You can also remove modifiers like final to allow modifing fields that are final. To do so, you will need t...
.htaccess files (or "distributed configuration files") provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all su...
Install .NET Core on macOS 10.11+, after install homebrew: brew update brew install openssl mkdir -p /usr/local/lib ln -s /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib /usr/local/lib/ ln -s /usr/local/opt/openssl/lib/libssl.1.0.0.dylib /usr/local/lib/ Install .NET Core SDK from https://go...
When defining discriminated unions you can name elements of tuple types and use these names during pattern matching. type Shape = | Circle of diameter:int | Rectangle of width:int * height:int let shapeIsTenWide = function | Circle(diameter=10) | Rectangle(width=10) -> t...
To use Vagrant on Windows platform you need to install virtualization software and an ssh command-line tool first. This example will use freeware VirtualBox and Cygwin. Install VirtualBox Download the latest VirtualBox version from the official download page and run the downloaded file. Note that ...
Clicking the Select an element in the page to inspect it button in the upper left corner of the Elements tab in Chrome or Inspector tab in Firefox, available from Developer Tools, and then clicking on a element of the page highlights the element and assigns it to the $0 variable. Elements inspecto...
5 <input type="date" /> A date picker will pop up on screen for you to choose a date. This is not supported in Firefox or Internet Explorer.

Page 124 of 1336