Tutorial by Examples: l

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...
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...
A list can be subset with [: l1 <- list(c(1, 2, 3), 'two' = c("a", "b", "c"), list(10, 20)) l1 ## [[1]] ## [1] 1 2 3 ## ## $two ## [1] "a" "b" "c" ## ## [[3]] ## [[3]][[1]] ## [1] 10 ## ## [[3]][[2]] ## [1] 20 l1[1] ##...
The order in which operators are evaluated is determined by the operator precedence (see also the Remarks section). In $a = 2 * 3 + 4; $a gets a value of 10 because 2 * 3 is evaluated first (multiplication has a higher precedence than addition) yielding a sub-result of 6 + 4, which equals to 10...
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
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...
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...
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(), ...
This query returns all cones with either a mint scoop or a vanilla scoop. minty_vanilla_cones = IceCream.objects.filter(scoops__contained_by=[MINT, VANILLA])
In order to define a Set of your own type you need to conform your type to Hashable struct Starship: Hashable { let name: String var hashValue: Int { return name.hashValue } } func ==(left:Starship, right: Starship) -> Bool { return left.name == right.name } Now you can cr...
Create a Loader object: var loader:Loader = new Loader(); //import Add listeners on the loader. Standard ones are complete and io/security errors loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete); //when the loader is done loading, call this function loader.co...
Twilio help build apps that communicate with everyone in the world. Voice & Video, Messaging and Authentication APIs for every application. You can get an API key for free. To send a message through Twilio, your application needs to make an HTTP POST request to Twilio with the following things...
A yield statement is similar to a return statement, except that instead of stopping execution of the function and returning, yield instead returns a Generator object and pauses execution of the generator function. Here is an example of the range function, written as a generator: function gen_one_t...
pip install sqlalchemy For most common applications, particularly web applications, it is usually recommended that beginners consider using a supplementary library, such as flask-sqlalchemy. pip install flask-sqlalchemy

Page 129 of 861