Tutorial by Examples: dp

The getAll() method retrieves all values from the preferences. We can use it, for instance, to log the current content of the SharedPreferences: private static final String PREFS_FILE = "MyPrefs"; public static void logSharedPreferences(final Context context) { SharedPreferences s...
Functions can take inputs in form of variables that can be used and assigned inside their own scope. The following function takes two numeric values and returns their sum: function addition (argument1, argument2){ return argument1 + argument2; } console.log(addition(2, 3)); // -> 5 ...
The % wildcard appended to the beginning or end (or both) of a string will allow 0 or more of any character before the beginning or after the end of the pattern to match. Using '%' in the middle will allow 0 or more characters between the two parts of the pattern to match. We are going to use this...
Properties are members of an object. Each named property is a pair of (name, descriptor). The name is a string that allows access (using the dot notation object.propertyName or the square brackets notation object['propertyName']). The descriptor is a record of fields defining the bevahiour of the pr...
Defining position as fixed we can remove an element from the document flow and set its position relatively to the browser window. One obvious use is when we want something to be visible when we scroll to the bottom of a long page. #stickyDiv { position:fixed; top:10px; left:10px; } ...
SharedPreferences sharedPreferences = ...; sharedPreferences.registerOnSharedPreferenceChangeListener(mOnSharedPreferenceChangeListener); private final SharedPreferences.OnSharedPreferenceChangeListener mOnSharedPreferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener(...
def say_hello_to(name) puts "Hello #{name}" end say_hello_to('Charles') # Hello Charles
def greet(greeting, name) puts "#{greeting} #{name}" end greet('Hi', 'Sophie') # Hi Sophie
Auto-implemented properties were introduced in C# 3. An auto-implemented property is declared with an empty getter and setter (accessors): public bool IsValid { get; set; } When an auto-implemented property is written in your code, the compiler creates a private anonymous field that can only be...
Python 2.x2.6 The format() method can be used to change the alignment of the string. You have to do it with a format expression of the form :[fill_char][align_operator][width] where align_operator is one of: < forces the field to be left-aligned within width. > forces the field to be righ...
Debug cargo build Release Building with the --release flag enables certain compiler optimizations that aren't done when building a debug build. This makes the code run faster, but makes the compile time a bit longer too. For optimal performance, this command should be used once a release build ...
// The Option type can either contain Some value or None. fn find(value: i32, slice: &[i32]) -> Option<usize> { for (index, &element) in slice.iter().enumerate() { if element == value { // Return a value (wrapped in Some). return Some(index);...
The following code creates a simple user interface containing a single Button that prints a String to the console on click. import javafx.application.Application; import javafx.scene.Scene; import javafx.scene.control.Alert; import javafx.scene.control.Alert.AlertType; import javafx.scene.contr...
if ($PSCmdlet.ShouldProcess("Target of action")) { # Do the thing } When using -WhatIf: What if: Performing the action "Invoke-MyCmdlet" on target "Target of action" When using -Confirm: Are you sure you want to perform this action? Performing operation &qu...
class Person { [string] $FirstName [string] $LastName [string] Greeting() { return "Greetings, {0} {1}!" -f $this.FirstName, $this.LastName } } $x = [Person]::new() $x.FirstName = "Jane" $x.LastName = "Doe" $greeting = $x.Greeting() #...
# test date-time object options(digits.secs = 3) d = as.POSIXct("2016-08-30 14:18:30.58", tz = "UTC") format(d,"%S") # 00-61 Second as integer ## [1] "30" format(d,"%OS") # 00-60.99… Second as fractional ## [1] "30.579" for...
The -Wildcard parameter allows switch statements to perform wildcard matching against conditions. Example: switch -Wildcard ('Condition') { 'Condition' {'Normal match'} 'Condit*' {'Zero or more wildcard chars.'} 'C[aoc]ndit[f-l]on' {'Range and set of chars...
The System namespace contains Func<..., TResult> delegate types with between 0 and 15 generic parameters, returning type TResult. private void UseFunc(Func<string> func) { string output = func(); // Func with a single generic type parameter returns that type Console.WriteLine...
The background-position property is used to specify the starting position for a background image or gradient .myClass { background-image: url('path/to/image.jpg'); background-position: 50% 50%; } The position is set using an X and Y co-ordinate and be set using any of the units used withi...
A Lens' s a means that you can always find an a within any s. A Prism' s a means that you can sometimes find that s actually just is a but sometimes it's something else. To be more clear, we have _1 :: Lens' (a, b) a because any tuple always has a first element. We have _Just :: Prism' (Maybe a) a...

Page 2 of 21