Showing posts with label Open source. Show all posts
Showing posts with label Open source. Show all posts

Wednesday, 15 May 2013

Installing and configuring Dropbox on Linux server

Installation


The Dropbox daemon works fine on all 32-bit and 64-bit Linux servers. To install, run the following command in your Linux terminal.

32-bit:


cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86" | tar xzf -



64-bit:


cd ~ && wget -O - "https://www.dropbox.com/download?plat=lnx.x86_64" | tar xzf -



Next, run the Dropbox daemon from the newly created .dropbox-dist folder.


~/.dropbox-dist/dropboxd



If you're running Dropbox on your server for the first time, you'll be asked to copy and paste a link in a working browser to create a new account or add your server to an existing account. Once you do, your Dropbox folder will be created in your home directory.

Problem I Faced


I've got a Linux server running in Amazon AWS and OS is on a 10GB drive and I use a Amazon EBS drive attached for storage.

Now I wanted to set up Dropbox on this machine. But I haven't synched yet because there won't be enough room in my home dir. My /home is on my 10GB drive since I never use it and all my data is on the 2TB drive mounted in /media/.

What is the best way to set this up? Dropbox doesn't support moving the folder in Linux yet. I found a script to move the folder but it seems outdated. Perhaps I can use symlinks in some clever way? Or maybe move my /home folder to my SATA drive?

Solution


You gave the answer yourself, Use symlinks. Move your Dropbox folder to your HDD, then create a symlink in your home folder For example: ln -s /media/MyHDD/Dropbox /home/yourname/


Thanks for visting our blog.

Thursday, 25 April 2013

Awesome editor for any Scripting Language - Sub lime Text Editor

In Linux and Mac, most people use Vi editor and text editor for editing any scripting languages like shell, Python..etc,

This editor will be a bit complex and will not be handy to use.

One of my friend, A Linux enthusiast has introduced me a editor called "Sub Lime". 

This is an awesome text editor.  I found it very useful and handy. So thought of sharing it with you all.

Advantages of Sublime Text editor:

1. It gives auto suggestions for keywords and variables.

2. You can easily manage files and folders.

Steps to install :

sudo add-apt-repository ppa:webupd8team/sublime-text-2
sudo apt-get update
sudo apt-get install sublime-text

After installing you can type the following command to open it.

sudo sublime-text

You can also find this in the applications after installing.

Do easy programming....

Reference Link : http://ellislab.com/forums/viewthread/232759/

Here is the preview ....

sublime

Thursday, 11 April 2013

iOS UI Automation






Introduction / Overview

iPhone apps are developed using native or native-hybrid bridge.

native-hybrid : The datas are rendered in HTML and the native actions are performed using js callbacks

Automation testing framework for these applications is mainly to,

  • Reduce the manual testing effort

  • Reduce the testing cycles involved for any changes to the application

  • Provide maximum test coverage


images



Why UIAutomation ?


Selenium Automation

Using selenium the basic level functionalities like tapping, swiping could not be done in the iPhone app. so,selenium could not be an option to automate the iPhone app
Jasmine framework


  •     Jasmine is a BDD (Behavior Driven Development) framework.

  •     Jasmine is mainly used for Unit testing

  •     More or less jasmine is same as tuneup framework

  •    Jasmine provides good reporting structure

  •    Reports can be in xml or html format


UI Automation + tuneup.js


  •     It is the Apple's inbuilt Automation testing framework.

  •     It is highly stable and also reliable testing framework.

  •     It uses javascript to automate the testcases.

  •     Automation can also be performed in the specified devices

  •     It can also be accessible from command line so that we can also integrate this with Hudson

  •     Considering its salient features,simplicity UIAutomation is preferred for automating the test cases over other testing frameworks


Tools used



  •      Xcode IDE (Version 4.X and above)

  •      Instruments


Instruments Tool

Instruments is a tool for UIAutomation provided by Xcode. Instruments provides us the record and playback feature which will be very useful in doing automation

It can be used to collect data about the performance and behavior of one or more processes on the system and track that data over time.
Test Case Log

The test case when executed on the iOS application target, using Instruments,

The Instruments console will show the details of,

Log Message - What Test case is being executed

Log Type - Test case is Pass or Fail.

If a test case fails, it would display the

  •  Element tree in the failed page meaning, what are the UI elements present in the current page.

  •   Also the screen shot of the page in which error occured.


Automation Framework


Tune-up  is the framework used for automation

Tune-up is a collection of JavaScript utilities that builds upon and improves the UIAutomation library provided by Apple for testing iOS applications via Instruments.
You can find more details about the Tune-up framework from here:https://github.com/alexvollmer/tuneup_js/blob/master/README.md
an also in http://alexvollmer.com/posts/2010/07/03/working-with-uiautomation/

Test Structure in Tune-up


To create a test case, use the test() function, which takes the name of the test case as a string, and a function. The function will be given a UIATarget instance and a UIAApplication instance.

For example:


test("Sign In to the app", function(target, app) {

// The target and app arguments are root elements

/* (i.e) The element structure of every element in the app goes in this way
UIATarget.localTarget().frontMostApp().(position of the particular element in the view)
for reusing UIATarget.localTarget().frontMostApp() we store it in target,app   */

// The UIATarget is the primary portal into the application running on the device or simulator

// Steps for Sign-in

});

test("Sign out from the app", function(target, app) {

// Steps for Sign-out

});





Integrating with the Project



MakeFile configuration:


Configure the MakeFile which is in the project home , with the command lines which is used to build the project and Launch the instrument.

Add the following configuration,

1.TRACE_PATH : Location to store the .trace file, which will create after the execution of test script using instruments.

2.TEMPLATE_PATH : Location where the test case TemplateTrace files are stored, which is created from the instruments by saving the testSuite script as Template.

3.uiautomation :

Shell command which

  • Builds the project ,

  • Executes the test case script by launching the Instruments tool.

  • And this executes the test Suite which has the entire flow.


Ex.
/* Specify the Trace path, Template path and App path */












TRACE_PATH = TraceDocument/UIAutomationTrace

TEMPLATE_PATH = Test/Automation/Resources/TestCaseTemplates

APP_PATH = /Users/${projectpath}//Products/Debug-iphonesimulator/sample.app





/* Shell commands to Run the Test cases */












uiautomation:


    xcodebuild -workspace sample.xcworkspace -scheme Release -sdk iphonesimulator5.0


    instruments -t ${TEMPLATE_PATH}/testSuiteTemplate.tracetemplate -D ${TRACE_PATH} ${APP_PATH}





Running the Automation Script


Command to run automation from Terminal using the MakeFile ,

In Terminal ,Move to the directory where the ‘.xcodeproj‘ file resides

And execute the following Command,











make uiautomation





Additional Info about Shell Commands


Write a Shell Script to execute the following commands

1) Building the Project


At first the Project should be build through ‘xcodebuild’ command

xcodebuild:

This command is used to build the xcode project.

Xcodebuild Usage

Xcodebuild -- workspace [PROJECT-WORKSPACE] --scheme [SCHEME-NAME] --sdk [DEVICE/SIMULATOR NAME]




















Option Description
-- workspacePROJECT-WORKSPACE
Name of the Project file(ex sample.xcworkspace)
--schemeSCHEME-NAME
Name of the Sheme
--sdkSpecify the device/simulator name(ex: simulator name – iPhoneSimulator5.0)


Move to the directory where the ‘.xcodeproj‘ file resides and then the command Should be executed

Ex:

Move to the directory where the project resides

Execute the xcodebuild command

$bash: xcodebuild -workspace sample.xcworkspace -scheme Release -sdk iphonesimulator5.0

This command will build the project with configuration as release and sdk as iphone simulator5.0

2) Launching the Instruments tool


Execute a command to launch the Instrument with the latest build

This command executes the saved ‘.tracetemplate’ file and saves the result in the path specified
Instruments Command Usage

instruments [-t template] [-d document] [-w device] [-p pid] | [application [-e variable value ]]




































Options                                                 Description
-t     templateFile name of type ‘ .tracetemplate ‘ with the path of  the file location
-s     Show list of known templates and exit
-d     documentThe path to save the trace document data to (This may already exist, in which case
a new Run will be added)
-p     pidThe ID of the process to attach to
application     The path to the application or command to launch
-w     hardware deviceThe identifier of the hardware to target
-e     variable valueAn environment variable setting (You may specify more than one)


Ex :

       instruments -t $TEMPLATE_PATH -D $TRACE_PATH  $APP_PATH
























OptionDescriptionExample
TEMPLATE_PATHTemplate path is the path of the saved template file$PROJECT_HOME/Test/Automation/Resources/TestCaseTemplates/testSuite.tracetemplate
TRACE_PATHIt is the path where the .trace will be saved after executing the automation$PROJECT_HOME/TraceDocument/UIAutomationTrace
APP_PATHIt is the path of the latest build of the APP~/Library/Developer/Xcode/DerivedData/sample-gxfepasnjxtmhjcevjkpyunezjca/Build/Products/Debug-iphonesimulator/sample.app


Note: After the execution of the xcodebuild command the app will be build in a directory; APP_PATH should have that directory path

The Build path can be customized. To change the app build path, In  the Xcode Choose the Xcode option int the Menu bar choose Preferences – Locations and then give the custom location in the derived data field

On executing this command, the script loaded in the .tracetemplate file will get executed on the specified simulator/device and stores the .trace file in the specified path



Tuesday, 26 March 2013

GenericOptionsParser, Tool, and ToolRunner for running Hadoop Job

Hadoop comes with a few helper classes for making it easier to run jobs from the command line. GenericOptionsParser is a class that interprets common Hadoop command-line options and sets them on a Configuration object for your application to use as desired. You don’t usually use GenericOptionsParser directly, as it’s more convenient to implement the Tool interface and run your application with the ToolRunner, which uses GenericOptionsParser internally:
public interface Tool extends Configurable {
int run(String [] args) throws Exception;
}

Below example shows a very simple implementation of Tool, for running the Hadoop Map Reduce Job.
public class WordCountConfigured extends Configured implements Tool {
@Override
public int run(String[] args) throws Exception {
Configuration conf = getConf();

return 0;
}
}
public static void main(String[] args) throws Exception {
int exitCode = ToolRunner.run(new WordCountConfigured(), args);
System.exit(exitCode);
}

We make WordCountConfigured a subclass of Configured, which is an implementation of the Configurable interface. All implementations of Tool need to implement Configurable (since Tool extends it), and subclassing Configured is often the easiest way to achieve this. The run() method obtains the Configuration using Configurable’s getConf() method, and then iterates over it, printing each property to standard output.

WordCountConfigured’s main() method does not invoke its own run() method directly. Instead, we call ToolRunner’s static run() method, which takes care of creating a Configuration object for the Tool, before calling its run() method. ToolRunner also uses a GenericOptionsParser to pick up any standard options specified on the command line, and set them on the Configuration instance. We can see the effect of picking up the properties specified in conf/hadoop-localhost.xml by running the following command:
hadoop WordCountConfigured -conf conf/hadoop-localhost.xml -D mapred.job.tracker=localhost:10011 -D mapred.reduce.tasks=n

Options specified with -D take priority over properties from the configuration files. This is very useful: you can put defaults into configuration files, and then override them with the -D option as needed. A common example of this is setting the number of reducers for a MapReduce job via -D mapred.reduce.tasks=n. This will override the number of reducers set on the cluster, or if set in any client-side configuration files. The other options that GenericOptionsParser and ToolRunner support are listed in Table.

GenericOptionsParser and ToolRunner option Description



































Property>Description
-D property=valueSets the given Hadoop configuration property to the given value. Overrides any default or site properties in the configuration, and any properties set via the -conf option.
-conf filename ...Adds the given files to the list of resources in the configuration. This is a convenient way to set site properties, or to set a number of properties at once.
-fs uriSets the default filesystem to the given URI. Shortcut for -D fs.default.name=uri
-jt host:portSets the jobtracker to the given host and port. Shortcut for -D mapred.job.tracker=host:port
-files file1,file2,...Copies the specified files from the local filesystem (or any filesystem if a scheme is specified) to the shared filesystem used by the jobtracker (usually HDFS) and makes them available to MapReduce programs in the task’s working directory.
-archives archive1,archive2,...Copies the specified archives from the local filesystem (or any filesystem if a scheme is
specified) to the shared filesystem used by the jobtracker (usually HDFS), unarchives them, and makes them available to MapReduce programs in the task’s working directory.
-libjars jar1,jar2,...Copies the specified JAR files from the local filesystem (or any filesystem if a scheme is specified) to the shared filesystem used by the jobtracker (usually HDFS), and adds them to the MapReduce task’s classpath. This option is a useful way of shipping JAR files that a job is dependent on

Monday, 25 March 2013

Apache Ant - Tutorial

1. Build Tools
Build tools are used to automate the repetitive task like compiling source code, generating documentation, running tests, uilding the jar and so on. Some of the well known build tools are Apache Ant, Maven.


2. Overview of Ant

Ant(Another Neat Tool) is the java library and mostly used to building and deploying the java application. Ant provides the built-in tools to compile, build, test and packing the java application. Ant builds are based on three blocks.
Tasks: Task is the unit of work. For example compile, packing.
Targets: Targets can be invoked via Ant.
Extension Points: Extension points are same as targets and it won't any operation and just coordinate the targets.

3. Building the Java Application: Using Apache Ant

Create the build.xml(not as same) in your project root directory. Given below is the sample build xml(self explanatory - comments inline)
<?xml version="1.0" ?>
<project name="nRelate Analytics" >
<!-- Sets variables which can later be used. -->
<!-- The value of a property is accessed via ${} -->
<property name="src.dir" location="src" />
<property name="build.dir" location="build" />
<property name="dist.dir" location="dist" />
<property name="lib.dir" location="lib" />

<!--
Create a classpath container which can be later used in the ant task
-->
<path id="build.classpath">
<fileset dir="${lib.dir}">
<include name="**/*.jar" />
</fileset>
</path>

<!-- Deletes the existing build, dist directory-->
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
</target>

<!-- Creates the build, dist directory-->
<target name="makedir">
<mkdir dir="${build.dir}" />
<mkdir dir="${dist.dir}" />
</target>

<!-- Compiles the java code (including the usage of library -->
<target name="compile" depends="clean, makedir">
<javac srcdir="${src.dir}" destdir="${build.dir}" classpathref="build.classpath">
</javac>
</target>

<!--Creates the deployable jar file -->
<target name="createjar" depends="compile">
<jar destfile="${dist.dir}LogNormalizer.jar" basedir="${build.dir}">
<!-- Adding to Manifest file, from which class to start exceution -->
<manifest>
<attribute name="Main-Class" value="test.MainClass" />
</manifest>
</jar>
</target>
</project>

4) Run your Ant build from the command line

Open a command line and switch to your project directory. Type in the following commands.
# Run the build
ant -f build.xml
# build.xml is default you can also use
ant
Specify the target as below.
#Run the build.xml by specifying the target.
ant -f build.xml createjar

The build should finish successfully and generate the build artifacts under the dist directory.

Subscribe to get updates on this article.

Thursday, 14 February 2013

Writing MapReduce Program on Hadoop - Context

Map and Reduce

Map Reduce works by breaking the processing into two phases: Map phase and Reduce phase. Each phase has the key-value pair as input and type of key and value can be chosen by the programmer.

Data flow in the Map and Reduce:
Input ==> Map ==> Mapper Output ==> Sort and shuffle ==> Reduce ==> Final Output

Steps to Write the Hadoop Map Reduce in Java

Map Reduce program need three things: Map, Reduce and Some code to run job(Here we will call it as Invoker)

1). Create the Map(Any Name) class and map function was represented by org.apache.hadoop.mapreduce.Mapper.class which declares an abstract map() method.
[code lang="java"]import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class Map extends Mapper&lt;;LongWritable, Text, Text,IntWritable&gt; {
private final static IntWritable one = new IntWritable(1);
private Text word = new Text();
public void map(LongWritable key,Text value,Context context) throws IOException, InterruptedException {
word.set(value.toString());
context.write(word, one);
}
}

[/code]
Explanation:
The Mapper class is the generic class with four formal parameters(input key, input value, output key and output value). Here input key is LongWritable(Long representation by hadoop), input value is the Text(String representation by hadoop), output key is text(keyword) and output value is Intwritable(int representation by hadoop). All above hadoop datatypes are same as java datatype expect that are optimized for network serialization.

2). Create the Reducer(Any Name) class and reduce function was represented by org.apache.hadoop.mapreduce.Reducer.class which declares an abstract reduce() method.
[code lang="java"]import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;
import java.util.Iterator;

public class Reduce extends Reducer&lt;Text, IntWritable, Text,IntWritable&gt; {
@Override
protected void reduce(Text key, Iterable values, Context context) throws IOException, InterruptedException {
int sum = 0;
for(IntWritable intWritable : values){
sum += intWritable.get();
}
context.write(key, new IntWritable(sum));
}
}
[/code]
Explanation:
The Reducer class is the generic class with four formal parameters(input key, input value, output key and output value). Here input key and input value type must match with Mapper output, output key is text(keyword) and output value is Intwritable(number of occurence).

3) We are ready with Map and Reduce implementation, then we need to have the invoker for confguring the Hadoop job and invoke the Map Reduce program.
[code lang="java"]import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

public class WordCount{
public static void main(String[] args) throws Exception {
Configuration configuration = new Configuration();
configuration.set("fs.default.name", "hdfs://localhost:10011");
configuration.set("mapred.job.tracker","localhost:10012");

Job job = new Job(configuration, "Word Count");

job.setJarByClass(WordCount.class);
job.setMapperClass(Map.class);
job.setReducerClass(Reduce.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
job.setInputFormatClass(org.apache.hadoop.mapreduce.lib.input.TextInputFormat.class);
job.setOutputFormatClass(org.apache.hadoop.mapreduce.lib.output.TextOutputFormat.class);
FileInputFormat.addInputPath(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));

//Submit the job to the cluster and wait for it to finish.
System.exit(job.waitForCompletion(true) ? 0 : 1);
}
}
[/code]
4). Compile code by using following command
mkdir WordCount
javac -classpath ${HADOOP_HOME}/hadoop-0.20.2+228-core.jar -d WordCount path/*.java

5). Create the jar by using command
jar -cvf ~/WordCount.jar -C WordCount/ .

6). Create the input file in the local file system

Eg : mkdir /home/user1/wordcount/input
cd /wordcount/input
gedit file01
gedit file02

and so on..

7). Copy the input file in local file system to HDFS
$HADOOP_HOME/bin/hadoop fs -cp ~/wordcount/input/file01 /home/user1/dfs/input/file01
$HADOOP_HOME/bin/hadoop fs -cp ~/wordcount/input/file02 /home/user1/dfs/input/file02

8). Execute the jar as follows:
$HADOOP_HOME/bin/hadoop jar WordCount.jar WordCount /home/user1/dfs/input /home/user1/dfs/output

9). After execution get completed, below set of commands is used to view the reduce file that are generated
$HADOOP_HOME/bin/hadoop fs -ls /home/user1/dfs/output/

10). To view the output, use this below given command
$HADOOP_HOME/bin/hadoop fs -cat hdfs:///home/user1/dfs/output/part-00000
$HADOOP_HOME/bin/hadoop fs -cat hdfs:///home/user1/dfs/output/part-00001
$HADOOP_HOME/bin/hadoop fs -cat hdfs:///home/user1/dfs/output/part-00002

and so on...

Upcoming Post: Using Distributed Cache in Java Hadoop MapReduce.

Thursday, 24 January 2013

Recovering corrupted files in Linux

There are many compression technique that you use and compress a file in Linux.

Few techniques are gzip, tar and lot more.

At times when you decompress/uncompress a file after a long time you may get few errors like.

"Unexpected EOF." "Files not in gzip format" or "Files not in gz format" something like this.

This is because the files may be corrupted.

There is a recovery tool kit and it is mainly for gzip but this can also be used for tar.gz too.

STEPS FOR RECOVERY :

Go to the link http://www.urbanophile.com/arenn/coding/gzrt/

And click on the gzrt-0.6.tar.gz link, then gzrt-0.6.tar.gz file will be downloaded to your machine.

Go to the specified location and do the following.

$ tar -xzvf gzrt-0.6.tar.gz
$ cd gzrt-0.6
$ make

Then copy the corrupted file to this folder and execute the following command.

$./gzrecover ABC.gz

Then the recovered file will be in the name of ABC.recovered

Hence there is no problem in dealing with corrupted files in Linux any more. :)

Tuesday, 22 January 2013

Downloading videos in Linux

There is a simple software (clip grab) that allows you to download online videos in Linux.

Execute the following commands in your terminal.

############################

sudo add-apt-repository ppa:clipgrab-team/ppa

sudo apt-get update

sudo apt-get install clipgrab

##########################

The software is now installed , to run the software execute the following command

#############

clipgrab

################

Steps to download :

1. Go to the "SETTINGS" tab in the GUI of Clip grab and mention the destination path where you need to save the video.

2. Then under downloads tab, Paste the web-link from which u want to download the video.

3. Click the "grab this clip" button.

The video will start getting downloaded in the specified destination.

Monday, 5 July 2010

Firebug a gift for WebDevelopers

Firebug is a firefox plugin, which converts a simple browsers into a powerful debugging tool. When I doing my project for college i came across the term Firebug. The day i found firebug, I was just thinking why it didn’t come to my sight all these days when i was surfing the net.

Firebug, gives so many reasons for a web developer to use it. May be let me list in what all ways Firebug helped me

1. It was very hard to find the bugs in Java Script. Most of the time if there is a syntax error, the code would not respond, Firebug often helps me in tracking the bug in the Java script.
2. Tracing through the HTML code. When you keep your mouse on each HTML, tag below Firebug will highlight the content at the top of the screen. It would be so helpful to trace, which part of the HTML creates a particular segment.
3. Then it can also trace CSS. Most commonly when you are trying to edit a template to create you website. Firebug when play a greater role in it.
4. I don’t think its over, but I am using Firebug for all these, still very often it gets updated with new features added.

Firefox is the Browser that i really love and the two plugins Delicious and Firebug have become my intimate these days, helping me every moment.