Tutorial by Examples

The Object.freeze() method is available since version 5.1. For older versions, you can use the following code (note that it also works in versions 5.1 and later): var ColorsEnum = { WHITE: 0, GRAY: 1, BLACK: 2 } // Define a variable with a value from the enum var currentColor = Co...
After defining an enum using any of the above ways and setting a variable, you can print both the variable's value as well as the corresponding name from the enum for the value. Here's an example: // Define the enum var ColorsEnum = { WHITE: 0, GRAY: 1, BLACK: 2 } Object.freeze(ColorsEnum); // D...
A lot of the value from local JVM unit tests comes from the way you design your application. You have to design it in such a way where you can decouple your business logic from your Android Components. Here is an example of such a way using the Model-View-Presenter pattern. Lets practice this out by...
Property scrollEnabled stores a Boolean value that determines whether scrolling is enabled or not. If the value of this property is true/YES, scrolling is enabled, otherwise not.The default value is true Swift scrollview.isScrollEnabled = true Objective-C scrollview.scrollEnabled = YES;
Create UIScrollView instance let scrollview = UIScrollView.init(frame: self.view.bounds) And then set these properties: scrollView.minimumZoomScale = 0.1 scrollView.maximumZoomScale = 4.0 scrollView.zoomScale = 1.0 scrollview.delegate = self as? UIScrollViewDelegate To zoom in and out im...
Redirect to within application (another action of specific controller). return $this->redirect([ 'controller' => 'myController', 'action' => 'myAction' ]); Redirect to referrer page return $this->redirect($this->referer()); Redirect to outside of application or spec...
Passing Variable in URL as a method's parameter return $this->redirect([ 'controller' => 'users', 'action' => 'profile', $id ]); Url should be looks like this http://your_app_url/users/profile/{id} in UsersController.php file in profile() method class UsersController e...
Set default layout for entire application. i.e, created layout file in /src/Template/Layout/admin.ctp class AppsController extends Controller { public function beforeFilter(Event $event) { parent::beforeFilter($event); $this->viewBuilder()->layout('admin'); // For Ver...
Generally in AJAX request no need of load CSS, JS. Also omitting other HTML code. Make ajax.ctp file in /src/Template/Layout, and code should be <?php $this->fetch('content'); Set AJAX based layout for entire application, in AppsController.php class AppsController extends Controlle...
We can load components in two ways. By initialize or override $components property in Controller By using loadComponent() method in initialize() method of Controller. Way-1 It should be override loading component by AppsController.php load one or more component class UsersController extend...
initialize() is introduced in CakePHP version > 3.0 As a code structure, it looks like same as beforeFilter() method. but there is many differences between beforeFilter() and initialize(). initialize() is always called after constructor is called. but beforeFilter() is not calling in case of ...
You can retrieve query string data as Array. $post_data= $this->request->query; You can retrieve post data for particular key. $this->request->query['field']; Retrieve specific key value $this->request->query('key_name'); Retrieve specific key value of nested array $th...
dependencies { compile 'com.google.code.gson:gson:2.8.1' } To use latest version of Gson The below line will compile latest version of gson library everytime you compile, you do not have to change version. Pros: You can use latest features, speed and less bugs. Cons: It might break com...
This will load a JSON file from disk and convert it to the given type. public static <T> T getFile(String fileName, Class<T> type) throws FileNotFoundException { Gson gson = new GsonBuilder() .create(); FileReader json = new FileReader(fileName); return gson....
Sometimes you need to serialize or deserialize some fields in a desired format, for example your backend may use the format "YYYY-MM-dd HH:mm" for dates and you want your POJOS to use the DateTime class in Joda Time. In order to automatically convert these strings into DateTimes object, y...
First of all you need to add the GsonConverterFactory to your build.gradle file compile 'com.squareup.retrofit2:converter-gson:2.1.0' Then, you have to add the converter factory when creating the Retrofit Service: Gson gson = new GsonBuilder().create(); new Retrofit.Builder() .baseUrl...
It's possible to compare lists and other sequences lexicographically using comparison operators. Both operands must be of the same type. [1, 10, 100] < [2, 10, 100] # True, because 1 < 2 [1, 10, 100] < [1, 10, 100] # False, because the lists are equal [1, 10, 100] <= [1, 10, 100] #...
Given this function: annualSalaryCalc :: (RealFloat a) => a -> a -> String annualSalaryCalc hourlyRate weekHoursOfWork | hourlyRate * (weekHoursOfWork * 52) <= 40000 = "Poor child, try to get another job" | hourlyRate * (weekHoursOfWork * 52) <= 120000 = "Money...
Class: public class Version : IComparable<Version> { public int[] Parts { get; } public Version(string value) { if (value == null) throw new ArgumentNullException(); if (!Regex.IsMatch(value, @"^[0-9]+(\.[0-9]+)*$")) th...
To enable or disable a BroadcastReceiver, we need to get a reference to the PackageManager and we need a ComponentName object containing the class of the receiver we want to enable/disable: ComponentName componentName = new ComponentName(context, MyBroadcastReceiver.class); PackageManager packageM...

Page 571 of 1336