/**
* @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;
}
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...
<?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...
By default, migrations are applied to the same database specified by the db application component. If you want them to be applied to a different database, you may specify the db command-line option like shown below:
yii migrate --db=db2
yii migrate
This command will list all migrations that have not been applied so far. If you confirm that you want to apply these migrations, it will run the up() or safeUp() method in every new migration class, one after another, in the order of their timestamp values. If any of the migrations fa...
SELECT *
FROM
table1,
table2
SELECT
table1.column1,
table1.column2,
table2.column1
FROM
table1,
table2
This is called cross product in SQL it is same as cross product in sets
These statements return the selected columns from multiple tables in one query....
Set memory limit and disable swap limit
docker run -it -m 300M --memory-swap -1 ubuntu:14.04 /bin/bash
Set both memory and swap limit. In this case, container can use 300M memory and 700M swap.
docker run -it -m 300M --memory-swap 1G ubuntu:14.04 /bin/bash
We can use Predefined Constants for Date format in date() instead of the conventional date format strings since PHP 5.1.0.
Predefined Date Format Constants Available
DATE_ATOM - Atom (2016-07-22T14:50:01+00:00)
DATE_COOKIE - HTTP Cookies (Friday, 22-Jul-16 14:50:01 UTC)
DATE_RSS - RSS (Fri, 22...
Installation Requirements
The minimum requirement by this project template is that your Web server supports PHP 5.4.0.
Yii2-advanced-app can be installed in two ways. They are
Installing via Composer
Installing from an Archive File
1) Installing via Composer
If you do not already have Comp...
Technically, autoloading works by executing a callback when a PHP class is required but not found. Such callbacks usually attempt to load these classes.
Generally, autoloading can be understood as the attempt to load PHP files (especially PHP class files, where a PHP source file is dedicated for a ...
In PHP, an anonymous function has its own scope like any other PHP function.
In JavaScript, an anonymous function can access a variable in outside scope. But in PHP, this is not permitted.
$name = 'John';
// Anonymous function trying access outside scope
$sayHello = function() {
return &q...
You can call a function in Racket by wrapping it in parentheses with the arguments after it. This looks like (function argument ...).
> (define (f x) x)
> (f 1)
1
> (f "salmon")
"salmon"
> (define (g x y) (string-append x y))
> (g "large" "sal...
The underscore _ may be used as a digit separator. Being able to group digits in large numeric literals has a significant impact on readability.
The underscore may occur anywhere in a numeric literal except as noted below. Different groupings may make sense in different scenarios or with different ...
Basics
A tuple is an ordered, finite list of elements. Tuples are commonly used in programming as a means to work with one single entity collectively instead of individually working with each of the tuple's elements, and to represent individual rows (ie. "records") in a relational databa...
Postconditions ensure that the returned results from a method will match the provided definition. This provides the caller with a definition of the expected result. Postconditions may allowed for simplied implmentations as some possible outcomes can be provided by the static analyizer.
Example......