Tutorial by Examples: c

Wikipedia currently defines a pure function as follows: The function always evaluates the same result value given the same argument value(s). The function result value cannot depend on any hidden information or state that may change while program execution proceeds or between different executions...
Suppose we need to do the sum of each column in a dataset set.seed(20) df1 <- data.frame(ID = rep(c("A", "B", "C"), each = 3), V1 = rnorm(9), V2 = rnorm(9)) m1 <- as.matrix(df1[-1]) There are many ways to do this. Using base R, the best option would be col...
Suppose you have this type: data Person = Person { name :: String, age:: Int } deriving (Show, Eq) and two values: alex = Person { name = "Alex", age = 21 } jenny = Person { name = "Jenny", age = 36 } a new value of type Person can be created by copying from alex, specif...
import pandas as pd # Save dataframe to pickled pandas object df.to_pickle(file_name) # where to save it usually as a .plk # Load dataframe from pickled pandas object df= pd.read_pickle(file_name)
The foreach statement is used to loop through arrays. For each iteration the value of the current array element is assigned to $value variable and the array pointer is moved by one and in the next iteration next element will be processed. The following example displays the items in the array a...
The continue keyword halts the current iteration of a loop but does not terminate the loop. Just like the break statement the continue statement is situated inside the loop body. When executed, the continue statement causes execution to immediately jump to the loop conditional. In the followin...
Accepts a mathematical expression and returns a numerical value. It is especially useful when working with different types of units (e.g. subtracting a px value from a percentage) to calculate the value of an attribute. +, -, /, and * operators can all be used, and parentheses can be added to spec...
Returns the value of an attribute of the selected element. Below is a blockquote element which contains a character inside a data-* attribute which CSS can use (e.g. inside the ::before and ::after pseudo-element) using this function. <blockquote data-mark='"'></blockquote> I...
Using scenario you can perform validation on different situation Define scenario in model class class User extends \yii\db\ActiveRecord { public static function tableName() { return 'user_master'; } // define validation in rule() function public ...
Vector based graphics are represented by a plethora of data that must be computed by the CPU (vector points, arcs, colors, etc). Anything other than simple shapes with minimal points and straight lines will consume vast amounts of CPU resource. There is a "Cache as Bitmap" flag that can b...
Using the Vector.<T> type and the for each loop is more performant than a conventional array and for loop: Good: var list:Vector.<Sprite> = new <Sprite>[]; for each(var sprite:Sprite in list) { sprite.x += 1; } Bad: var list:Array = []; for (var i:int = 0; i < ...
Steps to Create component: Create a folder named components in your project root folder Create your component inside components folder e.g.: MyComponent.php namespace app\components; use Yii; use yii\base\Component; use yii\base\InvalidConfigException; class MyComponent ...
Create function in MyComponent.php namespace app\components; use Yii; use yii\base\Component; use yii\base\InvalidConfigException; use yii\helpers\Url; use yii\helpers\ArrayHelper; use app\models\User; class MyComponent extends Component ...
A session is usually obtained using sessionmaker, which creates a Session class unique to your application. Most commonly, the Session class is bound to an engine, allowing instances to use the engine implicitly. from sqlalchemy.orm import sessionmaker # Initial configuration arguments Session ...
New or detached objects may be added to the session using add(): session.add(obj) A sequence of objects may be added using add_all(): session.add_all([obj1, obj2, obj3]) An INSERT will be emitted to the database during the next flush, which happens automatically. Changes are persisted when t...
To delete persisted objects use delete(): session.delete(obj) Actual deletion from the database will happen on next flush.
Using ActiveCell or ActiveSheet can be source of mistakes if (for any reason) the code is executed in the wrong place. ActiveCell.Value = "Hello" 'will place "Hello" in the cell that is currently selected Cells(1, 1).Value = "Hello" 'will always place "Hello&...
Implementing the IEnumerable interface allows classes to be enumerated in the same way as BCL collections. This requires extending the Enumerator class which tracks the state of the enumeration. Other than iterating over a standard collection, examples include: Using ranges of numbers based on a...
So you've uploaded your files to a folder say /backend/web/uploads/ and you want these uploads to be visible on the frontend too. The easiest option is to create a symlink in the frontend that links to the backend: ln -s /path/to/backend/web/uploads/ /path/to/frontend/web/uploads In your views y...
The <algorithm> header provides a number of useful functions for working with sorted vectors. An important prerequisite for working with sorted vectors is that the stored values are comparable with <. An unsorted vector can be sorted by using the function std::sort(): std::vector<int&...

Page 168 of 826