Tutorial by Examples: a

In PHP 5.3+ and above you can utilize late static binding to control which class a static property or method is called from. It was added to overcome the problem inherent with the self:: scope resolutor. Take the following code class Horse { public static function whatToSay() { echo ...
const auto input = "Some people, when confronted with a problem, think \"I know, I'll use regular expressions.\""s; smatch sm; cout << input << endl; // If input ends in a quotation that contains a word that begins with "reg" and another word begining...
This code takes in various brace styles and converts them to One True Brace Style: const auto input = "if (KnR)\n\tfoo();\nif (spaces) {\n foo();\n}\nif (allman)\n{\n\tfoo();\n}\nif (horstmann)\n{\tfoo();\n}\nif (pico)\n{\tfoo(); }\nif (whitesmiths)\n\t{\n\tfoo();\n\t}\n"s; cout &lt...
A std::regex_token_iterator provides a tremendous tool for extracting elements of a Comma Separated Value file. Aside from the advantages of iteration, this iterator is also able to capture escaped commas where other methods struggle: const auto input = "please split,this,csv, ,line,\\,\n&quot...
When processing of captures has to be done iteratively a regex_iterator is a good choice. Dereferencing a regex_iterator returns a match_result. This is great for conditional captures or captures which have interdependence. Let's say that we want to tokenize some C++ code. Given: enum TOKENS { ...
Single node Installation Pre-install NodeJS, Python and Java Select your installation document based on your platform http://docs.datastax.com/en/cassandra/3.x/cassandra/install/installTOC.html Download Cassandra binaries from http://cassandra.apache.org/download/ Untar the downloaded file to ...
db.people.insert({name: 'Tom', age: 28}); Or db.people.save({name: 'Tom', age: 28}); The difference with save is that if the passed document contains an _id field, if a document already exists with that _id it will be updated instead of being added as new. Two new methods to insert documents...
Update the entire object: db.people.update({name: 'Tom'}, {age: 29, name: 'Tom'}) // New in MongoDB 3.2 db.people.updateOne({name: 'Tom'},{age: 29, name: 'Tom'}) //Will replace only first matching document. db.people.updateMany({name: 'Tom'},{age: 29, name: 'Tom'}) //Will replace all matchin...
Query for all the docs in the people collection that have a name field with a value of 'Tom': db.people.find({name: 'Tom'}) Or just the first one: db.people.findOne({name: 'Tom'}) You can also specify which fields to return by passing a field selection parameter. The following will exclude t...
Object arrays are covariant, which means that just as Integer is a subclass of Number, Integer[] is a subclass of Number[]. This may seem intuitive, but can result in surprising behavior: Integer[] integerArray = {1, 2, 3}; Number[] numberArray = integerArray; // valid Number firstElement = numb...
Generators are useful when you need to generate a large collection to later iterate over. They're a simpler alternative to creating a class that implements an Iterator, which is often overkill. For example, consider the below function. function randomNumbers(int $length) { $array = []; ...
Our randomNumbers() function can be re-written to use a generator. <?php function randomNumbers(int $length) { for ($i = 0; $i < $length; $i++) { // yield tells the PHP interpreter that this value // should be the one used in the current iteration. yield mt...
One common use case for generators is reading a file from disk and iterating over its contents. Below is a class that allows you to iterate over a CSV file. The memory usage for this script is very predictable, and will not fluctuate depending on the size of the CSV file. <?php class CsvReade...
To be able to use JDBC you need to have the JDBC driver of your database on the class path of your application. There are multiple ways to connect to a database, but the common ways are to either use the java.sql.DriverManager, or to configure and use a database specific implementation of javax.sql...
The AppCompat Support Library defines several useful styles for Buttons, each of which extend a base Widget.AppCompat.Button style that is applied to all buttons by default if you are using an AppCompat theme. This style helps ensure that all buttons look the same by default following the Material D...
Atomic vectors (which excludes lists and expressions, which are also vectors) are subset using the [ operator: # create an example vector v1 <- c("a", "b", "c", "d") # select the third element v1[3] ## [1] "c" The [ operator can also tak...
For each dimension of an object, the [ operator takes one argument. Vectors have one dimension and take one argument. Matrices and data frames have two dimensions and take two arguments, given as [i, j] where i is the row and j is the column. Indexing starts at 1. ## a sample matrix mat <- matr...
Subsetting a data frame into a smaller data frame can be accomplished the same as subsetting a list. > df3 <- data.frame(x = 1:3, y = c("a", "b", "c"), stringsAsFactors = FALSE) > df3 ## x y ## 1 1 a ## 2 2 b ## 3 3 c > df3[1] # Subset a varia...
There are only two string operators: Concatenation of two strings (dot): $a = "a"; $b = "b"; $c = $a . $b; // $c => "ab" Concatenating assignment (dot=): $a = "a"; $a .= "b"; // $a => "ab"
$a = "some string"; results in $a having the value some string. The result of an assignment expression is the value being assigned. Note that a single equal sign = is NOT for comparison! $a = 3; $b = ($a = 5); does the following: Line 1 assigns 3 to $a. Line 2 assigns 5 to $a....

Page 168 of 1099