Search

androidtour

Month

September 2015

Scenario 3

If you want to develop the code for below json format.

{
    "Products": [
        {
            "ProductNo": "11111",
            "Descr": "Myproduct-1",
            "Price": "225.36"
        },
        {
            "ProductNo": "11112",
            "Descr": "Myproduct-2",
            "Price": "235.46"
        },
        {
            "ProductNo": "11113",
            "Descr": "Myproduct-3",
            "Price": "245.56"
        },
        {
            "ProductNo": "11114",
            "Descr": "Myproduct-4",
            "Price": "255.56"
        } 
    ],
    "DateUpdated" : "20091209",
    "UpdatUser" : "Bob" 
}

Program:
$array = array (
	'Products' => array (),
	'DateUpdated' => '20091209',
	'UpdateUser' => 'Bob',
);

while ($row = mysql_fetch_assoc($result))
	$array['Products'][] = $row;

$json = json_encode($array);
 

 

Installation of Hadoop in VMplayer in windows 8.1

Refer this for more info
http://hadoop.apache.org/docs/current/hadoop-project-dist/hadoop-common/SingleCluster.html

Install ubuntu in vmware player

install JDK/JRE using command line
https://www.digitalocean.com/community/tutorials/how-to-install-java-on-ubuntu-with-apt-get
For JDK
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
For JRE
http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html

Bydefault
JDK is installed in /usr/lib/jvm
for check wheather JDK is installed or not write java -version
http://www.howtogeek.com/191427/how-to-find-out-if-java-is-installed-in-ubuntu-and-how-to-install-it/

Download hadoop from this link
http://www.eu.apache.org/dist/hadoop/common/

Create hadoop folder in home directory and extract hadoop.tar in this folder

write sudo gedit /etc/profile
add this line in last of this file

JAVA_HOME=/usr/local/java/jdk1.8.0-60
PATH=$PATH:$JAVA_HOME/bin
JRE_HOME=/usr/local/java/jre1.8.0-60
PATH=$PATH:$JRE_HOME/bin
HADOOP_INSTALL=/home/hadoop/hadoop-1.2.1
PATH=$PATH:$HADOOP_INSTALL/bin
export JAVA_HOME
export JRE_HOME
export PATH

sudo update-alternatives –install “/usr/local/java” “java” “/usr/local/java/default-java/bin/java” 1

bin/hadoop jar hadoop-examples-*.jar grep input output ‘dfs[a-z.]+’

For remove JDK
http://ajgupta.github.io/ubuntu/2014/09/18/Completely-uninstall-Java-from-Ubuntu-14.04/
sudo apt-get install ssh

open conf/core-site.xml
<configuration>
<property>
<name>fs.default.name</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>

hdfs-site.xml
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>

mapred-site.xml
<configuration>
<property>
<name>mapred.job.tracker</name>
<value>localhost:9001</value>
</property>
</configuration>

open hadoop-env.sh
change JAVA_HOME /usr/local/java/jdk1.8.0_60
make sure # must be removed

install ssh and rsync

setup password key and run two command from first link of thisa artical

goto hadoop folder and write
bin/hadoop namenode format

for start all node and process regarding hadoop
bin/start-all.sh

jps is used for show the running process
jps is a command

bin/hadoop fs -put conf input

for install cludera installtion
http://pyfunc.blogspot.in/2012/05/hadoop-pseudo-cluster-installation.html

for kill the process on port
sudo kill `sudo lsof -t -i:9000`

netstat -nlp
for show the process

Find first( ) from CFG using JAVA

Under Testing….

UBUNTU update software command

Update software using command line

sudo apt-get update
sudo apt-get dist-upgrade

How to install ns in ubuntu
sudo apt-get install ns2

Easy way to learn Hadoop on windows

http://www.hadoopwizard.com/install-hadoop-on-windows-in-3-easy-steps-for-hortonworks-sandbox-tutorial/

Hortonworks

Hortonworks is a business computer software company based in Santa Clara, California. The company focuses on the development and support of Apache Hadoop, a framework that allows for the distributed processing of large data sets across clusters of computers.

http://hortonworks.com/

Cloudera

Cloudera Inc. is an American-based software company that provides Apache Hadoop-based software, support and services, and training to business customers.

Cloudera’s open-source Apache Hadoop distribution, CDH (Cloudera Distribution Including Apache Hadoop), targets enterprise-class deployments of that technology. Cloudera says that more than 50% of its engineering output is donated upstream to the various Apache-licensed open source projects (Apache Hive, Apache Avro, Apache HBase, and so on) that combine to form the Hadoop platform. Cloudera is also a sponsor of the Apache Software Foundation.

http://www.cloudera.com/content/cloudera/en/home.html

How to remove Unit production from CFG using JAVA

package cd;

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
/**
*
* @author Soham Navadiya
*/
public class Unit_Production {
static int caseCheck(String c){
if(c.matches(“[A-Z]”)){
return 1;
}
else if(c.matches(“[a-z]”)){
return 2;
}
else{
return 0;
}
}
public static void main(String []args) throws FileNotFoundException, IOException{

int check;
ArrayList<String> terminal=new ArrayList<String>();
ArrayList<String> nonterminal=new ArrayList<String>();

DataInputStream dis = new DataInputStream (new FileInputStream (“file/production.txt”));
byte[] datainBytes = new byte[dis.available()];
dis.readFully(datainBytes);
dis.close();
String content = new String(datainBytes, 0, datainBytes.length);
String input = content;

String lines[] = input.split(“\\r?\\n”);

Character [][]production=new Character[10][10];
int k=0;
ArrayList<Integer> len=new ArrayList<Integer>();
for(String i:lines){
len.add(i.length());
//System.out.println(“Production:”+i+”—Length: “+i.length());
for(int j=0;j<i.length();j++){
char[] chara=i.toCharArray();
production[k][j]=chara[j];
//System.out.print(production[k][j]);
}
//  System.out.println();
k++;

/*check=caseCheck(i);
if(check==1){
nonterminal.add(i);
System.out.println(“Non terminal: “+i);
}
else if(check==2){
terminal.add(i);
System.out.println(“Terminal: “+i);
}*/
}

for(int i=0;i<len.size();i++){
//System.out.print(“Length is: “+l+”\n”);
for(int j=0;j<len.get(i);j++){
// System.out.print(production[i][j]+”|”);
if(j==0){
check=caseCheck(production[i][j].toString());
if(check==1){
nonterminal.add(production[i][j].toString());
//System.out.println(“Non terminal is:” +production[i][j]);
}
}
}
}
String firstSubString = null;
String secondSubString;
for(int i=0;i<len.size();i++){

String ln2=lines[i].substring(0, lines[i].indexOf(“@”));
String ln=lines[i].substring(lines[i].lastIndexOf(“@”) + 1);

//System.out.println(“Left Part part is “+ln2);
//System.out.println(“Right part is”+ln);

if(ln.length()==1){
int h=check(ln,nonterminal);

if(h==0){
System.out.println(ln2+” @ “+ln);
}

if(h==1){

System.out.print(“Replace with “+ln2+” @ “);
//System.out.println(“Unit Production is “+ln);
//System.out.println(“Left Part part is “+ln2);

for(int p=0;p<len.size();p++){

String[] split = lines[p].split(“@”);

firstSubString = split[0];
secondSubString = split[1];

//char c=production[p][0];

if(firstSubString.equals(ln)){

System.out.println(secondSubString);
//System.out.println(“You have to Replace with “+secondSubString);

}
}
//System.out.println(“Left part is “+firstSubString);
//System.out.println(“Right part is “+secondSubString);
}

}
else{

System.out.println(ln2+” @ “+ln);
}

//  System.out.println();
}
// System.out.println(“After @ Length of String “+ln.length());
// System.out.println();
// System.out.println(“———–“);
/*
String example = “A@bCd”;
System.out.println(example.substring(example.lastIndexOf(“@”) + 1));
*/
}
static int check(String c,ArrayList<String> arr){
if(testAllUpperCase(c)){

if(arr.contains(c)){

return 1;
}
else
{
return 2;
}

}
else{
return 0;
}
}

public static boolean testAllUpperCase(String str){
for(int i=0; i<str.length(); i++){
char c = str.charAt(i);
if(c >= 97 && c <= 122) {
return false;
}
}
//str.charAt(index)
return true;
}
}

How to install Genymotion in Eclipse

Open Eclipse -> Help -> Install new Software –> write this url and install it then add path of installation in genymotion tab in preferances.

http://plugins.genymotion.com/eclipse/

What is Robotium?? How to learn it??

Robotium is a test framework created to make it easy to write powerful and robust automatic UI test cases for Android applications. With the support of Robotium, test case developers can write function, system and acceptance test scenarios, spanning multiple Android activities.

For beginner,

http://www.vogella.com/tutorials/Robotium/article.html

Protected: How to generate UML ( Class , Sequence ) Diagram from JAVA file or Project

This content is password protected. To view it please enter your password below:

Protected: Super not regarding JDBC

This content is password protected. To view it please enter your password below:

Unit Testing Principle and Feature

Unit testing work on only one object at a time.

Protected: Object oriented design interms of Programming ( Very usefull for develop the Efficient Software)

This content is password protected. To view it please enter your password below:

Use full Information regarding Regular Expression

In most regex dialects there are a set of convenient character summaries you can use for this kind of thing – these are good ones to remember:

\w – Matches any word character.

\W – Matches any nonword character.

\s – Matches any white-space character.

\S – Matches anything but white-space characters.

\d – Matches any digit.

\D – Matches anything except digits.

A search for “Regex Cheatsheets” should reward you with a whole lot of useful summaries.

What is Transaction in SQL???

A transaction is a single unit of work. If a transaction is successful, all of the data modifications made during the transaction are committed and become a permanent part of the database. If a transaction encounters errors and must be canceled or rolled back, then all of the data modifications are erased.

What is Context in android

In general term,

Context is the information surrounding the information. Without context, information can be misinterpreted; with context, information can be understood.

Context is a much-needed assistant, helping readers define unknown words and make sense of outside information.

IN android world,

Context represents environment data.

It provides access to things such as databases.

typically you call it to get information regarding another part of your program.

The Context class is an “Interface to global information about an application environment”.

Different invoking methods by which you can get context

  1. getApplicationContext()
  2. getContext()
  3. getBaseContext()
  4. this (when in the activity class) (“this” is the keyword of java and it refers to the context of the current activity)
     TextView TV=new TextView(this);

 

 

What is Data buffer?

In computer science, a data buffer (or just buffer) is a region of a physical memory storage used to temporarily store data while it is being moved from one place to another.

Buffers are often used in conjunction with I/O to hardware, such as disk drives, sending or receiving data to or from a network, or playing sound on a speaker.

What is Serialization?

Serialization is the process of translating data structures or object state into a format that can be stored (for example, in a file or memory buffer, or transmitted across a network connection link) and reconstructed later in the same or another computer environment.

What is GSON????

Gson (Google Gson) is an open source Java library to serialize and deserialize Java objects to (and from) JSON.

GSON is developed for internal purpose of Google ,After it is under the terms of Apache License 2.0.

For more tutorial: http://www.studytrails.com/java/json/java-google-json-introduction.jsp

http://www.javacodegeeks.com/2011/01/android-json-parsing-gson-tutorial.html

 

How to create short link of any URL.

Open www.google.com

Write https://goo.gl

Paste your URL here in this Page

Software Development Tips Web Application

  1. When you develop any database connectivity make sure connectivity should be in single place ,because it is easy to change when modification of connectivity is require.
  2. Add comment ,when important source code block is in web page.
  3. Maintain standard for variable name , static variable name.
  4. When you upload your site on server for testing male sure to create sub domain in your hosting site and create one ftp account and integrate with your dreamweaver
  5. For connect account to Dreamweaver ,refer this
  6.  https://helpx.adobe.com/dreamweaver/how-to/first-website-part6.html
  7. If you have problem to create new user in local server then open xampp shell and write
    mysql_upgrade
  8. Then create the new user , Select database –>privileges–>Add your server detail

Virtual School App Password Generator

This code is for Generate the system generated Password.

<?php

$password=”your password”;

echo “Password is :”.$password.”<br>”;
$ran=rand();
//echo $ran;
$salt = sha1($ran);

//echo “<br>”.$salt;
$salt = substr($salt, 0, 10);

//echo “<br>”.$salt.”<br>”;

$encrypted = base64_encode(sha1($password . $salt, true) . $salt);

//echo “Encrypted Password is :”.$encrypted;

$hash = array(“salt” => $salt, “encrypted” => $encrypted);

//Store in Database
$saltt=$hash[‘salt’];
echo $saltt;
$passwordt=$hash[‘encrypted’];
echo “<br>”.$passwordt;

$hash = base64_encode(sha1($password . $saltt, true) . $saltt);
if($hash==$passwordt)
{
echo “<br>Yes match found”;
}
else
{
echo “<br>Not found”;
}

// $uuid = uniqid(”, true);
//echo “<br>”.$uuid;

?>

Introduction Data Structure and Algorithm

What is Data Structure and Algorithm?????

In simple word,

Algorithm + Data Structure = Program

Algorithm: Method for solving problem.

Data Structure: Method for store Information.

Topics                                  data structure and algorithms

data types                            stack ,queue ,bag ,union-find ,priority queue

sorting                                  quicksort ,mergesort ,heapsort ,radix sort

searching                              BST ,red-black BST ,hash table

graphs                                   BFS ,DFS ,Prim ,Kruskal ,Dijkstra

strings                                  KMP ,regular expressiona ,TST ,Huffman ,LZW

advanced                             B-tree ,suffix ,array ,maxflowUntitled

 

JSON Practical scenario : 2

Target Format From Database:

[ 
{
  "hours":0
  "vulnerability":867
  "file":166
  "virus":59
}, 
{
  "hours":1
  "vulnerability":400
  "file":14
  "virus":40
}, 
]


eEcSC

 

Solution:

$output = array();

while ($row = mysql_fetch_assoc($result)) {
    $key = intval($row['hours']);
    if(!isset($output[$key])){
        $output[$key] = array('hours' => $key);
    }
    $output[$key][$row['subtype']] = intval($row['y']);
}

echo json_encode($output);

JSON Practical scenario : 1

  1. You have one table and two column.
  2. One column contain repeated data and second column contain different different  repeated data.
  3. Task is to write second column data as JSON array and First column data as JSON object.

Database Table:

Database

Output Like.

Output

Solution:

<?php
$con = mysql_connect(“localhost”,”root”,””);
if(!$con)
{
die(“Could Not connect”.mysql_error());
}
mysql_select_db(“virtual_school_app”,$con);

$tea_id=”15″;
$output=array();

$result=mysql_query(“SELECT DISTINCT `standard`,`division` FROM `timetable_teacher_detail` WHERE `Monday`=$tea_id”);
while ($row = mysql_fetch_assoc($result)) {
$key = $row[‘standard’];
$output[$key][] = $row[‘division’];
}
echo json_encode($output);
mysql_close($con);
?>

 

 

How work one dimensional array in JSON?

One dimensional scenario in JSON

How work two dimensional array in json?

Two dimensional scenario in JSON

JSON Introduction

Two main Parameter

  1. JSON Object  ,denoted as {  }
  2. JSON Array, denoted as [  ]

Create a free website or blog at WordPress.com.

Up ↑