Linux Process Monitor with RAm, CPU

sudo apt-get install sysstat

# To monitor process every 5 sec
pidstat -h -r -u -v -p 12345,11223 5

Goodle drive setup:

sudo add-apt-repository ppa:thefanclub/grive-tools
sudo apt-get update
sudo apt-get install grive-tools
  • Search Ubuntu Dash for Grive Setup and start the application.
  • Follow the on-screen instructions (see screenshots below)

Android Basic – 1

MainActivity.java
package com.example.giri.demo1; 

import android.app.AlertDialog; 
import android.bluetooth.BluetoothAdapter; 
import android.bluetooth.BluetoothDevice; 
import android.content.Context; 
import android.content.DialogInterface; 
import android.content.Intent; 
import android.content.res.Resources; 
import android.graphics.Bitmap; 
import android.net.Uri; 
import android.os.Bundle; 
import android.speech.tts.TextToSpeech; 
import android.support.design.widget.FloatingActionButton; 
import android.support.design.widget.Snackbar; 
import android.support.v7.app.AppCompatActivity; 
import android.support.v7.widget.Toolbar; 
import android.text.Editable; 
import android.text.Html; 
import android.text.TextWatcher; 
import android.text.method.LinkMovementMethod; 
import android.util.Log; 
import android.view.View; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.view.animation.Animation; 
import android.view.animation.AnimationUtils; 
import android.webkit.WebView; 
import android.widget.ArrayAdapter; 
import android.widget.AutoCompleteTextView; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.ImageView; 
import android.widget.ListView; 
import android.widget.MultiAutoCompleteTextView; 
import android.widget.TextView; 
import android.widget.Toast; 

import org.json.JSONArray; 
import org.json.JSONException; 
import org.json.JSONObject; 

import java.util.ArrayList; 
import java.util.Locale; 
import java.util.Set; 

public class MainActivity extends AppCompatActivity { 

    private EditText mCity; 
    private EditText mName; 
    private EditText mDept; 
    ImageView iv; 
    Button b1,bt1,bt2,gotoB1; 
    ListView lv; 

    TextToSpeech t1; 

    private BluetoothAdapter BA; 

    Button button; 
    String[] languages={"Android ","java","IOS","SQL","JDBC","Web services"}; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.activity_main); 
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 
        setSupportActionBar(toolbar); 

        addAlert(); 
        navigatePage(); 
        textListener(); 
        snackBar(); 
        jsonRead(); 
        arrayRead(); 
        htmlLink(); 
        animationSample(); 
        cameraShot(); 
        BtEnable(); 
        btList(); 

    } 

    public void addAlert() { 

        final Context context = this; 

        button = (Button) findViewById(R.id.alert2); 

        button.setOnClickListener(new View.OnClickListener() { 

            @Override 
            public void onClick(View arg0) { 

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder( 
                        context); 

                // set title 
                alertDialogBuilder.setTitle("Your Title"); 

                // set dialog message 
                alertDialogBuilder 
                        .setMessage("Click yes to exit!") 
                        .setCancelable(false) 
                        .setPositiveButton("Yes",new DialogInterface.OnClickListener() { 
                            public void onClick(DialogInterface dialog,int id) { 
                                // if this button is clicked, close 
                                // current activity 
                               // MainActivity.this.finish(); 
                                Toast.makeText(getApplicationContext(), 
                                        "Clicked Yes", Toast.LENGTH_LONG).show(); 
                            } 
                        }) 
                        .setNegativeButton("No",new DialogInterface.OnClickListener() { 
                            public void onClick(DialogInterface dialog,int id) { 
                                // if this button is clicked, just close 
                                // the dialog box and do nothing 
                                dialog.cancel(); 
                                Toast.makeText(getApplicationContext(), 
                                        "Clicked No", Toast.LENGTH_LONG).show(); 
                            } 
                        }); 

                // create alert dialog 
                AlertDialog alertDialog = alertDialogBuilder.create(); 

                // show it 
                alertDialog.show(); 

                //Intent intent = new Intent(context, App2Activity.class); 
                //startActivity(intent); 

            } 

        }); 

    } 

    private void navigatePage(){ 
        final Context context = this; 

        gotoB1=(Button)findViewById(R.id.gotoNext); 

        gotoB1.setOnClickListener(new View.OnClickListener() { 
            @Override 

            public void onClick(View v) { 
                Intent intent = new Intent(context, Main2Activity.class); 
                startActivity(intent); 
            } 
        }); 
    } 

    private void textListener(){ 
        mName = (EditText) findViewById(R.id.name); 
        mDept = (EditText) findViewById(R.id.department); 
        mCity = (EditText) findViewById(R.id.editText3); 

        TextWatcher watcherCity = new TextWatcher() { 
            @Override 
            public void beforeTextChanged(CharSequence s, int start, int count, int after) { 

            } 

            @Override 
            public void onTextChanged(CharSequence s, int start, int before, int count) { 

            } 

            @Override 
            public void afterTextChanged(Editable s) { 
                //Toast.makeText(getApplicationContext(), 
                //        "Required Field", Toast.LENGTH_LONG).show(); 
                View view = findViewById(R.id.imageButton); 
                Animation anim; 

                String city = mCity.getText().toString(); 
                int citylen = city.length(); 

                if(citylen < 1){ 
                    view.setVisibility(View.VISIBLE); 
                    anim = AnimationUtils.makeInAnimation(MainActivity.this,true); 
                } else { 
                    view.setVisibility(View.INVISIBLE); 
                    anim = AnimationUtils.makeOutAnimation(MainActivity.this,true); 
                } 

                view.startAnimation(anim); 

            } 
        }; 

        mCity.addTextChangedListener(watcherCity); 
    } 

    private void snackBar(){ 
        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); 
        fab.setOnClickListener(new View.OnClickListener() { 
            @Override 
            public void onClick(View view) { 
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) 
                        .setAction("Action", null).show(); 
            } 
        }); 
    } 

    private void btList(){ 
        lv = (ListView)findViewById(R.id.listView2); 

        Set<BluetoothDevice> pairedDevices = BA.getBondedDevices(); 
        ArrayList list = new ArrayList(); 

        for(BluetoothDevice bt : pairedDevices) 
            list.add(bt.getName()); 
        Toast.makeText(getApplicationContext(),"Showing Paired Devices",Toast.LENGTH_SHORT).show(); 
        //      final ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_list_item_1, list); 
        //        lv.setAdapter(adapter); 
    } 

    private void cameraShot(){ 
        iv=(ImageView)findViewById(R.id.imageView1); 
        b1=(Button)findViewById(R.id.alert1); 

        b1.setOnClickListener(new View.OnClickListener() { 
            @Override 
            public void onClick(View v) { 
                Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); 
                startActivityForResult(intent, 0); 
            } 
        }); 

    } 

    private void animationSample(){ 
        // Animation 
        // http://www.tutorialspoint.com/android/android_animations.htm 
        ImageView image = (ImageView)findViewById(R.id.imageButton); 
        Animation animation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.myanimation); 
        image.startAnimation(animation); 
    } 

    private void htmlLink(){ 
        TextView tv = (TextView) findViewById(R.id.largeText); 
        tv.setText(Html.fromHtml("<a href=http://www.stackoverflow.com> STACK OVERFLOW ")); 
        tv.setMovementMethod(LinkMovementMethod.getInstance()); 
    } 

    private void arrayRead(){ 
        TextView message = (TextView) findViewById(R.id.textView1); 
        Resources resources = this.getResources(); 
        String[] javafacts = resources.getStringArray(R.array.messages); 
        String fact = javafacts[0]; 

        String wholeFact = ""; 
        for(int i=0;i<javafacts.length;i++){ 
            wholeFact = wholeFact + javafacts[i] + "\n"; 
        } 
        message.setText(wholeFact); 

    } 

    private void jsonRead(){ 
        TextView output = (TextView) findViewById(R.id.jsonText); 
        String strJson="        {            \"Employee\" :[            {                \"id\":\"01\",                \"name\":\"Gopal Varma\",                \"salary\":\"500000\"            },            {                \"id\":\"02\",                \"name\":\"Sairamkrishna\",                \"salary\":\"500000\"            },            {                \"id\":\"03\",                \"name\":\"Sathish kallakuri\",                \"salary\":\"600000\"            }            ]        }"; 
        String data = ""; 
        try { 
            JSONObject jsonRootObject = new JSONObject(strJson); 

            //Get the instance of JSONArray that contains JSONObjects 
            JSONArray jsonArray = jsonRootObject.optJSONArray("Employee"); 

            //Iterate the jsonArray and print the info of JSONObjects 
            for(int i=0; i < jsonArray.length(); i++){ 
                JSONObject jsonObject = jsonArray.getJSONObject(i); 

                int id = Integer.parseInt(jsonObject.optString("id").toString()); 
                String name = jsonObject.optString("name").toString(); 
                float salary = Float.parseFloat(jsonObject.optString("salary").toString()); 

                data += "Node"+i+" : \n id= "+ id +" \n Name= "+ name +" \n Salary= "+ salary +" \n "; 
            } 
            output.setText(data); 
        } catch (JSONException e) {e.printStackTrace();} 
    } 

    private void BtEnable(){ 
        bt1 = (Button) findViewById(R.id.bt1); 
        BA = BluetoothAdapter.getDefaultAdapter(); 
        if (!BA.isEnabled()) { 
            Intent turnOn = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); 
            startActivityForResult(turnOn, 0); 
            Toast.makeText(getApplicationContext(),"Turned on",Toast.LENGTH_LONG).show(); 
        } 
        else 
        { 
            Toast.makeText(getApplicationContext(),"Already on", Toast.LENGTH_LONG).show(); 
        } 
    } 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
        // TODO Auto-generated method stub 
        super.onActivityResult(requestCode, resultCode, data); 

        Bitmap bp = (Bitmap) data.getExtras().get("data"); 
        iv.setImageBitmap(bp); 
    } 

    @Override 
    protected void onDestroy() { 
        super.onDestroy(); 
    } 

    public void processFormold(View registerForm) { 
        // registerForm.setVisibility(View.INVISIBLE); 
        String name = mName.getText().toString(); 
        int len = name.length(); 
        int pos = name.indexOf(" "); 

        //try{ 
        //    int cityCode = Integer.parseInt(mCity.getText().toString()); 
        //    Log.d("MainActivity", "City numer" + cityCode); 
        //}catch (Exception e){ 
        //    Log.d("MainActivity", "City numer is not an Number" ); 
        //} 

        if (len == 0) { 
            Toast.makeText(getApplicationContext(), 
                    "Required Field", Toast.LENGTH_LONG).show(); 
            mName.requestFocus(); 
            return; 
        } 

        if (len > 10) { 
            Toast.makeText(getApplicationContext(), 
                    "Mre than 10 characters", Toast.LENGTH_LONG).show(); 
            mName.requestFocus(); 
            return; 
        } else { 
            String userName=""; 
            try { 
                 userName = name.substring(0, pos); 
            }catch (Exception e){ 
                 userName = "nvalid"; 
            } 

            String thanks = "Thanks " + userName; 

            Toast.makeText(getApplicationContext(), 
                    thanks, Toast.LENGTH_LONG).show(); 
        } 
        Toast.makeText(getApplicationContext(), 
                name, Toast.LENGTH_LONG).show(); 
    } 

    public void processForm(View registerForm){ 
        // simple msg 

        /* 
        Intent i = new Intent(Intent.ACTION_SEND); 
        i.setType("text/plain"); 
        i.putExtra(Intent.EXTRA_TEXT, "This is my first messaging APP!"); 
        startActivity(i); 

        // sms 
        Intent i = new Intent(Intent.ACTION_SENDTO, 
                Uri.fromParts("sms","+919843915733",null) 
                ); 
        i.putExtra("sms_body", "This is my first messaging APP!"); 
        startActivity(i); 

        //Email 
        Intent i = new Intent(Intent.ACTION_SENDTO, 
                Uri.fromParts("mailto","kayalshri@gmail.com",null) 
                ); 
        i.putExtra(Intent.EXTRA_SUBJECT, "Subject content"); 
        i.putExtra(Intent.EXTRA_TEXT, "Body content"); 
        //startActivity(i); 
        startActivity(Intent.createChooser(i,"App header")); 
        */ 

        //phone Call 
        Intent intent = new Intent(); 
        intent.setAction(Intent.ACTION_DIAL); 
        intent.setData(Uri.parse("tel:9843915733")); 
        startActivity(intent); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
        // Inflate the menu; this adds items to the action bar if it is present. 
        getMenuInflater().inflate(R.menu.menu_main, menu); 
        return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
        // Handle action bar item clicks here. The action bar will 
        // automatically handle clicks on the Home/Up button, so long 
        // as you specify a parent activity in AndroidManifest.xml. 
        int id = item.getItemId(); 

        //noinspection SimplifiableIfStatement 
        if (id == R.id.action_settings) { 
            return true; 
        } 

        return super.onOptionsItemSelected(item); 
    } 
}

Android-studio installation on ubuntu 14.04 LTE

1. sudo su
2. # javac -version
The program 'javac' can be found in the following packages:
 * default-jdk
 * ecj
 * gcj-4.9-jdk
 * openjdk-7-jdk
 * gcj-4.8-jdk
 * openjdk-6-jdk
 * openjdk-8-jdk
Try: apt-get install <selected package>

* Install above packages

3. Download android-studio package
https://dl.google.com/dl/android/studio/ide-zips/1.5.1.0/android-studio-ide-141.2456560-linux.zip

4. Uncompress the File
unzip android-studio-ide-141.2456560-linux.zip

5. mv android-studio/ /usr/local/

6. set env path only for the current terminal
export PATH=$PATH:/usr/local/android-studio/bin

To a specific user permanently:
echo "export PATH=$PATH:/usr/local/android-studio/bin" >> /home/<user_name>/.bash_profile

To all user permanently: (executed)
echo "export PATH=$PATH:/usr/local/android-studio/bin" >> /etc/profile

7. Symbolic link
ln -s /usr/local/android-studio/bin/studio.sh /usr/local/sbin/

8. run the script
studio.sh

Ubuntu Google Chrome Install

 wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | sudo apt-key add - 
 sudo sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list'
 sudo apt-get update 
 sudo apt-get install google-chrome-stable

Andriod Studio Installation

Download Studio:

http://www.tutorialspoint.com/android/android_studio.htm

Download Java:

http://freewareupdate.com/download-java-se-development-kit/20002/

Set Env Path:

Set the JAVA_HOME Variable

Once you have identified the JRE installation path:

  1. Right-click the My Computer icon on your desktop and select Properties
  2. Click the Advanced tab
  3. Click the Environment Variables button
  4. Under System Variables, click New
  5. Enter the variable name as JAVA_HOME
  6. Enter the variable value as the installation path for the Java Development KitIf your Java installation directory contains a space in the path name, you should use the shortened path name (e.g. C:\Progra~1\Java\jre6) in the environment variable, instead.

    Note for Windows users on 64-bit systems

    Progra~1 = 'Program Files'
    Progra~2 = 'Program Files(x86)'

  7. Click OK
  8. Click Apply Changes
  9. Close any command window that was open before you made these changes and open a new command window.
    It's not possible to reload environment variables from an active command prompt. If the changes don't take effect even after reopening the command window, restart Windows.

JAVA_HOME => C:\Program Files\Java\jdk1.7.0_21

path => C:\Program Files\Java\jdk1.7.0_21\bin

htop cpu view customize

sudo vim $HOME/.config/htop/htoprc

edit:

left_meters=LeftCPUs2 CPU Memory Swap
left_meter_modes=1 1 1 1
right_meters=RightCPUs2 Tasks LoadAverage Uptime
right_meter_modes=1 2 2 2

Mysql user create and assign to specify db

CREATE USER 'username'@'localhost' IDENTIFIED BY 'abc#123';

CREATE USER 'username'@'%' IDENTIFIED BY 'abc#123';

create database DBNAME; 

GRANT ALL PRIVILEGES ON DBNAME . * TO 'username'@'localhost';

GRANT ALL PRIVILEGES ON DBNAME . * TO 'username'@'%';

FLUSH PRIVILEGES;

Mysql Root password reset in ubuntu

 

sudo dpkg-reconfigure mysql-server-N.N

(where N.N is the MySql Server version)

 

Ref : https://help.ubuntu.com/community/MysqlPasswordReset

 

mysql frm file recovery

Mysql Table structure recovery from mysqlfrm utility:

sudo apt-get install mysql-utilities
mysqlfrm --server=root:password@localhost *.frm  --port=3307 --user=root > db.sql

horizontal to vertical string – shell script

When i was expected below kind of result and i have checked so many sites but in vain. Finally I got the result and just want to share this...

cat input
12345abc
12345abc
12345abc
12345abc

length=`head -1 input | wc -c | cut -d" " -f1`;for (( c=1; c<=$length; c++ )); do cat input | cut -c${c} | sed -e :a -e '{N; s/\n//g; ta}'   ; done
1111
2222
3333
4444
5555
aaaa
bbbb
cccc

 

Further level of Filtering:

 length=`head -1 input | wc -c | cut -d" " -f1`;for (( c=1; c<=$length; c++ )); do cat input | cut -c${c} | sed -e :a -e '{N; s/\n//g; ta}' |  awk '!/\./ && !/4/ && /[2-5]/ {print $0}'  ; done

2222
3333
5555