<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Abhijit Gaikwad &#124; Abhijit Gaikwad</title>
	<atom:link href="http://gabhi.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://gabhi.com</link>
	<description>Software Developer</description>
	<lastBuildDate>Tue, 30 Apr 2013 04:53:39 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Deploying Locally to Mac OS X with Capistrano</title>
		<link>http://gabhi.com/deploying-locally-to-mac-os-x-with-capistrano/</link>
		<comments>http://gabhi.com/deploying-locally-to-mac-os-x-with-capistrano/#comments</comments>
		<pubDate>Tue, 30 Apr 2013 04:53:39 +0000</pubDate>
		<dc:creator>Abhijit Gaikwad</dc:creator>
				<category><![CDATA[Questions]]></category>

		<guid isPermaLink="false">http://gabhi.com/?p=1550</guid>
		<description><![CDATA[Deploying Locally to Mac OS X with Capistrano Lately I&#8217;ve wanted to deploy locally to my mac using Capistrano. Not for actual deployment locally, but to test some custom tasks I was working on. Its a lot quicker and safer to run custom tasks against a local sandbox then some &#8230;]]></description>
				<content:encoded><![CDATA[<div id="content">
<h2>Deploying Locally to Mac OS X with Capistrano</h2>
<p>Lately I&#8217;ve wanted to deploy locally to my mac using Capistrano. Not for actual deployment locally, but to test some custom tasks I was working on. Its a lot quicker and safer to run custom tasks against a local sandbox then some real server somewhere. Writing real tests for custom tasks is basically too difficult to be worth it, so testing locally is probably the least crummy option right now. Another side benefit of testing locally is the speed and removing the need for a net connection.</p>
<p>So out of the box, this won&#8217;t work:</p>
<pre><code>  role :app, "localhost"
  role :web, "localhost"
  role :db, "localhost"

  cap my_custom_task
</code></pre>
<p>For one thing, mac&#8217;s don&#8217;t have sshd (the ssh server) running by default. So first do that &#8211; go to System Preferences -&gt; Sharing -&gt; and enable &#8220;Remote Login&#8221;. That should start the ssh daemon.</p>
<p>Now if you deploy, Capistrano should be able to login but you may run into path issues, especially if you want to use gems in a custom task. If you just want to use a very basic task locally, you might be okay here &#8212; but if you see &#8216;command not found&#8217; or missing libraries, you probably need to keep reading.</p>
<p>Capistrano runs SSH over a non-interactive shell, and by default you have an empty environment when logged into a OS X non-interactively via SSH. To fix that, open up /etc/sshd_config in your favorite text editor. Change the following:</p>
<pre><code>PermitUserEnvironment yes</code></pre>
<p>This will allow you to set the environment in your home .ssh folder. Before you leave that file, also find these directives and make the following changes for security:</p>
<pre><code>PermitRootLogin no
Protocol 2
AllowUsers [username here]
</code></pre>
<p>This will turn off root login, allow only the more recent version of ssh, and explicitly allow only the one username you&#8217;ll be using. If you want to lock it down even more you should set the port to something much higher then 22, turn off password auth, and setup keys with good pass phrases. My mac is behind a router most of the time anyways, so I&#8217;m not going to worry about it. If you have a password of &#8216;password&#8217; or something similiar for the account you are using, you should <strong>definitely</strong> make that stronger.</p>
<p>Now, create a file for you local ssh environment.</p>
<pre><code>mate ~/.ssh/environment # or vi, or nano, etc...</code></pre>
<p>&nbsp;</p>
<p>Now add a PATH statement to that file like the following:</p>
<pre><code>PATH=/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/local/lib:opt/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
RUBYOPT=rubygems</code></pre>
<p>You&#8217;ll probably want the /usr/local and /opt/local (for MacPorts) stuff ahead of /usr/bin so that if you use Ruby or Rubygems in your tasks, the non-broken version you installed yourself will get used. After saving that file, go back to the system preferences and turn off ssh (remote login) and turn it back on again to pick up all changes. Now you can run any custom task against your localhost, and it should work pretty much like a typical linux box, assuming you&#8217;ve installed everything locally that your have remote.</p>
<p>If you still have issues, create a simple task like so:</p>
<pre><code>task(:debug_env) { run "env" }</code></pre>
<p>Run that locally and then run it remotely to see the differences in your environment, and hopefully that will reveal something missing from your path or maybe some env variable you need.</p>
<p>This was all done with Capistrano 1.4.1, as I haven&#8217;t taken the plunge into the new version 2 yet.</p>
<p>&nbsp;</p>
<div>source:http://robsanheim.com/2007/05/10/making-capistrano-deploy-to-mac-os-x/</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://gabhi.com/deploying-locally-to-mac-os-x-with-capistrano/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Capistrano</title>
		<link>http://gabhi.com/capistrano/</link>
		<comments>http://gabhi.com/capistrano/#comments</comments>
		<pubDate>Tue, 30 Apr 2013 03:45:46 +0000</pubDate>
		<dc:creator>Abhijit Gaikwad</dc:creator>
				<category><![CDATA[Questions]]></category>

		<guid isPermaLink="false">http://gabhi.com/?p=1546</guid>
		<description><![CDATA[Table of Contents Introduction How to Install Capistrano Prepare your Project for Capistrano Working with Capistrano Recipes Tips &#38; Tricks Further Reading Introduction Capistrano is a Ruby program that gives you a set of advanced tools to deploy web applications to your servers. In its simplest form, Capistrano allows you to &#8230;]]></description>
				<content:encoded><![CDATA[<h2>Table of Contents<a title="Show detailed TOC" href="http://guides.beanstalkapp.com/deployments/deploy-with-capistrano.html#"><br />
</a></h2>
<ul>
<li><a href="http://guides.beanstalkapp.com/deployments/deploy-with-capistrano.html#introduction">Introduction</a></li>
<li><a href="http://guides.beanstalkapp.com/deployments/deploy-with-capistrano.html#install-capistrano">How to Install Capistrano</a></li>
<li><a href="http://guides.beanstalkapp.com/deployments/deploy-with-capistrano.html#prepare-project">Prepare your Project for Capistrano</a></li>
<li><a href="http://guides.beanstalkapp.com/deployments/deploy-with-capistrano.html#capistrano-recipes">Working with Capistrano Recipes</a></li>
<li><a href="http://guides.beanstalkapp.com/deployments/deploy-with-capistrano.html#tips">Tips &amp; Tricks</a></li>
<li><a href="http://guides.beanstalkapp.com/deployments/deploy-with-capistrano.html#further-reading">Further Reading</a></li>
</ul>
<div itemprop="articleBody">
<h2 id="introduction">Introduction</h2>
<p><a href="http://www.capistranorb.com/">Capistrano</a> is a Ruby program that gives you a set of advanced tools to deploy web applications to your servers. In its simplest form, Capistrano allows you to copy code from your source control repository (<abbr title="Subversion">SVN</abbr> or Git) to your server via <abbr title="Secure Shell">SSH</abbr>, and perform pre and post-deploy functions like restarting a webserver, busting cache, renaming files, running database migrations and so on. With Capistrano it’s also possible to deploy to many machines at once.</p>
<p>Capistrano offers many advanced options that won’t be covered in this guide, and can be used to deploy many kinds of applications. For learning purposes, we will take you through the steps to setup a simple recipe for deploying a Rails application to a single server from either <abbr title="Subversion">SVN</abbr> or Git repositories. We will cover a common workflow that allows you to deploy multiple environments: in this case, staging and production.</p>
<h2 id="install-capistrano">How to Install Capistrano</h2>
<p>In order to install Capistrano you will need Ruby and RubyGems installed on your computer. If you’re on a Mac running OS X 10.5+, you’re ready to go. If not, you can use this reference to <a title="Download Ruby on Rails" href="http://rubyonrails.org/download">learn how to install Ruby and RubyGems</a>.</p>
<p>Then, run the following command from a Terminal or command line:</p>
<pre><code>gem install capistrano</code></pre>
<p>For this guide, we recommend the handy <b>capistrano-ext</b> gem that contains an extra set of tools to make your deployments even easier:</p>
<pre><code>gem install capistrano-ext</code></pre>
<p>If you’re having trouble or would like more detailed documentation, you might want to reference the official Capistrano <a href="https://github.com/capistrano/capistrano/wiki/2.x-Getting-Started">getting started guide</a>, or <a href="https://github.com/capistrano/capistrano/wiki/2.x-From-The-Beginning">find out more about the various components</a> that make Capistrano work.</p>
<h3 id="server-dependencies">Server Dependencies</h3>
<p>It’s important to make sure that your server is <abbr>POSIX</abbr>-compilant and has <abbr title="Secure Shell">SSH</abbr> access. Don’t forget to setup your <abbr title="Secure Shell">SSH</abbr> keys (<a href="http://guides.beanstalkapp.com/version-control/git-on-mac.html#creating-ssh-keys">Mac</a> or <a href="http://guides.beanstalkapp.com/version-control/git-on-windows.html#installing-ssh-keys">Windows</a>). If you can’t <abbr title="Secure Shell">SSH</abbr> into your server, Capistrano isn’t going to work for you.</p>
<h2 id="prepare-project">Prepare your Project for Capistrano</h2>
<p>Navigate to your application’s root directory in Terminal and run the following command:</p>
<pre><code>capify .</code></pre>
<p>This command creates a special file called <code>Capfile</code> in your project, and adds a template deployment recipe at <code>config/deploy.rb</code> in your Rails project. The <code>Capfile</code> helps Capistrano load your recipes and libraries properly, but you don’t need to edit it for now.</p>
<p>Instead, open the <code>deploy.rb</code> file in your favorite text editor. This file is where all the magic happens! You can start by deleting everything in the template file, as this guide will help you fill it with the correct code for a successful deployment recipe.</p>
<h2 id="capistrano-recipes">Working with Capistrano Recipes</h2>
<h3 id="recipe-create">How to Create a Capistrano Recipe</h3>
<p>In your now-empty <code>deploy.rb</code> file, let’s enter the name of your app in the first line. If your app’s name is “fancy shoes”, you’d type:</p>
<pre><code>set :application, "fancy_shoes"</code></pre>
<p>Now let’s add a repository to access. Git users can add this:</p>
<pre><code>set :scm, :git
set :repository, "git@account.beanstalkapp.com:/repository.git"
set :scm_passphrase, ""</code></pre>
<p>And Subversion users can use this:</p>
<pre><code>set :scm, :subversion
set :repository, "https://account.svn.beanstalkapp.com/repository"</code></pre>
<p>Additionally let’s set the user on our server that we want Capistrano to run commands with:</p>
<pre><code>set :user, "server-user-name"</code></pre>
<p>Make sure that this user has read &amp; write access to the directory that you specified in the <var>deploy_to</var>variable.</p>
<p>Before you go further, try connecting to that repository by hand from your Terminal (try an <code>svn co</code> or<code>git clone</code>), to make sure that you can authenticate properly. If you can’t connect to the repository, neither can Capistrano.</p>
<p>Next we’ll add information about your server to the recipe. We will be using the <b>Capistrano Multistage</b>function (it comes along with the gem <b>capistrano-ext</b> we installed earlier). This allows you to setup one recipe to deploy your code to more than one location. In this example, we’ll deploy to staging and production environments.</p>
<p>Begin by including multistage at the top of your <code>deploy.rb</code> file:</p>
<pre><code>require 'capistrano/ext/multistage'</code></pre>
<p>Then specify your environments, or “stages”:</p>
<pre><code>set :stages, ["staging", "production"]
set :default_stage, "staging"</code></pre>
<p>Since you will likely be deploying to staging more often than production, we find that it’s helpful to make staging the default stage. Next, create a directory called <code>deploy</code> inside your app’s <code>config</code> directory, and then add <code>production.rb</code> and <code>staging.rb</code> files to it. You’ll need one Ruby file per stage you’ve configured, and they need to be named the same so that Capistrano can load the appropriate files when you specify which stage you want to deploy.</p>
<p>Now let’s populate our <code>production.rb</code> settings:</p>
<pre><code>server "my_fancy_server.com", :app, :web, :db, :primary =&gt; true
set :deploy_to, "/var/www/fancy_shoes"</code></pre>
<p>And then <code>staging.rb</code>:</p>
<pre><code>server "my_fancy_server.com", :app, :web, :db, :primary =&gt; true
set :deploy_to, "/var/www/fancy_shoes_staging"</code></pre>
<p>In this example, we have only one server being assigned all three roles (app, web and db). The difference between production and staging is in the different <var>deploy_to</var> directory variables. In reality you might want to use different servers too.</p>
<h3 id="recipe-validate">Validating your Recipe</h3>
<p>Everything is ready to try our recipe for the first time and let Capistrano create the initial directory structure on your server for future deployments. Run the following command from the root directory of your application:</p>
<pre><code>cap deploy:setup</code></pre>
<p>When you run this command, Capistrano will <abbr title="Secure Shell">SSH</abbr> to your server, enter the directory that you specified in the <var>deploy_to</var> variable, and create a special directory structure that’s required for Capistrano to work properly. If something is wrong with the permissions or <abbr title="Secure Shell">SSH</abbr> access, you will get error messages. Look closely at the output Capistrano gives you while the command is running.</p>
<p>The last step before we can do an actual deployment with Capistrano is to make sure that everything is set up correctly on the server from the setup command. There’s a simple way to verify, with the command:</p>
<pre><code>cap deploy:check</code></pre>
<p>This command will check your local environment and your server and locate likely problems. If you see any error messages, fix them and run the command again. Once you can run <code>cap deploy:check</code>without errors, you can proceed!</p>
<h3 id="deploy">Deploy Using your New Recipe</h3>
<p>Once you’ve verified your local and server configuration, run the following command:</p>
<pre><code>cap deploy</code></pre>
<p>This will perform a deployment to your default stage, which is staging. If you want to deploy to production, you’d run the following:</p>
<pre><code>cap production deploy</code></pre>
<p>While these commands are performed, you will see a lot of output. Capistrano print all commands it runs on your server as well as their output, making it possible for you to debug any problems.</p>
<h2 id="tips">Tips &amp; Tricks</h2>
<h3 id="improve-performance">Improve Performance with Remote Cache</h3>
<p>The way Capistrano works, it will create a new clone/export of your repository on every deploy. That can be slow, so there’s an option to add some extra commands to our <code>deploy.rb</code> recipe to speed things up. Add the following to the section of your <code>deploy.rb</code> where you describe your <var>scm</var> settings:</p>
<pre><code>set :deploy_via, :remote_cache</code></pre>
<p>This command makes Capistrano do a single clone/checkout of your repository on your server the first time, then do an <code>svn up</code> or <code>git pull</code> on every deploy instead of doing an entire clone/export. If you deploy often, you’ll notice that this speeds up your deployments significantly.</p>
<h3 id="deploy-hooks">Add Custom Deploy Hooks</h3>
<p>Capistrano shines by doing things more sophisticated than just copying files via <abbr title="Secure Shell">SSH</abbr>. You can configure events and commands to run after the copying of files completes, such as restart a web-server or run a custom script. Capistrano calls these “tasks”. For an example, add the following code to your<code>deploy.rb</code> file:</p>
<pre><code>namespace :deploy do
  task :restart, :roles =&gt; :web do
    run "touch #{ current_path }/tmp/restart.txt"
  end

  task :restart_daemons, :roles =&gt; :app do
    sudo "monit restart all -g daemons"
  end
end</code></pre>
<p>Tasks in Capistrano are very powerful, and we’re only scratching the surface in this guide. You can create tasks to perform operations on your server before, after or separately from your deployment. This can be any sort of maintenance: restarting processes, cleaning up files, sending email notifications, running database migrations, executing scripts, and so on.</p>
<p>Our example includes two custom tasks. The “restart” task is built into Capistrano and will be executed by Capistrano automatically after your deployment is complete. We use the <code>touch tmp/restart.txt</code>technique that’s common to modern Rails applications powered by Passenger, but your webserver may require a different command.</p>
<p>Our second example task is &#8220;restart_daemons&#8221;, a custom task that Capistrano won’t run by default. We need to add a hook for it in order for it to run:</p>
<pre><code>after "deploy", "deploy:restart_daemons" </code></pre>
<p>This command tells Capistrano to execute our task after all deploy operations are complete. Other hooks are available, including “before” which runs the task before the files are copied.</p>
<p>You can read more about before and after hooks in the official Capistrano documentation:</p>
<ul>
<li><a href="https://github.com/capistrano/capistrano/wiki/2.x-DSL-Configuration-Tasks-Before">Before Tasks</a></li>
<li><a href="https://github.com/capistrano/capistrano/wiki/2.x-DSL-Configuration-Tasks-After">After Tasks</a></li>
</ul>
<h3 id="deploy-git-branches">Associate Git Branches With Environments</h3>
<p>Since we have two server environments (staging and production) most likely you will want to bind your branches in Git to these environments, so that you can deploy staging branch to staging environment and master branch to production automatically. Simply add the following line to your <code>production.rb</code>:</p>
<pre><code>set :branch, 'production'</code></pre>
<p>And the following line to <code>staging.rb</code>:</p>
<pre><code>set :branch, 'staging'</code></pre>
<p>Now every time you run a <code>cap deploy</code> Capistrano will deploy code from your staging branch (since staging is our default environment). If you run <code>cap production deploy</code> Capistrano will deploy code from your master branch. Easy peasy!</p>
<h2 id="further-reading">Further Reading</h2>
<p>Hopefully our guide was helpful for you as an initial kick-start. You will definitely want to read more, so we suggest you to go to the <a href="https://github.com/capistrano/capistrano/wiki">official wiki of Capistrano</a> and read. You can start with their awesome <a href="https://github.com/capistrano/capistrano/wiki/2.x-From-The-Beginning">From The Beginning</a> article.</p>
<p>&nbsp;</p>
<p>Source:http://guides.beanstalkapp.com/deployments/deploy-with-capistrano.html</p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://gabhi.com/capistrano/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>install Broadleaf Commerce on Mac</title>
		<link>http://gabhi.com/install-broadleaf-commerce-on-mac/</link>
		<comments>http://gabhi.com/install-broadleaf-commerce-on-mac/#comments</comments>
		<pubDate>Fri, 26 Apr 2013 04:21:00 +0000</pubDate>
		<dc:creator>Abhijit Gaikwad</dc:creator>
				<category><![CDATA[Questions]]></category>

		<guid isPermaLink="false">http://gabhi.com/?p=1543</guid>
		<description><![CDATA[Clone from Git repository https://github.com/BroadleafCommerce/DemoSite Open repository in Eclipse goto Terminal and root folder of demo site and run mvn clean install Add ant files to Ant in Eclipse Start the db using one of the task in the Ant Start either admin or demo or combined sites by launching the &#8230;]]></description>
				<content:encoded><![CDATA[<ol>
<li>Clone from Git repository https://github.com/BroadleafCommerce/DemoSite</li>
<li>Open repository in Eclipse</li>
<li>goto Terminal and root folder of demo site and run mvn clean install</li>
<li>Add ant files to Ant in Eclipse</li>
<li>Start the db using one of the task in the Ant</li>
<li>Start either admin or demo or combined sites by launching the jetty-demo task</li>
<li>access admin via localhost:8081/admin</li>
<li>access home via localhost:8080</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://gabhi.com/install-broadleaf-commerce-on-mac/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>install hadoop (1.0.4) on Mac os single node</title>
		<link>http://gabhi.com/install-hadoop-on-mac-os-single-node/</link>
		<comments>http://gabhi.com/install-hadoop-on-mac-os-single-node/#comments</comments>
		<pubDate>Thu, 25 Apr 2013 22:29:38 +0000</pubDate>
		<dc:creator>Abhijit Gaikwad</dc:creator>
				<category><![CDATA[Questions]]></category>

		<guid isPermaLink="false">http://gabhi.com/?p=1533</guid>
		<description><![CDATA[Step 1: Creating a designated hadoop user on your system This isn&#8217;t -entirely- necessary, but it&#8217;s a good idea for security reasons. To add a user, go to: System Preferences &#62; Accounts Click the &#8220;+&#8221; button near the bottom of the account list. You may need to unlock this ability by &#8230;]]></description>
				<content:encoded><![CDATA[<h2 id="Step_1:_Creating_a_designated_hadoop_user_on_your_system">Step 1: Creating a designated hadoop user on your system</h2>
<p>This isn&#8217;t -entirely- necessary, but it&#8217;s a good idea for security reasons. To add a user, go to:</p>
<pre>System Preferences &gt; Accounts</pre>
<p>Click the &#8220;+&#8221; button near the bottom of the account list. You may need to unlock this ability by hitting the lock icon at the bottom corner and entering the admin username and password.</p>
<p>When the New account window comes out enter a name, as short name and a password. I entered the following:</p>
<pre>Name: hadoop
Short name: Hadoop
Password: MyPassword (well you get the idea)</pre>
<p>Once you are done, hit &#8220;create account&#8221;. Now, log in as the hadoop user. You are ready to set up everything!</p>
<h2 id="Step_2:_Install.2BAC8-Configure_Preliminary_Software">Step 2: Install/Configure Preliminary Software</h2>
<p>Before installing Hadoop, there are a couple things that you need make sure you have on your system.</p>
<ol type="1">
<li>Java, and the latest version of the JDK</li>
<li>SSH</li>
</ol>
<p>Because OS X is awesome, you actually don&#8217;t have to install these things. However, you will have to enable and update what you have. Let&#8217;s start with Java:</p>
<h3 id="Updating_Java">Updating Java</h3>
<p>Open up the Terminal application. If it&#8217;s not already on your dock, you can access it through</p>
<pre>Applications &gt; Utilities &gt; Terminal</pre>
<p>Next check to see the version of Java that&#8217;s currently available on the system:</p>
<pre>$:~ java -version
java version "1.5.0_13"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_13-b05-237)
Java HotSpot(TM) Client VM (build 1.5.0_13-119, mixed mode, sharing)</pre>
<p>You may want to update this to Java Sun 6, which is available as an update for OS X 10.5 (Update 1). It&#8217;s currently only available for 64-bit machines though. You can download it <a href="http://www.apple.com/support/downloads/javaformacosx105update1.html">here</a>.</p>
<p>After you download and install the update, you are going to need to configure Java on your system so the default points to this new update.Go to:</p>
<pre>Applications &gt; Utilities &gt; Java &gt; Java Preferences</pre>
<p>Under &#8220;Java Version&#8221; hit the radio button next to &#8220;Java SE 6&#8243; Down by &#8220;Java Application Runtime Settings&#8221; change the order so Java SE 6 (64 bit) is first, followed by Java SE 5 (64 bit) and so on. Hit &#8220;Save&#8221; and close this window.</p>
<p>Now, when you go to the terminal, and type in &#8220;java -version&#8221; you should get the following:</p>
<pre>$:~ java -version

java version "1.6.0_43"</pre>
<p><em id="__mceDel">Java(TM) SE Runtime Environment (build 1.6.0_43-b01-447-10M4203)<br />
Java HotSpot(TM) 64-Bit Server VM (build 20.14-b01-447, mixed mode)</em></p>
<pre></pre>
<p>&nbsp;</p>
<p>Onto ssh!</p>
<h3 id="SSH:_Setting_up_Remote_Desktop_and_Enabling_Self-Login">SSH: Setting up Remote Desktop and Enabling Self-Login</h3>
<p>SSH also comes installed on your Mac. However, you need to enable access to your own machine (so hadoop doesn&#8217;t ask you for a password at inconvenient times). To do this, go to</p>
<pre>System Preferences &gt; Sharing (under Internet &amp; Network)</pre>
<p>Under the list of services, check &#8220;Remote Login&#8221;. For extra security, you can hit the radio button for &#8220;Only these Users&#8221; and select <strong>hadoop</strong></p>
<p>Now, we&#8217;re going to configure things so we can log into localhost without being asked for a password. Type the following into the terminal:</p>
<pre>$:~ mkdir .ssh
$:~ ssh-keygen -t rsa -P ""
$:~ cat $HOME/.ssh/id_rsa.pub &gt;&gt; $HOME/.ssh/authorized_keys</pre>
<p>Now try:</p>
<pre>$:~ ssh localhost</pre>
<p>You should be able to log in without a problem.</p>
<p>You are now ready to install Hadoop. Let&#8217;s go to step 3!</p>
<h2 id="Step_3:_Downloading_and_Installing_Hadoop">Step 3: Downloading and Installing Hadoop</h2>
<p>So this actually involves a few smaller steps:</p>
<ol type="1">
<li>Downloading and Unpacking Hadoop</li>
<li>Configuring Hadoop</li>
</ol>
<p>After we finish these, you should be ready to go! So let&#8217;s get started:</p>
<h3 id="Downloading_and_Unpacking_Hadoop">Downloading and Unpacking Hadoop</h3>
<p><a href="http://hadoop.apache.org/core/releases.html">Download</a> Hadoop. Make sure you download the latest version (as of this post, 1.0.4 are the latest versions). We call our generic version of hadoop hadoop-* in this tutorial.</p>
<p>Unpack the hadoop-*.tar.gz in the directory of your choice. I placed mine in /Users/hadoop. You may also want to set ownership permissions for the directory:</p>
<pre>$:~ tar -xzvf hadoop-*.tar.gz 
$:~ chown -R hadoop hadoop-*</pre>
<h3 id="Configuring_Hadoop">Configuring Hadoop</h3>
<p>There are two files that we want to modify when we configure Hadoop. The first is conf/hadoop-env.sh . Open this in nano or your favorite text editor and do the following:</p>
<p>- uncomment the export JAVA_HOME line and set it to /Library/Java/Home</p>
<p>- uncomment the export HADOOP_HEAPSIZE line and keep it at 2000</p>
<p>You may want to change other settings as well, but I chose to leave the rest of hadoop-env.sh the same. Here is an idea of what part of mine looks like:</p>
<pre># Set Hadoop-specific environment variables here.

# The only required environment variable is JAVA_HOME.  All others are
# optional.  When running a distributed configuration it is best to
# set JAVA_HOME in this file, so that it is correctly defined on
# remote nodes.

# The java implementation to use.  Required.
 export JAVA_HOME=/Library/Java/Home

# Extra Java CLASSPATH elements.  Optional.
# export HADOOP_CLASSPATH=

# The maximum amount of heap to use, in MB. Default is 1000.
 export HADOOP_HEAPSIZE=2000</pre>
<p>The next part that we need to set up is hadoop-site.xml. The most important parts to set here are hadoop.tmp.dir (which should be set to the directory of your choice) and to add mapred.tasktracker.maximum property to the file. This will effectively set the maximum number of tasks that can simulataneously run by a task tracker. You should also set dfs.replication &#8216;s value to one.</p>
<p>Below is a sample core-site.xml file:</p>
<pre>&lt;?xml version="1.0"?&gt;
&lt;?xml-stylesheet type="text/xsl" href="configuration.xsl"?&gt;

&lt;!-- Put site-specific property overrides in this file. --&gt;

&lt;configuration&gt;

&lt;property&gt;
  &lt;name&gt;hadoop.tmp.dir&lt;/name&gt;
  &lt;value&gt;/Users/hadoop/hadoop-1.0.4/hadoop-${user.name}&lt;/value&gt;
  &lt;description&gt;A base for other temporary directories.&lt;/description&gt;
&lt;/property&gt;

&lt;property&gt;
  &lt;name&gt;fs.default.name&lt;/name&gt;
  &lt;value&gt;hdfs://localhost:9000&lt;/value&gt;
  &lt;description&gt;The name of the default file system.  A URI whose
  scheme and authority determine the FileSystem implementation.  The
  uri's scheme determines the config property (fs.SCHEME.impl) naming
  the FileSystem implementation class.  The uri's authority is used to
  determine the host, port, etc. for a filesystem.&lt;/description&gt;
&lt;/property&gt;

&lt;property&gt;
  &lt;name&gt;mapred.job.tracker&lt;/name&gt;
  &lt;value&gt;localhost:9001&lt;/value&gt;
  &lt;description&gt;The host and port that the MapReduce job tracker runs
  at. If "local", then jobs are run in-process as a single map
  and reduce task.
  &lt;/description&gt;
&lt;/property&gt;

&lt;property&gt;
&lt;name&gt;mapred.tasktracker.tasks.maximum&lt;/name&gt;
&lt;value&gt;8&lt;/value&gt;
&lt;description&gt;The maximum number of tasks that will be run simultaneously by a
a task tracker
&lt;/description&gt;
&lt;/property&gt;

&lt;property&gt;
  &lt;name&gt;dfs.replication&lt;/name&gt;
  &lt;value&gt;1&lt;/value&gt;
  &lt;description&gt;Default block replication.
  The actual number of replications can be specified when the file is created.
  The default is used if replication is not specified in create time.
  &lt;/description&gt;
&lt;/property&gt;

&lt;/configuration&gt;</pre>
<p>Now to our last step!</p>
<h2 id="Step_4:_Formatting_and_Running_Hadoop">Step 4: Formatting and Running Hadoop</h2>
<p>Our last step involves formatting the namenode and testing our system.</p>
<pre>$:~ cd ~
$:~ hadoop-*/bin/hadoop namenode -format</pre>
<p>This will give you output along the lines of</p>
<pre>$:~ hadoop-*/bin/hadoop namenode -format
 08/09/14 21:22:14 INFO dfs.NameNode: STARTUP_MSG:
 /***********************************************************
 STARTUP_MSG: Starting NameNode
 STARTUP_MSG:   host = loteria/127.0.0.1
 STARTUP_MSG:   args = [-format]
 ***********************************************************/
 08/09/14 21:22:14 INFO dfs.Storage: Storage directory [...] has been successfully formatted.
 09/09/14 21:22:14 INFO dfs.NameNode: SHUTDOWN_MSG:
 /***********************************************************
 SHUTDOWN_MSG: Shutting down NameNode at loteria/127.0.0.1
 ***********************************************************/</pre>
<p>Once this is done, we are ready to test our program.</p>
<h3 id="Running_Hadoop">Running Hadoop</h3>
<p>First, start up the DFS. This will start up a <a href="http://wiki.apache.org/hadoop/TaskTracker">TaskTracker</a>, <a href="http://wiki.apache.org/hadoop/JobTracker">JobTracker</a>, and <a href="http://wiki.apache.org/hadoop/DataNode">DataNode</a> on the machine.</p>
<pre>$:~ hadoop-*/bin/start-all.sh</pre>
<p>As input for our test, we are going to copy the conf folder up to our DFS.</p>
<pre>$:~ hadoop-*/bin/hadoop dfs -copyFromLocal hadoop-*/conf input</pre>
<p>You can check to see if this actually worked by doing an ls on the dfs as follows:</p>
<pre>$:~ hadoop-*/bin/hadoop dfs -ls
Found 1 item</pre>
<p>Now, we need to compile the code. cd into the hadoop-*/ directory and do:</p>
<pre>$:~ cd hadoop-1.0.4
$:~ ant examples</pre>
<p>This will compile the example programs found in hadoop-*/src/examples</p>
<p>Now, we will run the example distributed grep program on the conf program as input.</p>
<pre>$:~ hadoop-*/bin/hadoop jar /Users/hadoop/hadoop-1.0.4/build/hadoop-examples-1.0.4-SNAPSHOT.jar grep input output 'dfs[a-z.]+'</pre>
<p>If this works, you&#8217;ll see something like this pop up on your screen:</p>
<p>13/04/25 15:53:59 INFO mapred.JobClient: Map input bytes=94<br />
13/04/25 15:53:59 INFO mapred.JobClient: SPLIT_RAW_BYTES=118<br />
13/04/25 15:53:59 INFO mapred.JobClient: Combine input records=0<br />
13/04/25 15:53:59 INFO mapred.JobClient: Reduce input records=3<br />
13/04/25 15:53:59 INFO mapred.JobClient: Reduce input groups=1<br />
13/04/25 15:53:59 INFO mapred.JobClient: Combine output records=0<br />
13/04/25 15:53:59 INFO mapred.JobClient: Reduce output records=3<br />
13/04/25 15:53:59 INFO mapred.JobClient: Map output records=3</p>
<p>The last step is to check if you have output!</p>
<p>You can do this by doing:</p>
<pre>$:~ hadoop-*/bin/hadoop dfs -ls output
Found 2 items</pre>
<p>Found 2 items-rw-r&#8211;r&#8211; 3 hadoop supergroup 0 2013-04-25 15:53 /user/hadoop/output/_SUCCESS<br />
-rw-r&#8211;r&#8211; 3 hadoop supergroup 52 2013-04-25 15:53 /user/hadoop/output/part-00000</p>
<pre></pre>
<p>The most important part is that the number next to the &lt;r 1&gt; should <strong>not</strong> be 0.</p>
<p>To check the actual contents of the output do:</p>
<pre>$:~ hadoop-*/bin/hadoop dfs -cat output/*</pre>
<p>Alternatively, you can copy it to local disk and check/modify it:</p>
<pre>$:~ hadoop-*/bin/hadoop dfs -copyToLocal output myoutput
$:~ cat myoutput/*</pre>
<h3 id="Stopping_the_Hadoop_DFS">Stopping the Hadoop DFS</h3>
<p>When you&#8217;re done running jobs on the dfs, run the stop-all.sh command.</p>
<pre>$:~ hadoop-*/bin/stop-all.sh</pre>
<p>That&#8217;s all! Happy Map Reducing!</p>
]]></content:encoded>
			<wfw:commentRss>http://gabhi.com/install-hadoop-on-mac-os-single-node/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Set all bits of a number in a range equal to another number</title>
		<link>http://gabhi.com/set-all-bits-of-a-number-in-a-range-equal-to-another-number/</link>
		<comments>http://gabhi.com/set-all-bits-of-a-number-in-a-range-equal-to-another-number/#comments</comments>
		<pubDate>Mon, 22 Apr 2013 01:25:43 +0000</pubDate>
		<dc:creator>Abhijit Gaikwad</dc:creator>
				<category><![CDATA[Questions]]></category>

		<guid isPermaLink="false">http://gabhi.com/?p=1529</guid>
		<description><![CDATA[You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set all bits between i and j in N equal to M (e.g., M becomes a substring of N located at i and starting at j). EXAMPLE: Input: N = &#8230;]]></description>
				<content:encoded><![CDATA[<p>You are given two 32-bit numbers, N and M, and two bit positions, i and j. Write a method to set all bits between i and j in N equal to M (e.g., M becomes a substring of N located at i and starting at j).<br />
EXAMPLE:<br />
Input: N = 10000000000, M = 10101, i = 2, j = 6<br />
Output: N = 10001010100</p>
<p>&nbsp;</p>
<pre>public class SetBits {

	/**
	 * @param args
	 */
	public static void main(String[] args) {

		int N = 1024;
		int M = 21;
		System.out.println(Integer.toBinaryString(M));
		System.out.println(Integer.toBinaryString(N));
		int j = updateBits(N, M, 2, 6);
		System.out.println(Integer.toBinaryString(j));
		System.out.println(j);
	}

	public static int updateBits(int n, int m, int i, int j) {
		int max = -1; /* All 1's */
		System.out.println("Max:       " + Integer.toBinaryString(max));

		// 1's through position j, then 0's
		int left = max - ((1 &lt;&lt; j) - 1);
		System.out.println("Left:      " + Integer.toBinaryString(left));

		// 1's after position i
		int right = ((1 &lt;&lt; i) - 1);
		System.out.println("Right:     " + Integer.toBinaryString(right));

		// 1's with 0s between i and j
		int mask = left | right;
		System.out.println("Mask:      " + Integer.toBinaryString(mask));
		System.out.println("n &amp; mask:  " + Integer.toBinaryString(n &amp; mask));
		System.out.println("m &lt;&lt; i:    " + Integer.toBinaryString(m &lt;&lt; i));

		// Clear i through j, then put m in there
		return (n &amp; mask) | (m &lt;&lt; i);
	}
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://gabhi.com/set-all-bits-of-a-number-in-a-range-equal-to-another-number/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>longest palindrom in string</title>
		<link>http://gabhi.com/longest-palindrom-in-string/</link>
		<comments>http://gabhi.com/longest-palindrom-in-string/#comments</comments>
		<pubDate>Mon, 15 Apr 2013 02:47:10 +0000</pubDate>
		<dc:creator>Abhijit Gaikwad</dc:creator>
				<category><![CDATA[Questions]]></category>
		<category><![CDATA[palindrom]]></category>
		<category><![CDATA[public static string]]></category>
		<category><![CDATA[static string]]></category>
		<category><![CDATA[string input]]></category>

		<guid isPermaLink="false">http://techinterviewprep.wordpress.com/?p=1491</guid>
		<description><![CDATA[]]></description>
				<content:encoded><![CDATA[<pre class="brush: java; title: ; notranslate">

public class LongestPalindromeFinder {

public static void main(String[] args) {
String input = &amp;amp;amp;quot;HYTBCABADEFGHABCDEDCBAGHTFYW12345678987654321ZWETYGDE&amp;amp;amp;quot;;
System.out.println(getLongestPalindrome(&amp;amp;amp;quot;1234&amp;amp;amp;quot;));
System.out.println(getLongestPalindrome(&amp;amp;amp;quot;1223213&amp;amp;amp;quot;));
System.out.println(getLongestPalindrome(&amp;amp;amp;quot;9912321456&amp;amp;amp;quot;));
System.out.println(getLongestPalindrome(&amp;amp;amp;quot;9912333321456&amp;amp;amp;quot;));
System.out.println(getLongestPalindrome(&amp;amp;amp;quot;12145445499&amp;amp;amp;quot;));
System.out.println(getLongestPalindrome(input));
}

private static String getLongestPalindrome(String string) {
String odd = getLongestPalindromeOdd(string);
String even = getLongestPalindromeEven(string);
return (odd.length() &amp;amp;amp;amp;gt; even.length() ? odd : even);
}

public static String getLongestPalindromeOdd(final String input) {
int rightIndex = 0, leftIndex = 0;
String currentPalindrome = &amp;amp;amp;quot;&amp;amp;amp;quot;, longestPalindrome = &amp;amp;amp;quot;&amp;amp;amp;quot;;
for (int centerIndex = 1; centerIndex = 0 &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp; rightIndex longestPalindrome
.length() ? currentPalindrome : longestPalindrome;
leftIndex--;
rightIndex++;
}
}
return longestPalindrome;
}

public static String getLongestPalindromeEven(final String input) {
int rightIndex = 0, leftIndex = 0;
String currentPalindrome = &amp;amp;amp;quot;&amp;amp;amp;quot;, longestPalindrome = &amp;amp;amp;quot;&amp;amp;amp;quot;;
for (int centerIndex = 1; centerIndex = 0 &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp; rightIndex longestPalindrome
.length() ? currentPalindrome : longestPalindrome;
leftIndex--;
rightIndex++;
}
}
return longestPalindrome;
}

}

</pre>
]]></content:encoded>
			<wfw:commentRss>http://gabhi.com/longest-palindrom-in-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://gabhi.com/hello-world/</link>
		<comments>http://gabhi.com/hello-world/#comments</comments>
		<pubDate>Mon, 15 Apr 2013 02:03:29 +0000</pubDate>
		<dc:creator>Abhijit Gaikwad</dc:creator>
				<category><![CDATA[Questions]]></category>

		<guid isPermaLink="false">http://gabhi.com/?p=1</guid>
		<description><![CDATA[Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!]]></description>
				<content:encoded><![CDATA[<p>Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!</p>
]]></content:encoded>
			<wfw:commentRss>http://gabhi.com/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>longest arithmetic progression</title>
		<link>http://gabhi.com/longest-arithmetic-progression/</link>
		<comments>http://gabhi.com/longest-arithmetic-progression/#comments</comments>
		<pubDate>Sun, 14 Apr 2013 08:56:07 +0000</pubDate>
		<dc:creator>Abhijit Gaikwad</dc:creator>
				<category><![CDATA[Questions]]></category>
		<category><![CDATA[2f 2f]]></category>
		<category><![CDATA[args]]></category>
		<category><![CDATA[arithmetic progression]]></category>
		<category><![CDATA[complexity]]></category>
		<category><![CDATA[system 3b]]></category>

		<guid isPermaLink="false">http://techinterviewprep.wordpress.com/?p=1489</guid>
		<description><![CDATA[using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace FindLongestAP { class APInfo { // stores the start index of the original data set for the AP found internal int startIndex; // stores the end index of the original data set for the AP found internal int endIndex; // stores &#8230;]]></description>
				<content:encoded><![CDATA[<p><code><br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text; </p>
<p>namespace FindLongestAP<br />
{<br />
class APInfo<br />
{<br />
// stores the start index of the original data set for the AP found<br />
internal int startIndex;<br />
// stores the end index of the original data set for the AP found<br />
internal int endIndex;<br />
// stores the difference for the the AP found<br />
internal int diff;<br />
}; </p>
<p>class Program<br />
{<br />
static void Main(string[] args)<br />
{<br />
int[] data = new int[] {2, 3, 5, 7, 8, 4, 9, 5, 10, 6}; </p>
<p>APInfo apInfo = FindLongestAPInfo(data); </p>
<p>for (int i = apInfo.startIndex; i &lt;= apInfo.endIndex; i++)<br />
{<br />
Console.Write(&quot;{0} &quot;, data[i]);<br />
}<br />
} </p>
<p>///<br />
<summary>
/// The main idea is scanning the data set to find the complete AP, then compare the<br />
/// current found AP with the longest one found so far, if the current one is longer,<br />
/// then update the longest one with the current one. After finished scanning the whole<br />
/// data set, then the longest AP is determined. O(N) complexity.<br />
/// </summary>
<p>///<br />
///<br />
static APInfo FindLongestAPInfo(int[] data)<br />
{<br />
if (data == null || data.Length &lt; 2)<br />
{<br />
return null;<br />
} </p>
<p>// Initialize<br />
APInfo currentAPInfo = new APInfo();<br />
currentAPInfo.startIndex = 0;<br />
currentAPInfo.endIndex = 1;<br />
currentAPInfo.diff = data[1] - data[0]; </p>
<p>APInfo longestAPInfo = new APInfo();<br />
longestAPInfo.startIndex = 0;<br />
longestAPInfo.endIndex = 1;<br />
longestAPInfo.diff = data[1] - data[0]; </p>
<p>for (int i = 2; i  longestAPInfo.endIndex - longestAPInfo.startIndex)<br />
{<br />
longestAPInfo.startIndex = currentAPInfo.startIndex;<br />
longestAPInfo.endIndex = currentAPInfo.endIndex;<br />
}<br />
// update currentAPInfo to start a new one<br />
currentAPInfo.startIndex = i - 1;<br />
currentAPInfo.endIndex = i;<br />
currentAPInfo.diff = diff;<br />
}<br />
} </p>
<p>return longestAPInfo;<br />
}<br />
}<br />
}</p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://gabhi.com/longest-arithmetic-progression/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MatrixTopDown java</title>
		<link>http://gabhi.com/matrixtopdown-java/</link>
		<comments>http://gabhi.com/matrixtopdown-java/#comments</comments>
		<pubDate>Sun, 14 Apr 2013 00:22:31 +0000</pubDate>
		<dc:creator>Abhijit Gaikwad</dc:creator>
				<category><![CDATA[Questions]]></category>
		<category><![CDATA[args]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[botton]]></category>
		<category><![CDATA[int row]]></category>
		<category><![CDATA[println]]></category>

		<guid isPermaLink="false">http://techinterviewprep.wordpress.com/?p=1487</guid>
		<description><![CDATA[public class MatrixTopDown { /** * @param args */ public static void main(String[] args) { int[][] a = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } }; printArray(a); } public static void printArray(int[][] a) { // print array in rectangular form for &#8230;]]></description>
				<content:encoded><![CDATA[<p><code></p>
<p>public class MatrixTopDown {</p>
<p>	/**<br />
	 * @param args<br />
	 */<br />
	public static void main(String[] args) {</p>
<p>		int[][] a = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };</p>
<p>		printArray(a);</p>
<p>	}</p>
<p>	public static void printArray(int[][] a) {<br />
		// print array in rectangular form<br />
		for (int i = 0; i &lt; a.length; i++) {<br />
			matrixTraversalTopDown(a, &quot;&quot; + a[0][i], 0, i);<br />
		}<br />
		System.out.println(&quot;&quot;);</p>
<p>	}</p>
<p>	private static void matrixTraversalTopDown(int[][] inputMatrix,<br />
			String path, int row, int col) {</p>
<p>		if (row == inputMatrix[0].length - 1) {<br />
			// Display the traversal path<br />
			System.out.println(path);<br />
			return;<br />
		}<br />
		// Botton Left<br />
		if (row + 1 = 0) {<br />
			matrixTraversalTopDown(inputMatrix, path + " - " + ""<br />
					+ inputMatrix[row + 1][col - 1], row + 1, col - 1);<br />
		}<br />
		// Bottom<br />
		if (row + 1 &lt; inputMatrix[0].length) {<br />
			matrixTraversalTopDown(inputMatrix, path + &quot; - &quot; + &quot;&quot;<br />
					+ inputMatrix[row + 1][col], row + 1, col);<br />
		}<br />
		// Bottom Right<br />
		if (row + 1 &lt; inputMatrix[0].length &amp;&amp; col + 1 &lt; inputMatrix[1].length) {<br />
			matrixTraversalTopDown(inputMatrix, path + &quot; - &quot; + &quot;&quot;<br />
					+ inputMatrix[row + 1][col + 1], row + 1, col + 1);<br />
		}<br />
	}</p>
<p>}</p>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://gabhi.com/matrixtopdown-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Array Shuffling in java</title>
		<link>http://gabhi.com/array-shuffling-in-java/</link>
		<comments>http://gabhi.com/array-shuffling-in-java/#comments</comments>
		<pubDate>Sat, 13 Apr 2013 19:50:09 +0000</pubDate>
		<dc:creator>Abhijit Gaikwad</dc:creator>
				<category><![CDATA[Questions]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[element]]></category>
		<category><![CDATA[random number generator]]></category>
		<category><![CDATA[rgen]]></category>
		<category><![CDATA[shuffle]]></category>

		<guid isPermaLink="false">http://techinterviewprep.wordpress.com/?p=1484</guid>
		<description><![CDATA[Random rgen = new Random(); // Random number generator int[] cards = new int[52]; //--- Initialize the array to the ints 0-51 for (int i=0; i&#60;cards.length; i++) { cards[i] = i; } //--- Shuffle by exchanging each element randomly for (int i=0; i&#60;cards.length; i++) { int randomPosition = rgen.nextInt(cards.length); int &#8230;]]></description>
				<content:encoded><![CDATA[<pre>Random rgen = new Random();  // Random number generator
int[] cards = new int[52];  

//--- Initialize the array to the ints 0-51
for (int i=0; i&lt;cards.length; i++) {
    cards[i] = i;
}

//--- Shuffle by exchanging each element randomly
for (int i=0; i&lt;cards.length; i++) {
    int randomPosition = rgen.nextInt(cards.length);
    int temp = cards[i];
    cards[i] = cards[randomPosition];
    cards[randomPosition] = temp;
}</pre>
]]></content:encoded>
			<wfw:commentRss>http://gabhi.com/array-shuffling-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
