Posts

Showing posts from 2023

ViewModel in android.

ViewModel is part of the  android architecture component . Android architecture components are the components that are used to build robust, clean, and scalable apps. Android architecture components hold some classes to manage UI components and Data persistence. The ViewModel class is designed to store and manage UI-related data in a lifecycle-conscious way. ViewModel classes are used to store the data even the configuration changes like rotating screen. ViewModel is one of the most critical class of the Android Jetpack Architecture Component that support data for UI components. Its purpose is to hold and manage the UI-related data. Moreover, its main function is to maintain the integrity and allows data to service during configuration changes like screen rotations. Any kind of configuration change in Android devices tends to recreate the whole activity of the application. It means the data will be lost if it has been not saved and restored properly from the activity which was destroye

Remove active class of tab pane in jquery

  $( '.tab' ). on ( 'click' , function ( ){ var thisTab = this ; /* some code ... */ /* Removing active effect with slideUp: */ $( '.active' ). not (thisTab). slideUp ( function ( ){ $( this ). removeClass ( 'active' ). fadeIn (); }); /* After that, active the clicked tab: */ $(thisTab). addClass ( 'active' ); });

Median of two sorted arrays

class Main {      // function to calculate median      static int getMedian( int ar1[], int ar2[], int n)      {            int i = 0 ;           int j = 0 ;          int count;          int m1 = - 1 , m2 = - 1 ;                  /* Since there are 2n elements, median will             be average of elements at index n-1 and             n in the array obtained after merging ar1             and ar2 */          for (count = 0 ; count <= n; count++)          {              /* Below is to handle case where all                elements of ar1[] are smaller than                smallest(or first) element of ar2[] */              if (i == n)              {                  m1 = m2;                  m2 = ar2[ 0 ];                  break ;              }                      /* Below is to handle case where all                 elements of ar2[] are smaller than                 smallest(or first) element of ar1[] */              else if (j == n)              {                  m1 =