Tutorial by Examples: c

// gets the Class objects from the net.mminecraft.server package with the given name public Class<?> getNmsClass(String name) throws ClassNotFoundException { // explode the Server interface implementation's package name into its components String[] packageArray = Bukkit.getServer()....
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="...
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...
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...
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...
Getting elements to center or bottom align vertically has always been a challenge with CSS and Bootstrap. The desired vertical alignment may be within a parent container, or relative to adjacent elements. Now that Bootstrap 4 is flexbox by default there are many different approaches to vertical ali...
This example shows a simple but effective splash screen with animation that can be created by using Android Studio. Step 1: Create an animation Create a new directory named anim in the res directory. Right-click it and create a new Animation Resource file named fade_in.xml: Then, put the follow...
This example shows how to define sub-commands for a given command, and how to easily associate a command handler. This example defines a thing command with get and set subcommands. package things; import io.dropwizard.cli.Command; import io.dropwizard.setup.Bootstrap; import net.sourceforge.a...
An example project (Git repo) that can be used as a starting point for doing some 3D rendering. The code for setting up OpenGL and the shaders is quite long and tedious so it wont fit well under this example format. Later pieces of it can be shown in separate examples detailing what exactly is going...
You can see the running demo by clicking here. HTML: <p> <span>Counter State</span><br /> (<em>Will increase each minute</em>): <p> <span id="counter-state" style="font-weight: bolder"></span> </p> &l...
Active Record Transactions can be applied to Model classes as well as Model instances, the objects within the transaction block need not all be instances of same class. This is because transactions are per-database connection, not per-model. For example: User.transaction do account.save! prof...
Using Oracle SQL’s NVL2() function, you can create a display column which contains one value if a field contains data and another value if a field does not contain data. For example, in an Entity search, turn the presence of a primary e-mail address into a text display column: NVL2( {email} , 'YES...
Below is a single hidden layer Multilayer Perceptron (MLP) using nested scoping of variables. def weight_variable(shape): return tf.get_variable(name="weights", shape=shape, initializer=tf.zeros_initializer(dtype=tf.float32)) def bias_variable(shape): ...

Page 726 of 826