Tutorial by Examples: ad

SharedPreferences Manager (Singleton) class to read and write all types of data. import android.content.Context; import android.content.SharedPreferences; import android.util.Log; import com.google.gson.Gson; import java.lang.reflect.Type; /** * Singleton Class for accessing SharedPref...
Executing code after 1.5 seconds: Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { //The code you want to run after the time is up } }, 1500); //the time you want to delay in milliseconds Executing code repeatedly every...
const fs = require('fs'); const readline = require('readline'); const rl = readline.createInterface({ input: fs.createReadStream('text.txt') }); // Each new line emits an event - every time the stream receives \r, \n, or \r\n rl.on('line', (line) => { console.log(line); }); ...
There are multiple threads in your code and you need to safely communicate between them. You can use a Queue from the queue library. from queue import Queue from threading import Thread # create a data producer def producer(output_queue): while True: data = data_computation() ...
In Objective-C, method swizzling is the process of changing the implementation of an existing selector. This is possible due to the way Selectors are mapped on a dispatch table, or a table of pointers to functions or methods. Pure Swift methods are not dynamically dispatched by the Objective-C run...
If you want to download an object from GCS that is publicly viewable, the simplest way is to use a web browser or a command line tool to fetch a URL with this pattern: https://storage.googleapis.com/bucketName/objectName. Example: https://storage.googleapis.com/pub/someOfTheTeam.jpg
add_filter('template_include', 'custom_function'); function custom_function($template){ /* * This example is a little more advanced. * It will check to see if $template contains our post-type in the path. * If it does, the theme contains a high level templat...
Custom views can also take custom attributes which can be used in Android layout resource files. To add attributes to your custom view you need to do the following: Define the name and type of your attributes: this is done inside res/values/attrs.xml (create it if necessary). The following file...
std::async is also able to make threads. Compared to std::thread it is considered less powerful but easier to use when you just want to run a function asynchronously. Asynchronously calling a function #include <future> #include <iostream> unsigned int square(unsigned int i){ r...
A Broadcast receiver is an Android component which allows you to register for system or application events. A receiver can be registered via the AndroidManifest.xml file or dynamically via the Context.registerReceiver() method. public class MyReceiver extends BroadcastReceiver { @Override ...
nuget sources add -name feedname -source http://sourcefeedurl
To add a method to a button, first create an action method: Objective-C -(void)someButtonAction:(id)sender { // sender is the object that was tapped, in this case its the button. NSLog(@"Button is tapped"); } Swift func someButtonAction() { print("Button is tapped...
Note that you cannot overload a function based on its return type. For example: // WRONG CODE std::string getValue() { return "hello"; } int getValue() { return 0; } int x = getValue(); This will cause a compilation error as the compiler will not be able to work out wh...
Intents can be used to broadcast messages to other components of your application (such as a running background service) or to the entire Android system. To send a broadcast within your application, use the LocalBroadcastManager class: Intent intent = new Intent("com.example.YOUR_ACTION"...
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...
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 packages foreign and haven can be used to import and export files from a variety of other statistical packages like Stata, SPSS and SAS and related software. There is a read function for each of the supported data types to import the files. # loading the packages library(foreign) library(have...
Swift let alert = UIAlertController(title: "Hello", message: "Welcome to the world of iOS", preferredStyle: UIAlertControllerStyle.alert) let defaultAction = UIAlertAction(title: "OK", style: UIAlertActionS...
The following is an excerpt from Gradle - What is a non-zero exit value and how do I fix it?, see it for the full discussion. Let's say you are developing an application and you get some Gradle error that appears that generally will look like so. :module:someTask FAILED FAILURE: Build failed with...
Look at the contents of /etc/redhat-release cat /etc/redhat-release Here is the output from a Fedora 24 machine: Fedora release 24 (Twenty Four) As mentioned in the debian-based response, you can also use the lsb_release -a command, which outputs this from a Fedora 24 machine: LSB Version: ...

Page 15 of 114