Tutorial by Examples: ee

It is now a best-practice to use Vector instead of List because the implementations have better performance Performance characteristics can be found here. Vector can be used wherever List is used. List creation List[Int]() // Declares an empty list of type Int List.empty[Int] // U...
Note that this deals with the creation of a collection of type Map, which is distinct from the map method. Map Creation Map[String, Int]() val m1: Map[String, Int] = Map() val m2: String Map Int = Map() A map can be considered a collection of tuples for most operations, where the first e...
Files: - example.rs (root of our modules tree, generally named lib.rs or main.rs when using Cargo) - first.rs - second/ - mod.rs - sub.rs Modules: - example -> example - first -> example::first - second -> example::second - sub -> exampl...
This example is a snippet taken from the Extending Django User Profile like a Pro from django.db import models from django.contrib.auth.models import User from django.db.models.signals import post_save class UserProfile(models.Model): user = models.OneToOneField(User, related_name='user'...
RoboGuice is a framework that brings the simplicity and ease of Dependency Injection to Android, using Google's own Guice library. @ContentView(R.layout.main) class RoboWay extends RoboActivity { @InjectView(R.id.name) TextView name; @InjectView(R.id.thumbnail) Image...
The UIAlertController available since iOS8 allows you to use the same alert object for either Action sheets or more classic alerts. The only difference is the UIAlertControllerStyle passed as a parameter when creating. This line changes from an AlertView to an ActionSheet, compared to some other ex...
Use unpacking to extract the first element and ensure it's the only one: a, = iterable def foo(): yield 1 a, = foo() # a = 1 nums = [1, 2, 3] a, = nums # ValueError: too many values to unpack
def gen(): yield 1 iterable = gen() for a in iterable: print a # What was the first item of iterable? No way to get it now. # Only to get a new iterator gen()
For Python, Guido van Rossum based the grouping of statements on indentation. The reasons for this are explained in the first section of the "Design and History Python FAQ". Colons, :, are used to declare an indented code block, such as the following example: class ExampleClass: #Eve...
When you are copying a string into a malloced buffer, always remember to add 1 to strlen. char *dest = malloc(strlen(src)); /* WRONG */ char *dest = malloc(strlen(src) + 1); /* RIGHT */ strcpy(dest, src); This is because strlen does not include the trailing \0 in the length. If you take the ...
A programming best practice is to free any memory that has been allocated directly by your own code, or implicitly by calling an internal or external function, such as a library API like strdup(). Failing to free memory can introduce a memory leak, which could accumulate into a substantial amount of...
Following is most basic expression tree that is created by lambda. Expression<Func<int, bool>> lambda = num => num == 42; To create expression trees 'by hand', one should use Expression class. Expression above would be equivalent to: ParameterExpression parameter = Expression.Pa...
5.1 JavaScript does not directly support enumerators but the functionality of an enum can be mimicked. // Prevent the enum from being changed const TestEnum = Object.freeze({ One:1, Two:2, Three:3 }); // Define a variable with a value from the enum var x = TestEnum.Two; // Prin...
For example, if t1 is currently not an InnoDB table, this statement changes its storage engine to InnoDB: ALTER TABLE t1 ENGINE = InnoDB; If the table is already InnoDB, this will rebuild the table and its indexes and have an effect similar to OPTIMIZE TABLE. You may gain some disk space improv...
A tree basically represents a folder in a traditional filesystem: nested containers for files or other folders. A tree contains: 0 or more blob objects 0 or more tree objects Just as you can use ls or dir to list the contents of a folder, you can list the contents of a tree object. $ git ca...
The intrinsic pack function packs an array into a vector, selecting elements based on a given mask. The function has two forms PACK(array, mask) PACK(array, mask, vector) (that is, the vector argument is optional). In both cases array is an array, and mask of logical type and conformable with...
This feeds a while loop with the output of a grep command: while IFS=":" read -r user _ do # "$user" holds the username in /etc/passwd done < <(grep "hello" /etc/passwd)
Through the use of event types you can easily reduce code bloat that often occurs when defining events for many objects on stage by filtering events in 1 function rather than defining many event handling functions. Imagine we have 10 objects on stage named object1, object2 ... object10 You could d...
Consider the following C# code Expression<Func<int, int>> expression = a => a + 1; Because the C# compiler sees that the lambda expression is assigned to an Expression type rather than a delegate type it generates an expression tree roughly equivalent to this code ParameterExpres...
Here is a program that calls malloc but not free: #include <stdio.h> #include <stdlib.h> int main(int argc, char **argv) { char *s; s = malloc(26); // the culprint return 0; } With no extra arguments, valgrind will not look for this error. But if we turn on...

Page 12 of 54