Tutorial by Examples: al

lst = ['a', 'b', 'c', 'd', 'e'] lst[2:4] # Output: ['c', 'd'] lst[2:] # Output: ['c', 'd', 'e'] lst[:4] # Output: ['a', 'b', 'c', 'd']
Java-like enumerations can be created by extending Enumeration. object WeekDays extends Enumeration { val Mon, Tue, Wed, Thu, Fri, Sat, Sun = Value } def isWeekend(day: WeekDays.Value): Boolean = day match { case WeekDays.Sat | WeekDays.Sun => true case _ => false } isWeekend...
An alternative to extending Enumeration is using sealed case objects: sealed trait WeekDay object WeekDay { case object Mon extends WeekDay case object Tue extends WeekDay case object Wed extends WeekDay case object Thu extends WeekDay case object Fri extends WeekDay case objec...
To avoid verbose null checking, the ?. operator has been introduced in the language. The old verbose syntax: If myObject IsNot Nothing AndAlso myObject.Value >= 10 Then Can be now replaced by the concise: If myObject?.Value >= 10 Then The ? operator is particularly powerful when you...
Swift let alert = UIAlertController(title: "Hello", message: "Welcome to the world of iOS", preferredStyle: UIAlertControllerStyle.alert) let defaultAction = UIAlertAction(title: "OK", style: UIAlertActionS...
Dim array() As Integer = {2, 0, 1, 6} ''Initialize an array of four Integers. Dim strings() As String = {"this", "is", "an", "array"} ''Initialize an array of four Strings. Dim floats() As Single = {56.2, 55.633, 1.2, 5.7743, 22.345} ...
With UIAlertController, action sheets like the deprecated UIActionSheet are created with the same API as you use for AlertViews. Simple Action Sheet with two buttons Swift let alertController = UIAlertController(title: "Demo", message: "A demo with two buttons", preferredStyle...
The java.math.BigInteger class provides operations analogues to all of Java's primitive integer operators and for all relevant methods from java.lang.Math. As the java.math package is not automatically made available you may have to import java.math.BigInteger before you can use the simple class nam...
Post::find()->all(); // SELECT * FROM post or the shorthand (Returns an active record model instance by a primary key or an array of column values.) Post::findAll(condition); returns an array of ActiveRecord instances. Find All with where Condition $model = User::find() ->w...
<?php namespace models; use yii\db\ActiveRecord; use yii\behaviors\TimestampBehavior; class Post extends ActiveRecord { public static function tableName() { return 'post'; } public function rules() { ...
The second value in the curly braces dictates the length of the replacement string. By adjusting the second value to be positive or negative, the alignment of the string can be changed. string.Format("LEFT: string: ->{0,-5}<- int: ->{1,-5}<-", "abc", 123); string....
If value types are assigned to variables of type object they are boxed - the value is stored in an instance of a System.Object. This can lead to unintended consequences when comparing values with ==, e.g.: object left = (int)1; // int in an object box object right = (int)1; // int in an object bo...
Boxed value types can only be unboxed into their original Type, even if a conversion of the two Types is valid, e.g.: object boxedInt = (int)1; // int boxed in an object long unboxedInt1 = (long)boxedInt; // invalid cast This can be avoided by first unboxing into the original Type, e.g.: lon...
Examples below are given in Ruby, but same matchers should be available in any modern language. Let’s say we have the string "AℵNaïve", produced by Messy Artificial Intelligence. It consists of letters, but generic \w matcher won’t match much: ▶ "AℵNaïve"[/\w+/] #⇒ "A&q...
It is worth noting that in swift, unlike other languages people are familiar with, there is an implicit break at the end of each case statement. In order to follow through to the next case (i.e. have multiple cases execute) you need to use fallthrough statement. switch(value) { case 'one': //...
ALTER TABLE Employees ALTER COLUMN StartingDate DATETIME NOT NULL DEFAULT (GETDATE()) This query will alter the column datatype of StartingDate and change it from simple date to datetime and set default to current date.
In Python 2, an octal literal could be defined as >>> 0755 # only Python 2 To ensure cross-compatibility, use 0o755 # both Python 2 and Python 3
NSString *filePath = [[NSFileManager defaultManager] pathForRessorce: @"data" ofType:@"txt"]; NSData *data = [NSData dataWithContentsOfFile:filePath]; int len = [data length];
This guide assumes you already have Ruby installed. If you're using Ruby < 1.9 you'll have to manually install RubyGems as it won't be included natively. To install a ruby gem, enter the command: gem install [gemname] If you are working on a project with a list of gem dependencies, then the...
To generate true random values that can be used for cryptography std::random_device has to be used as generator. #include <iostream> #include <random> int main() { std::random_device crypto_random_generator; std::uniform_int_distribution<int> int_distribution(0,9); ...

Page 38 of 269