Tutorial by Examples

updateState by key can be used to create a stateful DStream based on upcoming data. It requires a function: object UpdateStateFunctions { def updateState(current: Seq[Double], previous: Option[StatCounter]) = { previous.map(s => s.merge(current)).orElse(Some(StatCounter(current))) } ...
mapWithState, similarly to updateState, can be used to create a stateful DStream based on upcoming data. It requires StateSpec: import org.apache.spark.streaming._ object StatefulStats { val state = StateSpec.function( (key: String, current: Option[Double], state: State[StatCounter]) =&g...
/** * @param n Number to be rounded. * @param precision Decimal places. * @return Rounded Number */ function roundDecimal(n:Number, precision:Number):Number { var factor:int = Math.pow(10, precision); return (Math.round(n * factor) / factor); } Examples: trace(0.9 - 1); // -0...
package { import flash.events.Event; public class CustomEvent extends Event { public static const START:String = "START"; public static const STOP:String = "STOP"; public var data:*; public function CustomEvent(type:Strin...
function meridiem(d:Date):String { return (d.hours > 11) ? "pm" : "am"; }
/** * @param year Full year as int (ex: 2000). * @param month Month as int, zero-based (ex: 0=January, 11=December). */ function daysInMonth(year:int, month:int):int { return (new Date(year, ++month, 0)).date; }
function isLeapYear(year:int):Boolean { return daysInMonth(year, 1) == 29; }
function isDaylightSavings(d:Date):Boolean { var months:uint = 12; var offset:uint = d.timezoneOffset; var offsetCheck:Number; while (months--) { offsetCheck = (new Date(d.getFullYear(), months, 1)).timezoneOffset; if (offsetCheck != offset) ret...
function today(date:Date = null):Date { if (date == null) date = new Date(); return new Date(date.fullYear, date.month, date.date, 0, 0, 0, 0); }
The simplest case is just preforming a task for a fixed known number of times. Say we want to display the numbers between 1 to n, we can write: n = 5; for k = 1:n display(k) end The loop will execute the inner statement(s), everything between the for and the end, for n times (5 in this ex...
The right-hand side of the assignment in a for loop can be any row vector. The left-hand side of the assignment can be any valid variable name. The for loop assigns a different element of this vector to the variable each run. other_row_vector = [4, 3, 5, 1, 2]; for any_name = other_row_vector ...
If the right-hand side of the assignment is a matrix, then in each iteration the variable is assigned subsequent columns of this matrix. some_matrix = [1, 2, 3; 4, 5, 6]; % 2 by 3 matrix for some_column = some_matrix display(some_column) end (The row vector version is a normal case of thi...
yii migrate/create <name> The required name argument gives a brief description about the new migration. For example, if the migration is about creating a new table named news, you may use the name create_news_table and run the following command yii migrate/create create_news_table
<?php use yii\db\Migration; class m150101_185401_create_news_table extends Migration { public function up() { } public function down() { echo "m101129_185401_create_news_table cannot be reverted.\n"; return false; } /* // Use safeUp/safeDown to run migra...
public function up() { $this->dropTable('post'); }
yii migrate/create create_post_table --fields="title:string,body:text" Generates: /** * Handles the creation for table `post`. */ class m150811_220037_create_post_table extends Migration { /** * @inheritdoc */ public function up() { $this->createTable('post', [ ...
public function up() { $this->createTable('post', [ 'id' => $this->primaryKey() ]); }
public function up() { $this->dropColumn('post', 'position'); $this->renameColumn('post', 'owner_id', 'user_id'); $this->alterColumn('post', 'updated', $this->timestamp()->notNull()->defaultValue('0000-00-00 00:00:00')); }
public function up() { $this->addColumn('post', 'position', $this->integer()); }
yii migrate/down # revert the most recently applied migration yii migrate/down 3 # revert the most 3 recently applied migrations

Page 236 of 1336