Tutorial by Examples: any

One of the most elementary DCG nonterminals is ... //0, which can be read as "anything at all": ... --> [] | [_], ... . It can be used to describe a list Ls that contains the element E via: phrase(( ..., [E], ... ), Ls)
You can use all() to determine if all the values in an iterable evaluate to True nums = [1, 1, 0, 1] all(nums) # False chars = ['a', 'b', 'c', 'd'] all(chars) # True Likewise, any() determines if one or more values in an iterable evaluate to True nums = [1, 1, 0, 1] any(nums) # True val...
Problem # models.py: class Library(models.Model): name = models.CharField(max_length=100) books = models.ManyToManyField(Book) class Book(models.Model): title = models.CharField(max_length=100) # views.py def myview(request): # Query the database. libraries = Librar...
class Person(models.Model): name = models.CharField(max_length=50) description = models.TextField() class Club(models.Model): name = models.CharField(max_length=50) members = models.ManyToManyField(Person) Here we define a relationship where a club has many Persons and memb...
When implementing SFINAE using std::enable_if, it is often useful to have access to helper templates that determines if a given type T matches a set of criteria. To help us with that, the standard already provides two types analog to true and false which are std::true_type and std::false_type. The...
We use this model from the first example: class Person(models.Model): name = models.CharField(max_length=50) description = models.TextField() class Club(models.Model): name = models.CharField(max_length=50) members = models.ManyToManyField(Person) Add Tom and Bill to the N...

Any

When unsure of a type, any is available: let anything: any = 'I am a string'; anything = 5; // but now I am the number 5
Enums in Swift are much more powerful than some of their counterparts in other languages, such as C. They share many features with classes and structs, such as defining initialisers, computed properties, instance methods, protocol conformances and extensions. protocol ChangesDirection { mutati...
A has_many :through association is often used to set up a many-to-many connection with another model. This association indicates that the declaring model can be matched with zero or more instances of another model by proceeding through a third model. For example, consider a medical practice where p...
A has_and_belongs_to_many association creates a direct many-to-many connection with another model, with no intervening model. For example, if your application includes assemblies and parts, with each assembly having many parts and each part appearing in many assemblies, you could declare the models...
This bidirectional mapping requires the mappedBy attribute on the OneToMany association and the inversedBy attribute on the ManyToOne association. A bidirectional relationship has both an owning and inverse side. OneToMany relationships can use join tables, so you have to specify an owning side. Th...
(SelectMany, 1-m: The results of this mapping are “flattened”, just like LINQ’s SelectMany) TransformManyBlock<TInput, TOutput> is very similar to TransformBlock<TInput, TOutput>. The key difference is that whereas a TransformBlock<TInput, TOutput> produces one and only one outpu...
WITH cte AS ( SELECT ProjectID, ROW_NUMBER() OVER (PARTITION BY ProjectID ORDER BY InsertDate DESC) AS rn FROM ProjectNotes ) DELETE FROM cte WHERE rn > 1;
proc myproc args { ... } proc myproc {args} { ... } ;# equivalent If the special parameter name args is the last item in the argument list, it receives a list of all arguments at that point in the command line. If there are none, the list is empty. There can be arguments, including optional one...
'Trim the leading and trailing spaces in a string Const paddedText As String = " Foo Bar " Dim trimmedText As String trimmedText = Trim$(paddedText) 'trimmedText = "Foo Bar"
public function drawDisplayObjectUsingBounds(source:DisplayObject):BitmapData { var bitmapData:BitmapData;//declare a BitmapData var bounds:Rectangle = source.getBounds(source);//get the source object actual size //round bounds to integer pixel values (to aviod 1px str...
Preparation $ mkdir globbing $ cd globbing $ mkdir -p folder/{sub,another}folder/content/deepfolder/ touch macy stacy tracy "file with space" folder/{sub,another}folder/content/deepfolder/file .hiddenfile $ shopt -u nullglob $ shopt -u failglob $ shopt -u dotglob $ shopt -u nocaseg...
To get Array from any object, use Kernel#Array. The following is an example: Array('something') #=> ["something"] Array([2, 1, 5]) #=> [2, 1, 5] Array(1) #=> [1] Array(2..4) #=> [2, 3, 4] Array([]) #=> [] Array(nil) #=> [] For...
Suppose we want to read and stack a bunch of similarly-formatted files. The quick solution is: rbindlist(lapply(list.files(patt="csv$"), fread), id=TRUE) We might not be satisfied with this for a couple reasons: It might run into errors when reading with fread or when stacking with ...
XML <Goku> <child name="Gohan"/> <child name="Goten"/> </Goku> XPATH count(/Goku/child) OUTPUT 2.0

Page 2 of 6