Thursday, October 23, 2014

JSON - The briefest tutorial out there!


This blog post will cover a brief area in JSON. Just like the cool name, it does provide some cool services to the web developer. We will talk what is JSON first before getting it to its uses.

What? & Why?

JSON - JavaScript Object Notation. This is just a form of representing data. People at Oracle says:

"JSON is a text-based data exchange format derived from JavaScript that is used in web services and other connected applications."

I have used JSON in some of my web projects too. Solely for one purpose though, but I know there are a lot of other uses with this. My goal was to get the users country with the IP address he/she logs in from. My only option since I bought cheap hosting was to go with this. Click the following link and see what you get,

http://ip2country.sourceforge.net/ip2c.php?format=JSON

Yeah, thats what I thought => correct information!

We call something like this as a JSON Object. There are only two types of data structures in JSON. One as we know is an Object and the other is an Array.

So there are two things, you could create JSON text or you could get uses out of it. We'll talk how to use JSON text.

The two data structures are like this,

Objects will be enclosed in braces({}) and Arrays will be enclosed in box brackets([]). I am going to go ahead and use the same example in the oracle site.

{
   "firstName": "Duke",
   "lastName": "Java",
   "age": 18,
   "streetAddress": "100 Internet Dr",
   "city": "JavaTown",
   "state": "JA",
   "postalCode": "12345",
   "phoneNumbers": [
      { "Mobile": "111-111-1111" },
      { "Home": "222-222-2222" }
   ]
}
 
So this is a JSON text. I think they are just like a tuple in a Database. A method of delivering data, via a connection. Does that sound firmiliar? XML? Ah yes, this is a lot easier way to do things than XML :)

Going back to the description, Values inside an Object or in an Array are separated with a comma (,) and the identifier and the value is separated by a colon (:). These Identifiers are always Strings and their values can take any one of these: string, number, object, array, true, false, and null

Using

So how do we use the text we just received from the server? Did I say that JSON is a derivative of JavaScript? So when you are going JS way things get much more easy. :D There are tonnes of JSON decoders out there for any web based language. In php its 

$json = file_get_contents('the-web-address');
$expression = json_decode($json);
print_r($expression) 
So if we are doing these in JS, we could actually do like this, I shall get the first example to explain this,
 
var details = {
   "firstName": "Duke",
   "lastName": "Java",
   "age": 18,
   "streetAddress": "100 Internet Dr",
   "city": "JavaTown",
   "state": "JA",
   "postalCode": "12345",
   "phoneNumbers": [
      { "Mobile": "111-111-1111" },
      { "Home": "222-222-2222" }
   ]
}
 
document.write(details.firstName); 

Easy as that :)

So using JSON is very easy because,
  • Easy to generate and parse
  • Language independent
  • Light weight
  • Compact
I just wanted to show you how messy a XML file which returns the Country from IP:

Check this out,
http://ip-api.com/xml 

But it also does get the job done!

Monday, February 3, 2014

Flying like a Jelly Fish

Don't go crazy when you see the title, What I am about to say is a innovation by Lief Ristroph and Stephen Childress of New York University. You might have compare an aero plane to a bird and an helicopter to dragon fly in some day of your life. Both of these are animals who can fly, but did you ever thought that the researchers would be able to engineer a miniature flying machine using the swimming motion of a jellyfish?
As I have also said earlier most flying machines we have seen in our days mimic animals birds or insects, they tend to flip upside down unless they have special mechanisms called aerodynamic dampeners which are basically tails or sails; or a continues control system to control the wing speed and the motion. But this flying machines mechanism which mimics the jellyfish swim allowed it to maintain stability without adding those mechanisms.

This jellyfish flying machine is called a "Thopter" which weighs about 2.1 grams including the motor which weighs 1.1 grams still in experimental stage. Researchers would be one day able to get this flyer to a commercial stage.

For the ones who need to see how the jellyfish swim:
Resources:
LiveScienceVideos : YouTube channel
Facts from Royal Society Publishing

Linux Operating Systems - What are there!

Ok, I hope you guys have read the previous blog post, If not please go and check that out first. Here I will briefly list out what Linux OSs are out there.


Alright, you already know that there are over 600 linux OS that you can choose from, If you need to stay updated what OS has new updates and what are new OSs keep in touch with this site http://distrowatch.com/

Ok now that we have that cleared up, these are some of the OSs I recomond you to check out :)


  1. Ubuntu - Easy GUI, best for a converted user (coming from windows or mac)
  2. Mint - Something like Ubuntu, recently became popular among desktop users, best for beginners.
  3. CentOS - Used for servers, so you might not want to check that out, but if you have one, better use one like this :)
  4. Elementary OS - Kind of like MacOS and has a definite glow to the OS. One of the most beautiful Linux OSs I have seen
  5. Debian - Advanced and Base linux distro. If you are reading about Debian here, you might want to learn some things before checking that out :)
  6. Fedora - Another advanced Base linux distro.
  7. CrunchBang - This is also one of the advanced, based on debian and my favorite.  This is the most hackable distro that i have used.
  8. Puppy - One of the light weight distros, weighs about 165MBs, yes you can have that inside very small pen, And what i should say to you is that it can be used in very old hardware as well.
  9. DSL - The ISO image size of this is 50MB, thats why this is called DamnSmallLinux, can be run in very old hardware
  10. Ubuntu Studio - Aimed upon Audio, Video, Photography, Graphics and Publishing enthusiasts. This is a good Distro for the multi-media personnel looking to be free :)
  11. SystemRescueCD - Designed to repairing a System and its data after a system crash. Better have one of these if you are using an unstable linux distro.
So I have listed out some of the OSs that I think would be good to check out. Also keep in mind that these OS can be tested before you can use them in a Live mode, I will explain how to check out an OS and install it in a computer in the next post . Hope you will be with us until then.

Resources:
Thanks for GeekFume for the image :)

Sunday, February 2, 2014

Linux Operating Systems, a Little bit

You all must know if you have been with a computer there are open source operating systems out there that you can get for free. Yes, you don't have to spend a fortune just to use your computer as the way you want. And when talking about Open source Operating systems, you cannot forget about Linux OSs. These are based from the Unix one which changed the computer world by its roots.
There are over 600 (http://en.wikipedia.org/wiki/Linux_distribution) Linux distributions that you can choose from to install onto your computer. The best part is there is a distro for almost every need.

Day before yesterday one of my friends at a forum asked me to give him a good linux distribution where he can browse safely on the www and what i did was googling "web surf linux" then I came up with a good solution: IprediaOS. I think you might have got the idea.

Desktop, Multimedia, Servers, Security-Enhanced and there are more and there will be more.
CrunchBang, One of my favs 

So what you should first do is get a clear idea about what you are trying to do with your computer. Then go through discussions or ask from a Linux Guru (I my self is not one-but i can help you with the help of google and my recent knowledge :) )

Monday, January 27, 2014

Control Structures - Loops (while)

If you guys haven't read the previous posts linked with this post, please read them first and come back here :)
#1 Control Structures - If, If else, If else If
#2 Control Structures - Loops (for)

Ok, now you have a basic idea about what a loop is, and the for loop too. Now I will describe what is a while loop. While loop is used when we don't know the number of iterations in the loop. And the minimum number of iterations is zero.

This loop also works a bit similar to the for loop. Below I have an example code and the syntax.

while(<condition>)
{
   <statements>
}

Finite loop example:

int i = 0;
while(i<5)
{
   System.out.println("This is i: "+i"); //prints i when it is less than 5
}

Infinite Loop example

while(true)
{
   System.out.println("This will run forever!!");
}
While loop has the same arguments as in the for loop. But is has arranged in a different way. You will see that the starting index is not specified in the syntax, you can use that if you need a starting index for your code.

This works a bit simpler than the for loop. This only checks the condition, if the condition returns a true value, the code written between the curly brackets will run.
Resources: stepbystep.com

Tuesday, January 21, 2014

Control Structures - Loops

This post is linked with this, which we have talked about the IF, IF ELSE, IF ELSE IF and SWITCH CASE. So please make sure you read that and then come to this.

So you already know there are 2 types of control structures. The first one we have already discussed, the Conditional Statements. What we have left with is the Iterative structures. Simply the looping structures or the repeating structures. We can divide up to 2 types in this category.

  1. Infinite loops
  2. Finite loops
Let us first discuss about the 3 looping structures.

For loop

The syntax of the for loop is as follows:
for(startingIndex; condition; increment) //you can either use increment or decrement
{
    //codes to loop
}
Example for a finite loop:
for(int i=0; i<5;i++)
{
    System.out.println("This will print 5 times");
}
Example for a infinite loop:

for(int i=0;true;i++)
{
    System.out.println("Thisis i: "+i);
}

The code I have illustrated in the example executes like this. First when the interpreter comes into the for loop, it checks what the starting index variable and keeps them in a memory location. Then it checks the condition, if the condition returns a TRUE value, interpreter moves on to the code block surrounding with the curly brackets. After it has been executed, the interpreter goes to the increment or decrement part of the loop and executes it. Then the next step for the interpreter is to check the condition, if it returns a TRUE value, it goes on to the code block to loop...



There are two more looping structures, which I will explain in the next article. Enjoy and practice the for loop before you read the next :)

Resources: 
Images: 

Sunday, January 19, 2014

Control Structures in programming

We all know that when we write programs we write them in an order in which they will be executed. So what if we need to deviate from this order? what if we need to execute a set  of codes again and again? To do that, most of the programming languages have introduced us with control structures. These will do what ever thing they are instructed until their conditions are met. That's how they manage the control flow in a program.

There are a few control structures we can see in a programming language. To illustrate them, I have used Java language.

  • Conditional Statements
  • Iterative Structures
Before learning these, you need to have a basic idea of boolean data type. This is the data type which stores "TRUE" or "FALSE" values. Check the following example.

6 > 5 //true
2.4 > 9 //false
number == 5 //depends on how number is defined
number != 4
You have a set of operators that goes along with boolean data type.

> greater than
< less than
>= greater than ore equal
<= less than or equal
== equal
!= not equal
! not

You can use these to build boolean values.

Conditional Statements

In this category, we can find 4 different types of conditional statements. First one is the "IF" structure.

IF Structure

I will illustrate the syntax of an if structure using Java(language) codes.

if( x > 5 )
   System.out.print("The condition  is met");

Here in, x > 5 is the condition. You can see that the condition is always a boolean value. You can use raw boolean value inside a condition too, but that would not make sense of having the control structure in the first place. This structure works like this. If the value of the condition is "TRUE" then and only then the statement after that will be executed. If you have more than one statement to execute, you can enclose them inside curly brackets ( { } ).

IF ELSE Structure

This works the same as the IF Structure but this has another addition. You might have noticed in the IF Structure, the statement will only occur if and only if the condition is met. We have not specified what to do when the condition is not met.

if(x > 5 )
   System.out.print("Condition is met");
else
   System.out.print("Condition is not met");

So if the condition is not met, the else part will be executed. Which means that the condition is FALSE the else part will be executed.

IF ELSE IF

We have learned somewhat similar conditional statements. This differs from other types as follows, the two we learned previously had only one condition. If the condition is met the if block will execute, otherwise the else part will be executed. Here we can have more than one condition, this is how you do it.

if(x>5)
  System.out.print("Condition 1 is met");
else if(x>3)
  System.out.print("Condition 2 is met");
else if(x>4)
  System.out.print("Condition 3 is met");
.......
.......
else
  System.out.print("all conditions are false");

Switch Case

This is also another method of selecting the appropriate decision. Using this you can't implement all that you can do with an IF or IF ELSE or IF ELSE IF. But when you can implement something using this method, the amount of code will be less than previous cases and it will be easier to implement.

switch(x)
{
   case 1: System.out.print("x=1");
                break;
   case 2: System.out.print("x=2");
                 break;
   case 3: System.out.print("x=3");
                 break;
  default:   case 1: System.out.print("x is not 1, 2 or 3");
}

If the value of the x is 1, this simple code will print x=1, else if x is 2 it will print x=2... and for when x is 3 it will print x=3. The default case is just like else part in the IF ELSE IF statements.

We will discuss other control structures in the next blog post.
Resources:
# http://en.wikipedia.org/wiki/Java_(programming_language)