Tutorial by Examples

Here is an example of a service that greets people by the given name, and keeps track of how many users it encountered. See usage below. %% greeter.erl %% Greets people and counts number of times it did so. -module(greeter). -behaviour(gen_server). %% Export API Functions -export([start_link/0...
It is possible to release dynamically allocated memory by calling free(). int *p = malloc(10 * sizeof *p); /* allocation of memory */ if (p == NULL) { perror("malloc failed"); return -1; } free(p); /* release of memory */ /* note that after free(p), even using the *value...
Standard Allocation The C dynamic memory allocation functions are defined in the <stdlib.h> header. If one wishes to allocate memory space for an object dynamically, the following code can be used: int *p = malloc(10 * sizeof *p); if (p == NULL) { perror("malloc() failed");...
In PHP, a fatal error is a kind of error that cannot be caught, that is, after experiencing a fatal error a program does not resume. However, to log this error or somehow handle the crash you can use register_shutdown_function to register shutdown handler. function fatalErrorHandler() { // Let...
If the variable contains a value of an immutable type (e.g. a string) then it is okay to assign a default value like this class Rectangle(object): def __init__(self, width, height, color='blue'): self.width = width self.height = height self.color = color d...
Whenever you attempt to retrieve a certain field from a class like so: $animal = new Animal(); $height = $animal->height; PHP invokes the magic method __get($name), with $name equal to "height" in this case. Writing to a class field like so: $animal->height = 10; Will invoke...
In Erlang, numbers are either integers or floats. Erlang uses arbitrary-precision for integers (bignums), so their values are limited only by the memory size of your system. 1> 11. 11 2> -44. -44 3> 0.1. 0.1 4> 5.1e-3. 0.0051 5> 5.2e2. 520.0 Numbers can be used in various...
An atom is an object with a name that is identified only by the name itself. Atoms are defined in Erlang using atom literals which are either an unquoted string that starts with a lowercase letter and contains only letters, digits, underscores or the @ character, or A single quoted string Ex...
A binary is a sequence of unsigned 8-bit bytes. 1> <<1,2,3,255>>. <<1,2,3,255>> 2> <<256,257,258>>. <<0,1,2>> 3> <<"hello","world">>. <<"helloworld">> A bitstring is a generalized ...
A tuple is a fixed length ordered sequence of other Erlang terms. Each element in the tuple can be any type of term (any data type). 1> {1, 2, 3}. {1,2,3} 2> {one, two, three}. {one,two,three} 3> {mix, atom, 123, {<<1,2>>, [list]}}. {mix,atom,123,{<<1,2>>,[list...
XSLT is a special-purpose programming language; it is widely used for transforming XML documents either into a different XML format, into HTML, or into text-based formats. There are two main versions of XSLT in use: XSLT 1.0 and XSLT 2.0. XSLT 1.0 is more widely implemented but has many restriction...
Migrations in a Laravel 5 application live in the database/migrations directory. Their filenames conform to a particular format: <year>_<month>_<day>_<hour><minute><second>_<name>.php One migration file should represent a schema update to solve a particu...
Creating a new migration file with the correct filename every time you need to change your schema would be a chore. Thankfully, Laravel's artisan command can generate the migration for you: php artisan make:migration add_last_logged_in_to_users_table You can also use the --table and --create fla...
Each migration should have an up() method and a down() method. The purpose of the up() method is to perform the required operations to put the database schema in its new state, and the purpose of the down() method is to reverse any operations performed by the up() method. Ensuring that the down() me...
Once your migration is written, running it will apply the operations to your database. php artisan migrate If all went well, you'll see an output similar to the below: Migrated: 2016_07_21_134310_add_last_logged_in_to_users_table Laravel is clever enough to know when you're running migration...
The following code creates a simple user interface containing a single Button that prints a String to the console on click. import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; import javafx.scene.contr...
.rds and .Rdata (also known as .rda) files can be used to store R objects in a format native to R. There are multiple advantages of saving this way when contrasted with non-native storage approaches, e.g. write.table: It is faster to restore the data to R It keeps R specific information encoded ...
We are going to be showing how to make a GET request to an API that responds with a JSON object or a JSON array. The first thing we need to do is add the Retrofit and GSON Converter dependencies to our module's gradle file. Add the dependencies for retrofit library as described in the Remarks secti...
Run-length encoding captures the lengths of runs of consecutive elements in a vector. Consider an example vector: dat <- c(1, 2, 2, 2, 3, 1, 4, 4, 1, 1) The rle function extracts each run and its length: r <- rle(dat) r # Run Length Encoding # lengths: int [1:6] 1 3 1 1 2 2 # valu...
One of the first questions people have when they begin to use PowerShell for scripting is how to manipulate the output from a cmdlet to perform another action. The pipeline symbol | is used at the end of a cmdlet to take the data it exports and feed it to the next cmdlet. A simple example is using...

Page 137 of 1336