Tutorial by Examples

Left association If the preceedence of two operators is equal, the associativity determines the grouping (see also the Remarks section): $a = 5 * 3 % 2; // $a now is (5 * 3) % 2 => (15 % 2) => 1 * and % have equal precedence and left associativity. Because the multiplication occurs first ...
Simple check To check if constant is defined use the defined function. Note that this function doesn't care about constant's value, it only cares if the constant exists or not. Even if the value of the constant is null or false the function will still return true. <?php define("GOOD&quo...
Constants are created using the const statement or the define function. The convention is to use UPPERCASE letters for constant names. Define constant using explicit values const PI = 3.14; // float define("EARTH_IS_FLAT", false); // boolean const "UNKNOWN" = null; // null d...
Filter code: angular.module('myModule', []).filter('multiplier', function() { return function(number, multiplier) { if (!angular.isNumber(number)) { throw new Error(number + " is not a number!"); } if (!multiplier) { multiplier = 2; } return numbe...
If you want to include PHP code in your HTML file and you don't want to rename the file type from .html or .htm to .php, the below allows your HTML file to parse your PHP code correctly. AddHandler application/x-httpd-php .html .htm
An idiomatic technique for generating repeating code structures at compile time. An X-macro consists of two parts: the list, and the execution of the list. Example: #define LIST \ X(dog) \ X(cat) \ X(racoon) // class Animal { // public: // void say(); // }; #define...
404 responses are returned when a resource is not found on the server, in Symfony this status can be created by throwing a NotFoundHttpException exception. To avoid an extra use statement inside a controller use the createNotFoundException() provided by the Controller class <?php namespace Bu...
Implementing IErrorHandler for WCF services is a great way to centralize error handling and logging. The implementation shown here should catch any unhandled exception that is thrown as a result of a call to one of your WCF services. Also shown in this example is how to return a custom object, and h...
To assert that a value is either true or false,: Assert.IsFalse(Settings.DoBadThings, "Bad things should not happen, disable DoBadThings."); Assert.IsTrue(magicNumber =< 42, "The magic number is greater than 42!"); You can also pass formatting parameters for the exception...
ResultNotNull() checks to see if the object passed in is not null. If the object and message are not null it will then simply return the object that was passed in, otherwise it will throw InvalidOperationException. return Assert.ResultNotNull(this.Database.GetItem(this.ItemRootId), string.Concat(&q...
This checks to see if the given object is null, and then throws RequiredObjectIsNullException if it is. Assert.Required(parameter, "parameter is required.");
IsNotNull This is a very simple and popular method to use to check if an item is not null. It simply checks the object that is passed in to see if it is null. Assert.IsNotNull(database, type, "Name: {0}", item); IsNotNullOrEmpty This is the same as IsNotNull above, but works on strin...
ArgumentCondition This method checks to see if the argument specified is true. It also takes in the name of the argument that is logged if the condition fails. Assert.ArgumentCondition(pageIndex >= 0, "pageIndex", "Value must be greater than or equal to zero."); ArgumentN...
Checks to see if the passed Item is in Editing mode. If not, it throws an EditingNotAllowedException. Assert.IsEditing(Sitecore.Context.Item);
CanRunApplication To check to see if the user has permission to run the given application. If not, AccessDeniedException is thrown. Assert.CanRunApplication("WebEdit"); HasAccess HasAccess will check if the given parameter is true, otherwise an AccessDeniedException will be thrown. ...
When writing a class with generics in java, it is possible to ensure that the type parameter is an enum. Since all enums extend the Enum class, the following syntax may be used. public class Holder<T extends Enum<T>> { public final T value; public Holder(T init) { t...
To create a PostgreSQL ArrayField, we should give ArrayField the type of data we want it to store as a field as its first argument. Since we'll be storing book ratings, we will use FloatField. from django.db import models, FloatField from django.contrib.postgres.fields import ArrayField cla...
from django.db import models, IntegerField from django.contrib.postgres.fields import ArrayField class IceCream(models.Model): scoops = ArrayField(IntegerField() # we'll use numbers to ID the scoops , size=6) # our parlor only lets you have 6 scoops When you us...
This query returns all cones with a chocolate scoop and a vanilla scoop. VANILLA, CHOCOLATE, MINT, STRAWBERRY = 1, 2, 3, 4 # constants for flavors choco_vanilla_cones = IceCream.objects.filter(scoops__contains=[CHOCOLATE, VANILLA]) Don't forget to import the IceCream model from your models.py ...
You can nest ArrayFields by passing another ArrayField as it's base_field. from django.db import models, IntegerField from django.contrib.postgres.fields import ArrayField class SudokuBoard(models.Model): numbers = ArrayField( ArrayField( models.IntegerField(), ...

Page 206 of 1336