Wednesday, March 8, 2017

Processing JSON Data in Android (Using Omdbapi)

I'm going to provide you with the example of how to process a JSON data in Android.It's just a simple application.We are going to search for the Movies with titles similar to "Star" in IMDB site.Unfortunately, IMDB doesn't provide us with the information in JSON formatso we will seek help from Omdbapi.com



In our Main Activity:


package com.afeastoffriends.a9json;

import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;

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

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;

public class MainActivity extends AppCompatActivity {
    ListView listView;

//AsyncTask Allows us to do our task in background in another thread

    private class JsonDownload extends AsyncTask<String, Void, String>{

        @Override        protected String doInBackground(String... strings) {
            String result = "";
            URL url = null;
            HttpURLConnection urlConnection=null;

//We need try and catch as sometimes during the execution of application 
//there may be Internet Connectivity, Malformed Urls,etc


            try {
                url = new URL(strings[0]);
//Open urlConnection
                urlConnection = (HttpURLConnection) url.openConnection();
//Get Data from JSON
                InputStream in = urlConnection.getInputStream();
//Read Data from JSON
                InputStreamReader reader = new InputStreamReader(in);
                int data = reader.read();
//While data is unfinished
                while(data!=-1){
//Individual characters are read
                    char current = (char)data;
                    result += current;
//Next character is read
                    data = reader.read();
                }
                return  result;
            } catch (MalformedURLException e) {
                e.printStackTrace();
                return "MALformed URL Exception";
            } catch (IOException e) {
                e.printStackTrace();
                return "IOException";
            }
        }

        @Override        protected void onPostExecute(String s) {
            super.onPostExecute(s);
            try {
                JSONObject jsonObject = new JSONObject(s);
                String titley = jsonObject.getString("Search");


                ArrayList<String> fulllist = new ArrayList<String>();
                Log.i("Title",titley);
                JSONArray arr = new JSONArray(titley);
                for(int i=0; i<arr.length(); i++){
                    JSONObject jobject = arr.getJSONObject(i);
                    String tytle = jobject.getString("Title");
                    fulllist.add(tytle);
                }
                ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>
                (getApplicationContext(),android.R.layout.simple_list_item_1,fulllist);
                listView.setAdapter(arrayAdapter);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

//Create A ListView in the activity_main.xml file. We will use it to show movie list
        listView = (ListView)findViewById(R.id.listView);
//JsonDownload is a private class that we created
        JsonDownload json = new JsonDownload();
        json.execute("http://www.omdbapi.com/?s=star");
} }



In The AndroidManifest.xml you need permission to use INTERNET add the line:


<uses-permission android:name="android.permission.INTERNET"></uses-permission>

just before <application   />

Saturday, February 25, 2017

How To Create a .com.np Website For FREE

First of all you need
  1. Scanned Citizenship - Both front side and back side. Better if you combine them into same image. It must be less than 800kb
  2. Email Id
Then You Need a Web Host
We will use 000webhost.com as it is free. You can use other webhosting sites as well. All you need are the Name Servers.
In 000webhost.com you need to
  • There you can see Name Servers
  • Copy Name Servers, You will need them when Registering Domain

Now For Domain Registration
  • Enter Domain Name as your Name. Use your name for domain registration. Free .np domain can only be registered by your name. For eg:- subashbasnet.com.np, basnetsubash.com.np, sbasnet.com.np
  • In Domain Name enter as :- subashbasnet. In other fields, fill accordingly
  • Primary Name Server: ns01.000webhost.com
  • Secondary Name Server: ns02.000webhost.com
  • Click "Choose File" and Upload your citizenship and then Click Upload.
  • Enter the name of the file as "subashbasnet.com.np_citizenship"
  • Then Click Submit.
  • You will get response  from Mercantile within a week.
After you get response. You are ready for your new Domain under your own name

Friday, February 3, 2017

Phishing and How They Do It

Phishing is the type of attack by means of email, pop-up, chat messages, etc that tricks victims into clicking the link which can be an attempt to compromise a device to steal sensitive information like passwords, usernames, PIN, credit card number, online accounts.
It is the easiest and most common form of hacking. In this form of attack, victims are sent to the fake websites that look like the original sites such that when the user enters the account information, they are sent to hacker's database.
facebookhack

There are three major techniques of Phishing
1. Misspelt and Subdomain:-
In this type of phishing, there is subdomain manipulation. Most of the people who do not look properly while clicking links may fall into this trap. Misspelling of site is also common as people often donot look for spelling errors. (except Grammar Nazis :D and conscious people) For eg:-
http://www.facebook.com.xpertise.net
http://xpertise.net/au/facebook.com/help
http://www.facbook.com

2. IDN homograph attack:-
In this type of phishing, they expl0it the fact that how some characters 1ook alike. Using 0 instead of o and 1 instead of l(small L). If you can use the correct font sometimes we cannot distinguish between some characters. For eg:-
paypa1.com 1 & l(small letter L)
g00gle.com 0 & o
http://asĸ.com  k & ĸ

3. Hidden URLs:-
In this type of phishing, phishing urls are hidden inside links such as Click Here or http://www.facebook.com (Both sites link to http://www.google.com). Victim is tricked by this method.
hiddenurl

 You can just hover over the links and you can see the real website the link is directing you to.

Saturday, January 14, 2017

Cool Windows 10 Tips and Tricks

1. Create a GodMode in Windows 10:

God Mode is the file which lets you access to all the settings in a single page.
  • Create a new folder and rename it to "GodMode.{ED7BA470-8E54-465E-825C-99712043E01C}" without the ".
2. Microsoft Edge has a "Reading View" just like "Pocket" which helps you to get rid of all the unwanted contents and you can read the article only. In some sites it is not supported.

3. Win+G in Windows 10 can let you Record & Screenshot your GamePlay mainly but you can also record your screen. You can find the records in the "Video/Captures" folder.

4. Creating Virtual Desktops and Switching among them. It was a Linux thing but it has arrived to Windows finally.
  • Windows Key+Ctrl+D : Creates a New Virtual Desktop
  • Windows Key+Ctrl+Left Arrow : Switches to the Desktop on the Left
  • Windows Key+Ctrl+Right Arrow : Switches to the Desktop on the Right
  • Windows Key+Ctrl+F4 : Closes the Current Desktop
5. Snap Active Windows: If you want the window you are working to be Maximized, Minimized, Snapped to the right/left then you can do it using these shortcuts:
  • Windows Key+Left Arrow: Snap the window to the left.
  • Windows Key+Right Arrow: Snap the window to the right.
  • Windows Key+Up Arrow: Snap the window to the top/Maximize.
  • Windows Key+Down Arrow: Snap the window to the bottom/Minimize.

Saturday, January 7, 2017

10 Tips and Tricks For Computers. Be a Computer Pro and Prankster.

1. If you want to reopen the tab you just closed in a browser, just press "Control"  plus "Shift," plus "T,"

2. To make a copy of a file, you can press "Control" and then click and drag the file. When you find the appropriate folder for the copy you can then un-click and drop it there.

3. In Google Chrome, if you press "S" while right click on an image it gives you information about the image.

4. You can hit the space bar to pause a YouTube video, but sometimes this causes it to scroll down the page if you haven't already clicked on the video. If you press "K," this will play (or pause) the video every time. Hitting the "J" key will go back 10 seconds, while hitting the "L" key will go forward 10 seconds.

5. If you click the "Windows" key+right/left/up/down  arrow your window will go to the side of the arrow.



6. Clear cache in your browser by pressing Control+Shift+R. This will also refresh your page.

7. Press "Windows," plus  "L" to lock your computer quickly. You can also fool people by doing it.

8. Want to freak out your friends! If you press "Control" plus "Alt" plus one of the arrow keys, it will rotate your screen that way. It is way more fun.
ulto computer


9. If you want to bring up a basic text editor you can type in, just paste this into the address bar in your browser:
data:text/html, <title>Text Editor</title><body contenteditable style="font-size:3rem;font-family:arial;line-height:1.2;max-width:80rem;margin:1 auto;padding:5rem;">
text editor in browser


10. You can edit the webpage, write whatever you like with just a simple code. You need to paste it in the web browser (works on IE 7, Mozilla Firefox)
javascript:document.body.contentEditable='true'; document.designMode='on'; void 0

edit web text

For Google Chrome Users:
Press Ctrl Shift and J and paste it in there, then press Enter.









Sunday, January 1, 2017

File Compression

File Compression

ZIP files are very handy invention. It reduces the overall number of bits and bytes in a file so it can be transmitted faster and takes less space.
What file compression does is that it simply gets rid of the redundancy. For eg:-
Let's take example of J.F.K's quote:-
Ask not what your country can do for you - ask what you can do for your country.

Here there are:-

  • 17 - words
  • 61 - letters
  • 16 - spaces
  • 1 - dash
  • 1 - period
  • 79 - total memory units

Here "ask", "what", "your", "country", "can", "do", "for" and "you" appear two times.
Here's what LZ adaptive dictionary-based algorithm does. It indexes number to redundant words.
1.ask
2.what
3.your
4.country
5.can
6.do
7.for
8.you
Our sentence now is "1 not 2 3 4 5 6 7 8 - 1 2 8 5 6 7 3 4"
Here indexing takes 37 byte and sentence takes 37 byte taking overall 74 byte. It's not much but in reality the files take much more space and there is much more redundancy.

Here we take a look at repeated words but compression program sees it different. It doesn't know about separate words, it looks for patterns.
Here
1. "ask "
2. "what"
3. "you"
4. "r country"
5. " can do for you"
are repeated and the sentence can be made using these fragments.
1 not 2345 - 12354
Which decreased the total file size to 59 units