Linux and mac useful tips

Bash Startup Files

When invoked as an interactive login shell, Bash looks for the /etc/profile file, and if the file exists , it runs the commands listed in the file. Then Bash searches for ~/.bash_profile~/.bash_login, and ~/.profile files, in the listed order, and executes commands from the first readable file found.

When Bash is invoked as an interactive non-login shell, it reads and executes commands from ~/.bashrc, if that file exists, and it is readable.

Difference Between .bashrc and .bash_profile

.bash_profile is read and executed when Bash is invoked as an interactive login shell, while .bashrc is executed for an interactive non-login shell.

Use .bash_profile to run commands that should run only once, such as customizing the $PATH environment variable .

Put the commands that should run every time you launch a new shell in the .bashrc file. This include your aliases and functions , custom prompts, history customizations , and so on.

Create .bash_profile

To create the bash_profile, proceed with the following steps:

  1. Open the terminal.
  2. Move the home directory using the following command:
    cd ~/
  3. Use the touch command to create the bash_profile as follows:
    touch .bash_profile

Edit .bash_profile

using your favourite editor and put this :

#change the bold keyword as per your system

ANDROID_SDK=/Users/username/Library/Android/sdk
PlatformTool_PATH=”$ANDROID_SDK/platform-tools”
BuildTools=”$ANDROID_SDK/build-tools/30.0.2/”
export PATH=”$PATH:$ANDROID_SDK:$PlatformTool_PATH:$BuildTools”
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

Create .bashrc

Use same step as in .bash_profile

Edit .bashrc

using your favourite editor and put this :

#Linux


alias ll=’ls -alFh’
alias l=’ls -CFah’
alias lt=’du -sh * | sort -h’
alias CD=”cd ~/Desktop”
alias Cd=”cd ~/Documents”
alias Cdo=”cd ~/Downloads”
alias Cdop=”cd ~/Downloads && open .”
alias Cdp=”cd ~/Documents && open .”
alias CDp=”cd ~/Desktop && open .”

#git

alias gh=’history|grep’
alias gs=’git status’
alias gl=’git log –oneline’
alias gf=’git fetch’
alias gm=’cd git rev-parse --show-toplevel && git checkout master && git pull’
alias cg=’cd git rev-parse --show-toplevel

#android

ANDROID_SDK=/Users/kinaval/Library/Android/sdk
PlatformTool_PATH=”$ANDROID_SDK/platform-tools”
BuildTools=”$ANDROID_SDK/build-tools/30.0.2/”
export PATH=”$PATH:$ANDROID_SDK:$PlatformTool_PATH:$BuildTools”

alias alog=’adb logcat | tee ‘
alias alogc=’adb logcat > log.txt’
alias count=’find . -type f | wc -l’
alias cpv=’rsync -ah –info=progress2′

#paython

alias ve=’python3 -m venv ./venv’
alias va=’source ./venv/bin/activate’

Now save all file it and open terminal for this time use

source ~/.bash_profile

By navalkishorjha

Android Studio plugin to easy work

  1. SonarLint
  2. JSON Editor
  3. Rainbow Brackets
  4. SQLDelight
  5. ADB Idea
  6. JSON To Kotlin Class
  7. code-iris
  8. Codota
  9. String Manipulation
  10. Easy Gradle
  11. Kotlin Fill Class
  12. Key Promoter X
  13. Clear Cache Plugin
  14. FCM Push Sender
  15. JSON Helper —
  16. Json String into Kotlin data class
  17. Python Community Edition
  18. Rainbow CSV
  19. Database development, scripting and navigation tool
  20. SQLAndroid
  21. Android ButterKnife Zelezny injections
  22. SQLScout
  23. CodeGlance
  24. Indent Rainbow
  25. TabNine
  26. Kite AI
  27. Material Theme UI

https://betterprogramming.pub/the-top-20-android-studio-plugins-4331f5cdeb80

https://www.dunebook.com/best-android-studio-plugins/

video compresser online free

https://compress-video-online.com/

https://github.com/Genymobile/scrcpy/blob/master/doc/windows.md: Android Studio plugin to easy work

https://github.com/mik3y/usb-serial-for-android

By navalkishorjha

Room Database pre-populated data! and Database Upgrade

@Query("UPDATE tableName SET 
    field1 = :value1,
    field2 = :value2, 
    ...
    //some more fields to update
    ...
    field_N= :value_N
    WHERE id = :id)

int updateTour(long id, 
               Type value1, 
               Type value2, 
               ... ,
               // some more values here
               ... ,
               Type value_N);

Example:

Entity:

@Entity(tableName = "orders")
class Order {
    @NonNull
    @PrimaryKey
    @ColumnInfo(name = "order_id")
    private val id = 0

    @ColumnInfo(name = "order_title")
    private val title: String? = null

    @ColumnInfo(name = "order_amount")
    private val amount: Float? = null

    @ColumnInfo(name = "order_price")
    private val price: Float? = null

    @ColumnInfo(name = "order_desc")
    private val description: String? = null

    @ColumnInfo(name = "order_date")
    private val date: Long = 0 // ... methods, getters, setters
}

Dao:

@Dao
interface OrderDao {
    @get:Query("SELECT * FROM orders")
    val orderList: List<Any?>?

    @get:Query("SELECT * FROM orders")
    val orderLiveList: LiveData<List<Order?>?>?

    @Query("SELECT * FROM orders WHERE order_id =:orderId")
    fun getLiveOrderById(orderId: Int): LiveData<Order?>?

    /** * Updating only price * By order id  */
    @Query("UPDATE orders SET order_price=:price WHERE order_id = :id")
    fun update(price: Float?, id: Int)

    /** * Updating only amount and price * By order id  */
    @Query("UPDATE orders SET order_amount = :amount, price = :price WHERE order_id =:id")
    fun update(amount: Float?, price: Float?, id: Int)

    /** * Updating only title and description * By order id  */
    @Query("UPDATE orders SET order_desc = :description, order_title= :title WHERE order_id =:id")
    fun update(description: String?, title: String?, id: Int)

    @Update
    fun update(order: Order?)

    @Delete
    fun delete(order: Order?)

    @Query("DELETE FROM orders")
    fun deleteAll()

    @Insert(onConflict = REPLACE)
    fun insert(order: Order?)

    @Query("SELECT * FROM Order WHERE id IN (:orderIds)")
    fun loadAllByOrderId(vararg orderIds: Int): List<*>?

    @Query("SELECT * FROM Order WHERE order_title LIKE :name AND oder_date = :orderDate LIMIT 1")
    fun loadOneByNameAndReleaseYear(name: String?, orderDate: Long): Order?

    @Insert
    fun insertAll(vararg order: Order?)
}

Database:

@Database(entities = arrayOf(Order::class), version = 1, exportSchema = true)
abstract class InventoryRoomDatabase : RoomDatabase() {

   abstract fun orderDao(): OrderDao

   private class InventoryDBCallback() : RoomDatabase.Callback() {

       override fun onOpen(db: SupportSQLiteDatabase) {
           super.onOpen(db)
           INSTANCE?.let { database ->
                   var orderDao = database.orderDao()

                   // Delete all content here.
                   orderDao.deleteAll()

                   // Add sample order.
                   var order = Order().apply{ 
                       order_title="Apple";order_amount=200.00;
                       order_price=150.00;
                       order_desc="50 bugs discoount coupon";
                       order_date=1590645654
                   }
                   orderDao.insert(order)
                //add 1 more order   
                   order.order_title="talc"
                   orderDao.insert(order)

                   // TODO: Add your own order!
                   order = Order().apply{ 
                      order_title="NoteBook";order_amount=80.00;
                      order_price=80.00;
                      order_desc="0 bugs discoount on note book";
                      order_date=1590645886}
                      orderDao.insert(order)
                  }
           }
       } 
   }

   companion object {
       @Volatile
       private var INSTANCE: InventoryRoomDatabase? = null

       fun getDatabase(context: Context): WordRoomDatabase {
            // if the INSTANCE is not null, then return it,
            // if it is, then create the database
            return INSTANCE ?: synchronized(this) {
                val instance = Room.databaseBuilder(
                        context.applicationContext,
                        InventoryRoomDatabase::class.java,
                        "inventory_database"
                )
                 .addCallback(InventoryDBCallback())
                 .allowMainThreadQueries()
                 .fallbackToDestructiveMigration()
               //.addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_1_4)
                 .build()
                INSTANCE = instance
                // return instance
                instance
        }
     }
   }

val MIGRATION_1_2: Migration = object : Migration(1, 2) {
       override fun migrate(database: SupportSQLiteDatabase) {
        //simple migration 
      }
    }

val MIGRATION_2_3: Migration = object : Migration(2, 3) {
            override fun migrate(database: SupportSQLiteDatabase) {
                // sechema change migration
                database.execSQL("ALTER TABLE orders " + " ADD COLUMN last_update INTEGER")
            }
        }
val MIGRATION_3_4: Migration = object : Migration(3, 4) {
            override fun migrate(database: SupportSQLiteDatabase) {
                // Create the new table
                database.execSQL("CREATE TABLE users_new (userid TEXT, username TEXT, last_update INTEGER, PRIMARY KEY(userid))")
                // Copy the data
                database.execSQL("INSERT INTO users_new (userid, username, last_update) SELECT userid, username, last_update FROM users")
                // Remove the old table
                database.execSQL("DROP TABLE users")
                // Change the table name to the correct one
                database.execSQL("ALTER TABLE users_new RENAME TO users")
            }
        }
 
val MIGRATION_1_4: Migration = object : Migration(1, 4) {
            override fun migrate(database: SupportSQLiteDatabase) {
                // Create the new table
                database.execSQL("CREATE TABLE users_new (userid TEXT, username TEXT, last_update INTEGER, PRIMARY KEY(userid))")
                // Copy the data
                database.execSQL("INSERT INTO users_new (userid, username, last_update) SELECT userid, username, last_update FROM users")
                // Remove the old table
                database.execSQL("DROP TABLE users")
                // Change the table name to the correct one
                database.execSQL("ALTER TABLE users_new RENAME TO users")
            }
        }

for the schema to keep a record

in the module where your database file are present, default will be app

so open the build.gradle file

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'


android {
    // ......
    defaultConfig {
     //....
        kapt {
               arguments {
                   arg("room.schemaLocation", "${projectDir}/schemas")
               }
       }
  }//defaultConfig closing

} // android



dependencies {
    def  room_version = '2.2.4'
    //....
   implementation "androidx.room:room-runtime:$room_version"
   kapt "androidx.room:room-compiler:$room_version"
     // For Kotlin use kapt instead of annotationProcessor
     // optional - Kotlin Extensions and Coroutines support for Room
   implementation "androidx.room:room-ktx:$room_version"
     //...
}

By navalkishorjha