Tutorial by Examples: c

Simple example Assuming that the "HelloWorld.java" contains the following Java source: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello world!"); } } (For an explanation of the above code, please refer to Gettin...
Setting up an instance To use Realm you first need to obtain an instance of it. Each Realm instance maps to a file on disk. The most basic way to get an instance is as follows: // Create configuration RealmConfiguration realmConfiguration = new RealmConfiguration.Builder(context).build(); // O...
Prolog tries alternative clauses for a predicate in the order of appearance: likes(alice, music). likes(bob, hiking). // Either alice likes music, or bob likes hiking will succeed. The disjunction (OR) operator ; can be used to express this in one rule: likes(P,Q) :- ( P = alice , Q = ...
Conjunction (logical AND) is represented by the comma , operator (among other roles). Conjunction between clauses can appear in a query: ?- X = 1, Y = 2. Conjunction can also appear between the subgoal clauses in the body of a rule: triangleSides(X,Y,Z) :- X + Y > Z, X + Z > Y, Y + ...
Sometimes it is desirable to prevent Prolog from backtracking into alternative solutions. The basic tool available to the programmer to stop prolog from continuing futher in its backtrack is the cut operator. consider the following. % (percent signs mean comments) % a is the parent of b, c, and d....
ObjectAnimator is a subclass of ValueAnimator with the added ability to set the calculated value to the property of a target View. Just like in the ValueAnimator, there are two ways you can create the ObjectAnimator: (the example code animates an alpha of a View from 0.4f to 0.2f in 250ms) Fr...
As Rebar3 is free, open source and written in Erlang, it's possible to simply clone and build it from the source code. $ git clone https://github.com/erlang/rebar3.git $ cd rebar3 $ ./bootstrap This will create the rebar3 script, which you can put on your PATH or link to /usr/local/bin as expl...
To bootstrap a new Erlang project, simply choose the template you want to use from the list. The available templates can be retrieved by the following command: $ rebar3 new app (built-in): Complete OTP Application structure cmake (built-in): Standalone Makefile for building C/C++ in c_src escr...
Sectioning is a concise way to partially apply arguments to infix operators. For example, if we want to write a function which adds "ing" to the end of a word we can use a section to succinctly define a function. > (++ "ing") "laugh" "laughing" Notice...
Hash tables are created by make-hash-table: (defvar *my-table* (make-hash-table)) The function may take keyword parameters to further specify the behavior of the resulting hash table: test: Selects the function used to compare keys for equality. Maybe a designator for one of the functions eq,...
Extractor behavior can be used to derive arbitrary values from their input. This can be useful in scenarios where you want to be able to act on the results of a transformation in the event that the transformation is successful. Consider as an example the various user name formats usable in a Window...
Map 'Mapping' across a collection uses the map function to transform each element of that collection in a similar way. The general syntax is: val someFunction: (A) => (B) = ??? collection.map(someFunction) You can provide an anonymous function: collection.map((x: T) => /*Do something wi...
The variable command ensures that a given namespace variable is created. Until a value is assigned to it, the variable's value is undefined: namespace eval mynamespace { variable alpha set alpha 0 } The variable can be accessed from outside the namespace (from anywhere, in fact) by at...
Make sure you are in the directory that contains your Rails app, then create an app on Heroku. $ heroku create example Creating ⬢ example... done https://example.herokuapp.com/ | https://git.heroku.com/example.git The first URL of the ouput, http://example.herokuapp.com, is the location the ap...
Given these two CSV files: $ cat file1 1,line1 2,line2 3,line3 4,line4 $ cat file2 1,line3 2,line4 3,line5 4,line6 To print those lines in file2 whose second column occurs also in the first file we can say: $ awk -F, 'FNR==NR {lines[$2]; next} $2 in lines' file1 file2 1,line3 2,line4...
The -n flag enables you to check the syntax of a script without having to execute it: ~> $ bash -n testscript.sh testscript.sh: line 128: unexpected EOF while looking for matching `"' testscript.sh: line 130: syntax error: unexpected end of file
Almost every function in C standard library returns something on success, and something else on error. For example, malloc will return a pointer to the memory block allocated by the function on success, and, if the function failed to allocate the requested block of memory, a null pointer. So you sho...
String#at Returns a substring of a string object. Same interface as String#[]. str = "hello" str.at(0) # => "h" str.at(1..3) # => "ell" str.at(-2) # => "l" str.at(-2..-1) # => "lo" str.at(5) # => nil str.at(5..-...
String#to_time Converts a string to a Time value. The form parameter can be either :utc or :local, defaults to :local. "13-12-2012".to_time # => 2012-12-13 00:00:00 +0100 "06:12".to_time # => 2012-12-13 06:12:00 +0100 "2012-12-13 06...
String#exclude? The inverse of String#include? "hello".exclude? "lo" # => false "hello".exclude? "ol" # => true "hello".exclude? ?h # => false

Page 376 of 826