Tutorial by Examples

Eloquent is the ORM built into the Laravel framework. It allows you to interact with your database tables in an object-oriented manner, by use of the ActiveRecord pattern. A single model class usually maps to a single database table, and also relationships of different types (one-to-one, one-to-man...
First, some terminology: argument (actual parameter): the actual variable being passed to a function; parameter (formal parameter): the receiving variable that is used in a function. In Python, arguments are passed by assignment (as opposed to other languages, where arguments can be passed by...
INSERT INTO `table_name` (`field_one`, `field_two`) VALUES ('value_one', 'value_two'); In this trivial example, table_name is where the data are to be added, field_one and field_two are fields to set data against, and value_one and value_two are the data to do against field_one and field_two resp...
INSERT INTO `table_name` (`index_field`, `other_field_1`, `other_field_2`) VALUES ('index_value', 'insert_value', 'other_value') ON DUPLICATE KEY UPDATE `other_field_1` = 'update_value', `other_field_2` = VALUES(`other_field_2`); This will INSERT into ta...
In Haskell, it often makes sense not to bother with file handles at all, but simply read or write an entire file straight from disk to memory†, and do all the partitioning/processing of the text with the pure string data structure. This avoids mixing IO and program logic, which can greatly help avoi...
Built-in Types Booleans bool: A boolean value of either True or False. Logical operations like and, or, not can be performed on booleans. x or y # if x is False then y otherwise x x and y # if x is False then x otherwise y not x # if x is True then False, otherwise True In Python 2...
String#split splits a String into an Array, based on a delimiter. "alpha,beta".split(",") # => ["alpha", "beta"] An empty String results into an empty Array: "".split(",") # => [] A non-matching delimiter results in an Array...
Array#join joins an Array into a String, based on a delimiter: ["alpha", "beta"].join(",") # => "alpha,beta" The delimiter is optional, and defaults to an empty String. ["alpha", "beta"].join # => "alphabeta" An em...
Merges two collections to create a distinct collection using the default equality comparer int[] numbers1 = { 1, 2, 3 }; int[] numbers2 = { 2, 3, 4, 5 }; var allElement = numbers1.Union(numbers2); // AllElement now contains 1,2,3,4,5 Live Demo on .NET Fiddle
The easiest way to create a multiline string is to just use multiple lines between quotation marks: address = "Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.&quot...
virtualenv is a tool to build isolated Python environments. This program creates a folder which contains all the necessary executables to use the packages that a Python project would need. Installing the virtualenv tool This is only required once. The virtualenv program may be available through yo...
Normally you would want to avoid using cursors as they can have negative impacts on performance. However in some special cases you may need to loop through your data record by record and perform some action. DECLARE @orderId AS INT -- here we are creating our cursor, as a local cursor and only a...
public class DatabaseHelper extends SQLiteOpenHelper { private static final String DATABASE_NAME = "Example.db"; private static final int DATABASE_VERSION = 3; // For all Primary Keys _id should be used as column name public static final String COLUMN_ID = "_id&q...
// You need a writable database to insert data final SQLiteDatabase database = openHelper.getWritableDatabase(); // Create a ContentValues instance which contains the data for each column // You do not need to specify a value for the PRIMARY KEY column. // Unique values for these are automatic...
A struct can be used to bundle multiple return values: C++11 struct foo_return_type { int add; int sub; int mul; int div; }; foo_return_type foo(int a, int b) { return {a + b, a - b, a * b, a / b}; } auto calc = foo(5, 12); C++11 Instead of assignment to indi...
A module is a file containing Python definitions and statements. Function is a piece of code which execute some logic. >>> pow(2,3) #8 To check the built in function in python we can use dir(). If called without an argument, return the names in the current scope. Else, return an alph...
If you've got a session which you wish to destroy, you can do this with session_destroy() /* Let us assume that our session looks like this: Array([firstname] => Jon, [id] => 123) We first need to start our session: */ session_start(); /* We can now remove all the v...
Just execute lsb_release -a. On Debian: $ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux testing (stretch) Release: testing Codename: stretch On Ubuntu: $ lsb_release -a No LSB modules are available. Distributor ID: Ubun...
The most common way to create a Symbol object is by prefixing the string identifier with a colon: :a_symbol # => :a_symbol :a_symbol.class # => Symbol Here are some alternative ways to define a Symbol, in combination with a String literal: :"a_symbol" "a_symbol&quot...
Given a String: s = "something" there are several ways to convert it to a Symbol: s.to_sym # => :something :"#{s}" # => :something

Page 110 of 1336