Tutorial by Examples

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...
Perform a basic GET request and prints the contents of a site (HTML). package main import ( "fmt" "io/ioutil" "net/http" ) func main() { resp, err := http.Get("https://example.com/") if err != nil { panic(err) } ...
A request for the top 10 most recently active StackOverflow posts using the Stack Exchange API. package main import ( "encoding/json" "fmt" "net/http" "net/url" ) const apiURL = "https://api.stackexchange.com/2.2/posts?" ...
You may pull (download) files from the device by executing the following command: adb pull <remote> <local> For example: adb pull /sdcard/ ~/ You may also push (upload) files from your computer to the device: adb push <local> <remote> For example: adb push ~/im...
You can reboot your device by executing the following command: adb reboot Perform this command to reboot into bootloader: adb reboot bootloader Reboot to recovery mode: adb reboot recovery Be aware that the device won't shutdown first!
This is an extension of Basic Example: Basic Structure import React, { Component } from 'react'; import { render } from 'react-dom'; class FirstComponent extends Component { render() { return ( <div> Hello, {this.props.name}! I am a FirstCompon...
To get a value from the map, you just have to do something like:00 value := mapName[ key ] If the map contains the key, it returns the corresponding value. If not, it returns zero-value of the map's value type (0 if map of int values, "" if map of string values...) m := map[string]s...
If you want to cancel an alarm, and you don't have a reference to the original PendingIntent used to set the alarm, you need to recreate a PendingIntent exactly as it was when it was originally created. An Intent is considered equal by the AlarmManager: if their action, data, type, class, and ca...
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...
It is possible to create a function that accepts objects that implement a specific trait. Static Dispatch fn generic_speak<T: Speak>(speaker: &T) { println!("{0}", speaker.speak()); } fn main() { let person = Person {}; let dog = Dog {}; generic_speak(...
An algorithmic problem is specified by describing the complete set of instances it must work on and of its output after running on one of these instances. This distinction, between a problem and an instance of a problem, is fundamental. The algorithmic problem known as sorting is defined as follows:...
__FUNCTION__ returns only the name of the function whereas __METHOD__ returns the name of the class along with the name of the function: <?php class trick { public function doit() { echo __FUNCTION__; } public function doitagain() { echo __METHOD_...
__CLASS__ magic constant returns the same result as get_class() function called without parameters and they both return the name of the class where it was defined (i.e. where you wrote the function call/constant name ). In contrast, get_class($this) and get_called_class() functions call, will both ...
To switch between time zones, you need datetime objects that are timezone-aware. from datetime import datetime from dateutil import tz utc = tz.tzutc() local = tz.tzlocal() utc_now = datetime.utcnow() utc_now # Not timezone-aware. utc_now = utc_now.replace(tzinfo=utc) utc_now # Timezon...
int[] arr = new int[] { 0, 10, 20, 30}; // Get Console.WriteLine(arr[2]); // 20 // Set arr[2] = 100; // Get the updated value Console.WriteLine(arr[2]); // 100
An array can be declared and filled with the default value using square bracket ([]) initialization syntax. For example, creating an array of 10 integers: int[] arr = new int[10]; Indices in C# are zero-based. The indices of the array above will be 0-9. For example: int[] arr = new int[3] {7,9,...
int[] arr = new int[] {1, 6, 3, 3, 9}; for (int i = 0; i < arr.Length; i++) { Console.WriteLine(arr[i]); } using foreach: foreach (int element in arr) { Console.WriteLine(element); } using unsafe access with pointers https://msdn.microsoft.com/en-ca/library/y31yhkeb.asp...
Support for type hinting array parameters (and return values after PHP 7.1) was added in PHP 5.1 with the keyword array. Any arrays of any dimensions and types, as well as empty arrays, are valid values. Support for type hinting callables was added in PHP 5.4. Any value that is_callable() is valid ...
Since PHP objects don't inherit from any base class (including stdClass), there is no support for type hinting a generic object type. For example, the below will not work. <?php function doSomething(object $obj) { return $obj; } class ClassOne {} class ClassTwo {} $classOne= new...
Type hinting for classes and interfaces was added in PHP 5. Class type hint <?php class Student { public $name = 'Chris'; } class School { public $name = 'University of Edinburgh'; } function enroll(Student $student, School $school) { echo $student->name . ' is b...

Page 176 of 1336