Tutorial by Examples: c

If you need to send events from fragment to activity, one of the possible solutions is to define callback interface and require that the host activity implement it. Example Send callback to an activity, when fragment's button clicked First of all, define callback interface: public interface Samp...
This is an example for how to handle dynamic key for response. Here A and B are dynamic keys it can be anything Response { "response": [ { "A": [ { "name": "Tango" }, { "name": "P...
CREATE TABLE ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, ... PRIMARY KEY(id), ... ); Main notes: Starts with 1 and increments by 1 automatically when you fail to specify it on INSERT, or specify it as NULL. The ids are always distinct from each other, but... Do not make a...
The following examples use the UTF-8 encoding to represent filenames (and directory names) on disk. If you want to use another encoding, you should use Encode::encode(...). use v5.14; # Make Perl recognize UTF-8 encoded characters in literal strings. # For this to work: Make sure your text-editor...
Some common operations in MATLAB, like differentiation or integration, output results that have a different amount of elements than the input data has. This fact can easily be overlooked, which would usually cause errors like Matrix dimensions must agree. Consider the following example: t = 0:0.1:1...
Recursive type Discriminated unions can be recursive, that is they can refer to themselves in their definition. The prime example here is a tree: type Tree = | Branch of int * Tree list | Leaf of int As an example, let's define the following tree: 1 2 5 3 4 We can defi...
The $q constructor function is used to create promises from asynchronous APIs that use callbacks to return results. $q(function(resolve, reject) {...}) The constructor function receives a function that is invoked with two arguments, resolve and reject that are functions which are used to eithe...
When using C#'s inbuilt lock statement an instance of some type is needed, but its state does not matter. An instance of object is perfect for this: public class ThreadSafe { private static readonly object locker = new object(); public void SomeThreadSafeMethod() { lock (locker) { ...
//Get instance of cache using System.Runtime.Caching; var cache = MemoryCache.Default; //Check if cache contains an item with cache.Contains("CacheKey"); //get item from cache var item = cache.Get("CacheKey"); //get item from cache or add item if not existing obje...
If you want to provide a URL out of convenience for your user but map it directly to another one you're already using. Use a redirect: # config/routes.rb TestApp::Application.routes.draw do get 'courses/:course_name' => redirect('/courses/%{course_name}/lessons'), :as => "course&quot...
To create an albums collection, add the following to your config.yml file: collections: - albums Create a corresponding folder at the root of your Jekyll install, named exactly what you put in your config.yml file with an additional prepended underscore; in our example, <source>/_albums....
These Java issues can be very embarrassing, and sometimes remain undiscovered until run in production. Fallthrough behavior in switch statements is often useful; however, missing a “break” keyword when such behavior is not desired can lead to disastrous results. If you have forgotten to put a “break...
Every time a program opens a resource, such as a file or network connection, it is important to free the resource once you are done using it. Similar caution should be taken if any exception were to be thrown during operations on such resources. One could argue that the FileInputStream has a finaliz...
This example is about deliberately ignoring or "squashing" exceptions. Or to be more precise, it is about how to catch and handle an exception in a way that ignores it. However, before we describe how to do this, we should first point out that squashing exceptions is generally not the co...
This exception occurs when a collection is modified while iterating over it using methods other than those provided by the iterator object. For example, we have a list of hats and we want to remove all those that have ear flaps: List<IHat> hats = new ArrayList<>(); hats.add(new Ushanka...
ASP.NET Core introduces the concept of dependency injection into Views via the @inject directive via the following syntax : @inject <type> <name> Example Usage Adding this directive into your View will basically generate a property of the given type using the given name within your ...
The basic math operations are performed mainly on numbers or on vectors (lists of numbers). 1. Using single numbers We can simple enter the numbers concatenated with + for adding and - for subtracting: > 3 + 4.5 # [1] 7.5 > 3 + 4.5 + 2 # [1] 9.5 > 3 + 4.5 + 2 - 3.8 # [1] 5.7 >...
In vc.h @interface vc : UIViewController<UIWebViewDelegate> in vc.m - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType{ if (navigationType == UIWebViewNavigationTypeLinkClicked){...
AsyncTaskLoader is an abstract Loader that provides an AsyncTask to do the work. Here some basic implementation: final class BasicLoader extends AsyncTaskLoader<String> { public BasicLoader(Context context) { super(context); } @Override public String loadInBa...
For Each row As DataRow In FooDataTable.Rows Me.RowsToProcess.Add(row) Next Dim myOptions As ParallelOptions = New ParallelOptions() myOptions.MaxDegreeOfParallelism = environment.processorcount Parallel.ForEach(RowsToProcess, myOptions, Sub(currentRow, state) ...

Page 367 of 826