Tutorial by Examples: c

You can access SharedPreferences in several ways: Get the default SharedPreferences file: import android.preference.PreferenceManager; SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); Get a specific SharedPreferences file: public static final String PREF_FILE_NAM...
Within a catch block the throw keyword can be used on its own, without specifying an exception value, to rethrow the exception which was just caught. Rethrowing an exception allows the original exception to continue up the exception handling chain, preserving its call stack or associated data: try...
You can use the CONVERT function to cast a datetime datatype to a formatted string. SELECT GETDATE() AS [Result] -- 2016-07-21 07:56:10.927 You can also use some built-in codes to convert into a specific format. Here are the options built into SQL Server: DECLARE @convert_code INT = 100 -- See ...
@Provider public class CORSResponseFilter implements ContainerResponseFilter { public void filter( ContainerRequestContext requestContext, ContainerResponseContext responseContext ) throws IOException { MultivaluedMap<String, Object> headers = responseCo...
A Sub is a procedure that performs a specific task but does not return a specific value. Sub ProcedureName ([argument_list]) [statements] End Sub If no access modifier is specified, a procedure is Public by default. A Function is a procedure that is given data and returns a value, ideally...
Slices are the typical way go programmers store lists of data. To declare a slice variable use the []Type syntax. var a []int To declare and initialize a slice variable in one line use the []Type{values} syntax. var a []int = []int{3, 1, 4, 1, 5, 9} Another way to initialize a slice is with...
A class designed to be inherited-from is called a Base class. Care should be taken with the special member functions of such a class. A class designed to be used polymorphically at run-time (through a pointer to the base class) should declare the destructor virtual. This allows the derived parts of...
Bear in mind that declaring a destructor inhibits the compiler from generating implicit move constructors and move assignment operators. If you declare a destructor, remember to also add appropriate definitions for the move operations. Furthermore, declaring move operations will suppress the genera...
When creating a recyclerview with a gridlayout layout manager you have to specify the span count in the constructor. Span count refers to the number of columns. This is fairly clunky and doesn't take into account larger screen sizes or screen orientation. One approach is to create multiple layouts f...
To add a header to a recyclerview with a gridlayout, first the adapter needs to be told that the header view is the first position - rather than the standard cell used for the content. Next, the layout manager must be told that the first position should have a span equal to the *span count of the e...
Define your class that will represent your custom error. public class ErrorDto { public int Code { get; set; } public string Message { get; set; } // other fields public override string ToString() { return JsonConvert.SerializeObject(this); } } Then put nex...
The idea is to use HttpContext.Response.OnStarting callback, as this is the last event that is fired before the headers are sent. Add the following to your middleware Invoke method. public async Task Invoke(HttpContext context) { context.Response.OnStarting((state) => { if ...
A shell script is a very versatile way to extend your build to basically anything you can think of. As an exmaple, here is a simple script to compile protobuf files and add the result java files to the source directory for further compilation: def compilePb() { exec { // NOTICE: grad...
The class we are going to test is: public class Service { private Collaborator collaborator; public Service(Collaborator collaborator) { this.collaborator = collaborator; } public String performService(String input) { return collaborator.transformStri...
The class we are going to test is: public class Service{ private Collaborator collaborator; public Service(Collaborator collaborator){ this.collaborator = collaborator; } public String performService(String input){ return collaborator.transformS...
Enumerable is the most popular module in Ruby. Its purpose is to provide you with iterable methods like map, select, reduce, etc. Classes that use Enumerable include Array, Hash, Range. To use it, you have to include Enumerable and implement each. class NaturalNumbers include Enumerable de...
The core concepts of RxJava are its Observables and Subscribers. An Observable emits objects, while a Subscriber consumes them. Observable Observable is a class that implements the reactive design pattern. These Observables provide methods that allow consumers to subscribe to event changes. The ev...
Comparable is one of the most popular modules in Ruby. Its purpose is to provide with convenience comparison methods. To use it, you have to include Comparable and define the space-ship operator (<=>): class Rectangle include Comparable def initialize(a, b) @a = a @b = b ...
angular.module("app") .service("counterService", function(){ var service = { number: 0 }; return service; });
angular.module("app") // Custom services are injected just like Angular's built-in services .controller("step1Controller", ['counterService', '$scope', function(counterService, $scope) { counterService.number++; // bind to...

Page 112 of 826