Tutorial by Examples: basic

Array is an ordered collection type in the Swift standard library. It provides O(1) random access and dynamic reallocation. Array is a generic type, so the type of values it contains are known at compile time. As Array is a value type, its mutability is defined by whether it is annotated as a var (...
When type is called with three arguments it behaves as the (meta)class it is, and creates a new instance, ie. it produces a new class/type. Dummy = type('OtherDummy', (), dict(x=1)) Dummy.__class__ # <type 'type'> Dummy().__class__.__class__ # <type 'type'> It is po...
Since PHP 5.0, PDO has been available as a database access layer. It is database agnostic, and so the following connection example code should work for any of its supported databases simply by changing the DSN. // First, create the database handle //Using MySQL (connection via local socket): $d...
For any iterable (for eg. a string, list, etc), Python allows you to slice and return a substring or sublist of its data. Format for slicing: iterable_name[start:stop:step] where, start is the first index of the slice. Defaults to 0 (the index of the first element) stop one past the last in...
Routes are defined in config/routes.rb. They are often defined as a group of related routes, using the resources or resource methods. resources :users creates the following seven routes, all mapping to actions of UsersController: get '/users', to: 'users#index' post '/users', ...
@media screen and (min-width: 720px) { body { background-color: skyblue; } } The above media query specifies two conditions: The page must be viewed on a normal screen (not a printed page, projector, etc). The width of the user's view port must be at least 720 pixels. I...
CREATE TABLE HR_EMPLOYEES ( PersonID int, LastName VARCHAR(30), FirstName VARCHAR(30), Position VARCHAR(30) ); CREATE TABLE FINANCE_EMPLOYEES ( PersonID INT, LastName VARCHAR(30), FirstName VARCHAR(30), Position VARCHAR(30) ); Let's say we want to ...
A simple function that does not accept any parameters and does not return any values: func SayHello() { fmt.Println("Hello!") }
A basic struct is declared as follows: type User struct { FirstName, LastName string Email string Age int } Each value is called a field. Fields are usually written one per line, with the field's name preceeding its type. Consecutive fields of the sa...
The function rand() can be used to generate a pseudo-random integer value between 0 and RAND_MAX (0 and RAND_MAX included). srand(int) is used to seed the pseudo-random number generator. Each time rand() is seeded wih the same seed, it must produce the same sequence of values. It should only be see...
Template literals are a special type of string literal that can be used instead of the standard '...' or "...". They are declared by quoting the string with backticks instead of the standard single or double quotes: `...`. Template literals can contain line breaks and arbitrary expression...
Inheritance in Python is based on similar ideas used in other object oriented languages like Java, C++ etc. A new class can be derived from an existing class as follows. class BaseClass(object): pass class DerivedClass(BaseClass): pass The BaseClass is the already existing (parent)...
Functions can be declared without parameters or a return value. The only required information is a name (hello in this case). func hello() { print("Hello World") } Call a function with no parameters by writing its name followed by an empty pair of parenthesis. hello() //output...
Defining a new protocol: @protocol NewProtocol - (void)protocolMethod:(id)argument; - (id)anotherMethod; @end
Data Manipulation Language (DML for short) includes operations such as INSERT, UPDATE and DELETE: -- Create a table HelloWorld CREATE TABLE HelloWorld ( Id INT IDENTITY, Description VARCHAR(1000) ) -- DML Operation INSERT, inserting a row into the table INSERT INTO HelloWorld (D...
The key to correctly stretching is in the top and left border. The top border controls horizontal stretching and the left border controls vertical stretching. This example creates rounded corners suitable for a Toast. The parts of the image that are below the top border and to the right of the ...
The Spinner can be reskinned according to your own style requirements using a Nine Patch. As an example, see this Nine Patch: As you can see, it has 3 extremely small areas of stretching marked. The top border has only left of the icon marked. That indicates that I want the left side (complete ...
An if statement checks whether a Bool condition is true: let num = 10 if num == 10 { // Code inside this block only executes if the condition was true. print("num is 10") } let condition = num == 10 // condition's type is Bool if condition { print("num is 10&...
The term "IFrame" means Inline Frame. It can be used to include another page in your page. This will yield a small frame which shows the exact contents of the base.html. <iframe src="base.html"></iframe>
A class is a user-defined type. A class is introduced with the class, struct or union keyword. In colloquial usage, the term "class" usually refers only to non-union classes. A class is a collection of class members, which can be: member variables (also called "fields"), mem...

Page 3 of 43