Tutorial by Examples: bas

About Protocols A Protocol specifies initialisers, properties, functions, subscripts and associated types required of a Swift object type (class, struct or enum) conforming to the protocol. In some languages similar ideas for requirement specifications of subsequent objects are known as ‘interfaces...
struct Repository { let identifier: Int let name: String var description: String? } This defines a Repository struct with three stored properties, an integer identifier, a string name, and an optional string description. The identifier and name are constants, as they've been decla...
A basic join (also called "inner join") queries data from two tables, with their relationship defined in a join clause. The following example will select employees' first names (FName) from the Employees table and the name of the department they work for (Name) from the Departments table:...
Closures (also known as blocks or lambdas) are pieces of code which can be stored and passed around within your program. let sayHi = { print("Hello") } // The type of sayHi is "() -> ()", aka "() -> Void" sayHi() // prints "Hello" Like other fun...
This a Basic example for using the MVVM model in a windows desktop application, using WPF and C#. The example code implements a simple "user info" dialog. The View The XAML <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> ...
str.split(sep=None, maxsplit=-1) str.split takes a string and returns a list of substrings of the original string. The behavior differs depending on whether the sep argument is provided or omitted. If sep isn't provided, or is None, then the splitting takes place wherever there is whitespace. Howe...
In the following example - Database for an auto shop business, we have a list of departments, employees, customers and customer cars. We are using foreign keys to create relationships between the various tables. Live example: SQL fiddle Relationships between tables Each Department may have 0 ...
Functions in Swift may return values, throw errors, or both: func reticulateSplines() // no return value and no error func reticulateSplines() -> Int // always returns a value func reticulateSplines() throws // no return value, but may throw an error func reticulat...
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 ...
Rebasing reapplies a series of commits on top of another commit. To rebase a branch, checkout the branch and then rebase it on top of another branch. git checkout topic git rebase master # rebase current branch onto master branch This would cause: A---B---C topic / D---E---F---G...
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...
var data = 'iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACN' + 'byblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHx' + 'gljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg=='; var characters = atob(data); var array = new Uint8Array(characters.length); for (var i = 0; i < characters.length; i++) { array[i] ...

Page 3 of 65