Tutorial by Examples

Touch event handler for surfaces (e.g. SurfaceView, GLSurfaceView, and others): import android.app.Activity; import android.os.Bundle; import android.view.MotionEvent; import android.view.SurfaceView; import android.view.View; public class ExampleClass extends Activity implements View.OnTouc...
public class CustomSurfaceView extends SurfaceView { @Override public boolean onTouchEvent(MotionEvent e) { super.onTouchEvent(e); if(e.getPointerCount() > 2){ return false; // If we want to limit the amount of pointers, we return false //...
A splash screen is just like any other activity, but it can handle all of your startup-needs in the background. Example: Manifest: <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="...
There is more than one way to do it: Using the package manager: sudo apt install perl Installing from source: wget http://www.cpan.org/src/5.0/perl-version.tar.gz tar -xzf perl-version.tar.gz cd perl-version ./Configure -de make make test make install Installing in your $h...
There are several options: Perlbrew: # You need to install Command Line Tools for Xcode curl -L https://install.perlbrew.pl | bash Perlbrew with thread support: # You need to install Command Line Tools for Xcode curl -L https://install.perlbrew.pl | bash After the install of p...
As we said before, we go with the open-source version. For Windows you can choose strawberry or DWIM. Here we cover the strawberry version, since DWIM is based on it. The easy way here is installing from the official executable. See also berrybrew - the perlbrew for Windows Strawberry Perl
NLTK provides the FreqDist class that let's us easily calculate a frequency distribution given a list as input. Here we are using a list of part of speech tags (POS tags) to see which lexical categories are used the most in the brown corpus. import nltk brown_tagged = nltk.corpus.brown.tagged_w...
A function is defined by at least its return type and an unique name. void say_hello () { print ("Hello, world!\n"); } Then, to call it just use the name of the function followed by a parenthese. say_hello (); Functions can also have parameters between the parentheses, d...
Parameters can be marked as optional by giving them a default value. Optional parameters can be omitted when calling the function. string greet (string name, string language = "English") { if (language == "English") { return @"Hello, $name!"; } else ...
Value types (structures and enumerations) are passed by value to functions: a copy will be given to the function, not a reference to the variable. So the following function won't do anything. void add_three (int x) { x += 3; } int a = 39; add_three (a); assert (a == 39); // a is still 39...
You can assert that parameters have certain values with requires. int fib (int i) requires (i > 0) { if (i == 1) { return i; } else { return fib (i - 1) + fib (i - 2); } } fib (-1); You won't get any error during the compilation, but you'll get an error wh...
int sum (int x, ...) { int result = x; va_list list = va_list (); for (int? y = list.arg<int?> (); y != null; y = list.arg<int?> ()) { result += y; } return result; } int a = sum (1, 2, 3, 36); With this function, you can pass as many int as you w...
A key part of the Reader monad is the ask (https://hackage.haskell.org/package/mtl-2.2.1/docs/Control-Monad-Reader.html#v:ask) function, which is defined for illustrative purposes: import Control.Monad.Trans.Reader hiding (ask) import Control.Monad.Trans ask :: Monad m => ReaderT r m r ask ...
This is an official MATLAB example Consider the following code: month = [1;1;2;3;8;1;3;4;9;11;9;12;3;4;11]; temperature = [57;61;60;62;45;59;64;66;40;56;38;65;61;64;55]; maxTemp = accumarray(month,temperature,[],@max); The image below demonstrates the computation process done by accumarray in...
A discriminant of a record type may influence the structure of objects. A choice of components may exists in an object according as a discriminant had had a particular value when the object was created. To support this variation, a record type's definition includes a distinction by cases that depend...
Generic subprograms are usefull to create a subprograms that have the same structure for several types. For example, to swap two objects: generic type A_Type is private; procedure Swap (Left, Right : in out A_Type) is Temp : A_Type := Left; begin Left := Right; Right := Temp; ...
In Ada generic package, upon instantiation, data are duplicated; that is, if they contain global variables, each instance will have its own copy of the variable, properly typed and independent from the others. generic type T is private; package Gen is type C is tagged record V :...
Ada offers a wide variety of generic parameters which is difficult to translate into other languages. The parameters used during instantiation and as a consequence those on which the generic unit may rely on may be variables, types, subprograms, or package instances, with certain properties. For exa...
These exceptions are caused when the type of some object should be different TypeError: [definition/method] takes ? positional arguments but ? was given A function or method was called with more (or less) arguments than the ones it can accept. Example If more arguments are given: def foo(a): re...
Let's see all the basic component for create a simple Hallo World. Define which implementation of JPA 2.1 we will use Build the connection to database creating the persistence-unit Implements the entities Implements DAO (Data access object) for manipulate the entities Test the application ...

Page 1170 of 1336