Tutorial by Examples

Payments Table CustomerPayment_typeAmountPeterCredit100PeterCredit300JohnCredit1000JohnDebit500 select customer, sum(case when payment_type = 'credit' then amount else 0 end) as credit, sum(case when payment_type = 'debit' then amount else 0 end) as debit from payments group by ...
If you need to remove one or more elements from a slice, or if you need to work with a sub slice of another existing one; you can use the following method. Following examples uses slice of int, but that works with all type of slice. So for that, we need a slice, from witch we will remove some ...
Maps in go are not safe for concurrency. You must take a lock to read and write on them if you will be accessing them concurrently. Usually the best option is to use sync.RWMutex because you can have read and write locks. However, a sync.Mutex could also be used. type RWMap struct { sync.RWMut...
Doctrine 2 is easy to install via composer composer require doctrine/orm but it can also be downloaded from http://www.doctrine-project.org/projects/orm.html or from its GitHub project page.
ActionScript 3 can be used by installing the Adobe AIR SDK or Apache Flex SDK or as part Adobe's Animate CC product (formerly known as Flash Professional). Adobe Animate CC is a professional software solution that can be used to create AS3 projects using visual tools - once installed, no further st...
Classes have 3 types of methods: instance, singleton and class methods. Instance Methods These are methods that can be called from an instance of the class. class Thing def somemethod puts "something" end end foo = Thing.new # create an instance of the class foo.somemeth...

For

for($i = 0; $i -le 5; $i++){ "$i" } A typical use of the for loop is to operate on a subset of the values in an array. In most cases, if you want to iterate all values in an array, consider using a foreach statement.
ForEach has two different meanings in PowerShell. One is a keyword and the other is an alias for the ForEach-Object cmdlet. The former is described here. This example demonstrates printing all items in an array to the console host: $Names = @('Amy', 'Bob', 'Celine', 'David') ForEach ($Name in $...
A while loop will evaluate a condition and if true will perform an action. As long as the condition evaluates to true the action will continue to be performed. while(condition){ code_block } The following example creates a loop that will count down from 10 to 0 $i = 10 while($i -ge 0){ ...
A command shell is a command line interface computer program to an operating system. Some Variants 1. Bash : Comes as default shell on ubuntu 2. KornShell(ksh) : To install ksh in Ubuntu $ sudo apt-get install ksh To start working with ksh $ ksh $ ps $$ PID TTY STAT ...
Detailed instructions on getting UWP set up or installed. Requirements Windows 10 Visual Studio 2015 Steps Download and custom install Visual Studio 2015, while making sure that Universal Windows App Development Toolsis selected along with its sub options:- a) Tools and Windows SDK b...
A custom extraction can be written by implementing the unapply method and returning a value of type Option: class Foo(val x: String) object Foo { def unapply(foo: Foo): Option[String] = Some(foo.x) } new Foo("42") match { case Foo(x) => x } // "42" The retur...
Java provides several ways to copy an array. for loop int[] a = { 4, 1, 3, 2 }; int[] b = new int[a.length]; for (int i = 0; i < a.length; i++) { b[i] = a[i]; } Note that using this option with an Object array instead of primitive array will fill the copy with reference to the origi...
Example: Get a Stream of 30 elements, containing 21st to 50th (inclusive) element of a collection. final long n = 20L; // the number of elements to skip final long maxSize = 30L; // the number of elements the stream should be limited to final Stream<T> slice = collection.stream().skip(n).li...
Variable declaration for examples: Collection<String> abc = Arrays.asList("a", "b", "c"); Collection<String> digits = Arrays.asList("1", "2", "3"); Collection<String> greekAbc = Arrays.asList("alpha", "be...
Hash has a default value for keys that are requested but don't exist (nil): a = {} p a[ :b ] # => nil When creating a new Hash, one can specify the default: b = Hash.new 'puppy' p b[ :b ] # => 'puppy' Hash.new also takes a block, which allows you to automatically create n...
Two Arrays var array1 = [1, 2]; var array2 = [3, 4, 5]; 3 var array3 = array1.concat(array2); // returns a new array 6 var array3 = [...array1, ...array2] Results in a new Array: [1, 2, 3, 4, 5] Multiple Arrays var array1 = ["a", "b"], array2 = ["...
Unshift Use .unshift to add one or more items in the beginning of an array. For example: var array = [3, 4, 5, 6]; array.unshift(1, 2); array results in: [1, 2, 3, 4, 5, 6] Push Further .push is used to add items after the last currently existent item. For example: var array = [1, 2, 3...
var object = { key1: 10, key2: 3, key3: 40, key4: 20 }; var array = []; for(var people in object) { array.push([people, object[people]]); } Now array is [ ["key1", 10], ["key2", 3], ["key3", 40], ["key4", 20] ] ...
Given the following array var array = [ ["key1", 10], ["key2", 3], ["key3", 40], ["key4", 20] ]; You can sort it sort it by number(second index) array.sort(function(a, b) { return a[1] - b[1]; }) 6 array.sort((a,b) => a[1] - b[1]);...

Page 129 of 1336