Tutorial by Examples: c

Lets assume we have this class and we would like to test doSmth method. In this case we want to see if parameter "val" is passed to foo. Object foo is mocked. public class Bar { private final Foo foo; public Bar(final Foo foo) { this.foo = foo; } public ...
You can define central config info's in a separate gradle include file Centralizing dependencies via "dependencies.gradle" file a stand alone properties file Versioning your builds via "version.properties" file or do it with root gradle.properties file the project structu...
Inline display elements, usually such as span or a, will include up to one white-space character before and after them in the document. In order to avoid very long lines in the markup (that are hard to read) and unintentional white-space (which affects formatting), the white-space can be commented o...
build.gradle: dependencies { compile 'com.android.support:appcompat-v7:23.3.0' compile 'com.jakewharton.rxbinding:rxbinding-appcompat-v7:0.4.0' } menu/menu.xml: <menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.c...
First of all you need Uri and temp Folders and request codes : public final int REQUEST_SELECT_PICTURE = 0x01; public final int REQUEST_CODE_TAKE_PICTURE = 0x2; public static String TEMP_PHOTO_FILE_NAME ="photo_"; Uri mImageCaptureUri; File mFileTemp; Then init mFileTemp : public ...
Obfuscation is often considered as a magic solution for code protection, by making your code harder to understand if it ever gets de-compiled by hackers. But if you're thinking that removing the Log.x(..) actually removes the information the hackers need, you'll have a nasty surprise. Removing al...
In addition to cursor movements using the arrow keys, Home, End, Page up, and Page down, emacs defines a number of keystrokes that can move the cursor over smaller or larger pieces of text: By character: Backward character: C-b Forward character: C-f By word Backward word: M-b (i.e. Alt b...
One of the use cases of callback URLs is OAuth. Let us do this with an Instagram Login: If the user enters their credentials and clicks the Login button, Instagram will validate the credentials and return an access_token. We need that access_token in our app. For our app to be able to listen to suc...
X-Macros can be used for code generation, by writing repetitive code: iterate over a list to do some tasks, or to declare a set of constants, objects or functions. Here we use X-macros to declare an enum containing 4 commands and a map of their names as strings Then we can print the string values ...
Enums contains only constants and can be compared directly with ==. So, only reference check is needed, no need to use .equals method. Moreover, if .equals used incorrectly, may raise the NullPointerException while that's not the case with == check. enum Day { GOOD, AVERAGE, WORST; } publi...
The Standard (10.4) states: Member functions can be called from a constructor (or destructor) of an abstract class; the effect of making a virtual call (10.3) to a pure virtual function directly or indirectly for the object being created (or destroyed) from such a constructor (or destructor) is u...
Most, but not all, C++ implementations support the #pragma once directive which ensures the file is only included once within a single compilation. It is not part of any ISO C++ standard. For example: // Foo.h #pragma once class Foo { }; While #pragma once avoids some problems associated w...
Insertion sort is a very simple, stable, in-place sorting algorithm. It performs well on small sequences but it is much less efficient on large lists. At every step, the algorithms considers the i-th element of the given sequence, moving it to the left until it is in the correct position. Graphica...
There are two common ways to list all processes on a system. Both list all processes running by all users, though they differ in the format they output (the reason for the differences are historical). ps -ef # lists all processes ps aux # lists all processes in alternative format (BSD) Thi...
VariableDetails$* / $@Function/script positional parameters (arguments). Expand as follows:$* and $@ are the same as $1 $2 ... (note that it generally makes no sense to leave those unquoted)"$*" is the same as "$1 $2 ..." 1 "$@" is the same as "$1" "$2&qu...
To get the name of the current function - type: my_function() { echo "This function is $FUNCNAME" # This will output "This function is my_function" } This instruction will return nothing if you type it outside the function: my_function echo "This function i...
Similar to $HOSTTYPE above, this also includes information about the OS as well as hardware ~> $ echo $MACHTYPE x86_64-redhat-linux-gnu
The number of seconds a script has been running. This can get quite large if shown in the shell: ~> $ echo $SECONDS 98834
Positional parameters passed to the script from either the command line or a function: #!/bin/bash # $n is the n'th positional parameter echo "$1" echo "$2" echo "$3" The output of the above is: ~> $ ./testscript.sh firstarg secondarg thirdarg firstarg sec...
LINQ provides a built-in function for checking the equality of two IEnumerables, and that function can be used on arrays. The SequenceEqual function will return true if the arrays have the same length and the values in corresponding indices are equal, and false otherwise. int[] arr1 = { 3, 5, 7 };...

Page 405 of 826