<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">

<channel>
	<title>NitinH.com</title>
	
	<link>http://www.nitinh.com</link>
	<description>Nitin Hayaran's Blog</description>
	<lastBuildDate>Sat, 18 May 2013 17:09:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/TheCodeDreamer" /><feedburner:info uri="thecodedreamer" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><feedburner:emailServiceId>TheCodeDreamer</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><item>
		<title>Getting started with Grunt &amp; Bower</title>
		<link>http://feedproxy.google.com/~r/TheCodeDreamer/~3/T8UZfAFsc1Q/</link>
		<comments>http://www.nitinh.com/2013/05/getting-started-with-grunt-bower/#comments</comments>
		<pubDate>Sat, 18 May 2013 15:33:59 +0000</pubDate>
		<dc:creator>nitin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[bower]]></category>
		<category><![CDATA[bowerjs]]></category>
		<category><![CDATA[grunt]]></category>
		<category><![CDATA[gruntjs]]></category>
		<category><![CDATA[less]]></category>
		<category><![CDATA[nodejs]]></category>
		<category><![CDATA[workflow]]></category>

		<guid isPermaLink="false">http://www.nitinh.com/?p=583</guid>
		<description><![CDATA[<p><p><img src="http://www.nitinh.com/wp-content/uploads/2013/05/bower_grunt.png" alt="Bower &#38; Grunt" width="630" height="270" class="size-full wp-image-618" /></p>
<p>Lately I have been dabbling with various tools and libraries to improve my skills, and workflow. In the process I have tried <a href="http://yeoman.io/">Yeoman</a>, which is a collection of tools and best practices to make web development easier and better.</p>
<p><span id="more-583"></span></p>
<h2>Why Yeoman?</h2>
<p>Yeoman comes with a collection of <a href="http://yeoman.io/generators.html">generators</a>, which initialize your project with  default set of tools and libraries those might be needed. But many a times, I fealt that one might not need all those tools, and such generators could be overload.</p> <a href="http://www.nitinh.com/2013/05/getting-started-with-grunt-bower/" class="read_more">Read More</a></p><p>The post <a href="http://www.nitinh.com/2013/05/getting-started-with-grunt-bower/">Getting started with Grunt &#038; Bower</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><img src="http://www.nitinh.com/wp-content/uploads/2013/05/bower_grunt.png" alt="Bower &amp; Grunt" width="630" height="270" class="size-full wp-image-618" /></p>
<p>Lately I have been dabbling with various tools and libraries to improve my skills, and workflow. In the process I have tried <a href="http://yeoman.io/">Yeoman</a>, which is a collection of tools and best practices to make web development easier and better.</p>
<p><span id="more-583"></span></p>
<h2>Why Yeoman?</h2>
<p>Yeoman comes with a collection of <a href="http://yeoman.io/generators.html">generators</a>, which initialize your project with  default set of tools and libraries those might be needed. But many a times, I fealt that one might not need all those tools, and such generators could be overload. Hence, its better to use basic building blocks of yeoman and create a workflow which suits you.</p>
<h2>Introducing Grunt &amp; Bower</h2>
<p>In simple words Grunt is a JavaScript Task Runner. It lets you automate repetitive tasks like minification, compilation, unit testing, linting, etc.</p>
<p>On the other hand, Bower is a front-end package manager. It allows you to simple include, remove, upgrade various packages available for front-end development. You can see various packages available <a href="http://sindresorhus.com/bower-components/">here</a>.</p>
<h2>Get Started</h2>
<p>The best way to learn using grunt is with an example. So lets setup a simple web application with grunt and bower. I will be setting up a simple webapp that will include standalone development server, livereload, and compilation of less files.</p>
<h3>Grunt</h3>
<p>Grunt and Bower are based on node.js, so first install nodejs &amp; npm on your machine. For information you can see <a href="nodejs.org">node.js</a></p>
<p>To start with create a directory for your project, say <code>gruntSample</code>. Now your project needs a <code>package.json</code> and a <code>Gruntfile.js</code>. The package.json file is used by npm and should contain the dependencies for your project.<br />
The Gruntfile.js will contain tasks and load Grunt plugins for you. Both of these files should be in the root of your project.</p>
<h4>Package.json</h4>
<p>You can find detailed information about creating package.json on <a href="http://gruntjs.com/getting-started">grunt getting started guide</a>. Here I&rsquo;ll tell you the way I proceed.</p>
<p>From project directory run following commands.</p>
<pre><code>npm init
npm install grunt grunt-contrib-less grunt-contrib-connect grunt-contrib-watch grunt-open matchdep connect-livereload --save-dev
</code></pre>
<p><code>npm init</code> will guide you though various step in creating initial package.json file, you can go ahead with the default while creating it, and later change it manually.</p>
<p>Second command will install grunt and other grunt packages needed for this project.</p>
<h3>Gruntfile.js</h3>
<p>Now that we have added the package.json file, we can create Gruntfile.js. Here is the Gruntfile.js which we&rsquo;ll be using in this sample project.</p>
<pre lang="javascript">'use strict';
var LIVERELOAD_PORT = 35729;
var lrSnippet = require('connect-livereload')({port: LIVERELOAD_PORT});
var mountFolder = function (connect, dir) {
    return connect.static(require('path').resolve(dir));
};

// # Globbing
// for performance reasons we're only matching one level down:
// 'test/spec/{,*/}*.js'
// use this if you want to recursively match all subfolders:
// 'test/spec/**/*.js'

module.exports = function (grunt) {
    // load all grunt tasks
    require('matchdep').filterDev('grunt-*').forEach(grunt.loadNpmTasks);

    grunt.initConfig({
        watch: {
            options: {
                nospawn: true
            },
            less: {
                files: ['app/styles/*.less'],
                tasks: ['less:server']
            },
            livereload: {
                options: {
                    livereload: LIVERELOAD_PORT
                },
                files: [
                    'app/*.html',
                    'app/styles/{,*/}*.css',
                    'app/scripts/{,*/}*.js',
                    'app/images/{,*/}*.{png,jpg,jpeg,gif,webp,svg}'
                ]
            }
        },
        connect: {
            options: {
                port: 9000,
                // change this to '0.0.0.0' to access the server from outside
                hostname: 'localhost'
            },
            livereload: {
                options: {
                    middleware: function (connect) {
                        return [
                            mountFolder(connect, 'app'),
                            lrSnippet
                        ];
                    }
                }
            }
        },
        open: {
            server: {
                path: 'http://localhost:<%= connect.options.port %>'
            }
        },
        less: {
            server: {
                options: {
                    paths: ['app/components/bootstrap/less', 'app/styles']
                },
                files: {
                    'app/styles/main.css': 'app/styles/main.less'
                }
            }
        }
    });

    grunt.registerTask('server', function (target) {

        grunt.task.run([
            'less:server',
            'connect:livereload',
            'open',
            'watch'
        ]);
    });
};</pre>
<h3>Bower</h3>
<p>As already mentioned <strong>Bower</strong> is the package manager. So to get started you first have to install Bower. For this run following command in Terminal.</p>
<pre><code>npm install -g bower</code></pre>
<p>Then create a file named <code>.bowerrc</code> in project folder, with following content.</p>
<pre lang="javascript">{
   "directory": "app/components"
}
</pre>
<p>This will direct bower to download <a href="http://sindresorhus.com/bower-components/">bower components</a> <code>app/components</code> directory.</p>
<p>Later run following commands.</p>
<pre><code>mkdir app
mkdir app/components
bower init
bower install bootstrap
</code></pre>
<p><code>bower init</code> will guide you to create a file <code>bower.json</code>. This is the file which will contain all the dependencies of the project. Later on production you can simply copy this file and run <code>bower install</code> to install all dependencies.</p>
<h3>Project Files</h3>
<p>Now lets add some code to test your project setup. Just create following files.</p>
<p><strong>app/index.html</strong></p>
<pre lang="html">&lt;!doctype html&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;meta charset="UTF-8"&gt;
    &lt;title&gt;Test Document&lt;/title&gt;
    &lt;link rel="stylesheet" type="text/css" href="styles/main.css"&gt;
&lt;/head&gt;
&lt;body&gt;
    &lt;h2&gt;Hello Grunt!&lt;/h2&gt;

    &lt;script src="http://localhost:35729/livereload.js"&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<p><strong>app/styles/main.less</strong></p>
<pre lang="css">body{
    font-family: Arial, sans-serif;
}
h2{
    color: red;
}</pre>
<p>In our <code>Gruntfile.js</code> we have added just one task to run the development server. This task will internally start a livereload server and will start compiling less to css as and when <code>main.less</code> file is changed.</p>
<p>Just run following command to test if everything is working fine.</p>
<pre><code>grunt server
</code></pre>
<p>The command should start server and the should open <code>http://localhost:9000/</code> in your browser. You can also try changing less / html file, the changes should be reflected  on browser without refreshing the page.</p>
<h2>Conclusion</h2>
<p>In this grunt file we have just added support of compling less files, livereload and starting a development server. If you want you can also add various other tasks as per you requirement, more detailed tutorial can be found <a href="http://gruntjs.com/configuring-tasks">here</a>.</p>
<p>I have also put up this sample grunt application on github, feel free to use it. <a href="https://github.com/nitinhayaran/gruntSample">gruntSample</a></p>
<p>Being a frontend developer if you haven&rsquo;t yet added Grunt.js to your workflow, then you are seriously missing something. You should surely check it out.</p>
<p>The post <a href="http://www.nitinh.com/2013/05/getting-started-with-grunt-bower/">Getting started with Grunt &#038; Bower</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p><img src="http://feeds.feedburner.com/~r/TheCodeDreamer/~4/T8UZfAFsc1Q" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nitinh.com/2013/05/getting-started-with-grunt-bower/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.nitinh.com/2013/05/getting-started-with-grunt-bower/</feedburner:origLink></item>
		<item>
		<title>Hell of email applications on iPhone</title>
		<link>http://feedproxy.google.com/~r/TheCodeDreamer/~3/ftDS0gmJTmI/</link>
		<comments>http://www.nitinh.com/2013/05/state-of-email-applications-on-iphone/#comments</comments>
		<pubDate>Wed, 15 May 2013 06:00:48 +0000</pubDate>
		<dc:creator>nitin</dc:creator>
				<category><![CDATA[iWish]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[mail]]></category>
		<category><![CDATA[mailbox]]></category>

		<guid isPermaLink="false">http://www.nitinh.com/?p=570</guid>
		<description><![CDATA[<p><p><a title="Mailboxes by 75Central, on Flickr" href="http://www.flickr.com/photos/lrod/5243500409\."><img alt="Mailboxes" src="http://farm6.staticflickr.com/5002/5243500409_c2b9371e7e_z.jpg" /></a></p>
<p>I&#8217;ve been using Apple&#8217;s native mail application since the day I bought my first iPhone. Its set up with my <a href="http://www.gmail.com">gmail</a> using google exchange. Everything seemed perfect, I was able to read emails, reply to them, add pictures, open attachments, it looked complete. So far so good!</p>
<p>Then came <a href="https://itunes.apple.com/in/app/gmail-email-from-google/id422689480?mt=8">Gmail official iPhone application</a>, that made me realize what I have been missing so far. It was having most of the features which I like about its web counterpart. It had great message display, <strong>better representation for email thread</strong>, above all its <strong>search</strong> actually worked.</p> <a href="http://www.nitinh.com/2013/05/state-of-email-applications-on-iphone/" class="read_more">Read More</a></p><p>The post <a href="http://www.nitinh.com/2013/05/state-of-email-applications-on-iphone/">Hell of email applications on iPhone</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><a title="Mailboxes by 75Central, on Flickr" href="http://www.flickr.com/photos/lrod/5243500409\."><img alt="Mailboxes" src="http://farm6.staticflickr.com/5002/5243500409_c2b9371e7e_z.jpg" /></a></p>
<p>I&#8217;ve been using Apple&#8217;s native mail application since the day I bought my first iPhone. Its set up with my <a href="http://www.gmail.com">gmail</a> using google exchange. Everything seemed perfect, I was able to read emails, reply to them, add pictures, open attachments, it looked complete. So far so good!</p>
<p>Then came <a href="https://itunes.apple.com/in/app/gmail-email-from-google/id422689480?mt=8">Gmail official iPhone application</a>, that made me realize what I have been missing so far. It was having most of the features which I like about its web counterpart. It had great message display, <strong>better representation for email thread</strong>, above all its <strong>search</strong> actually worked.</p>
<p>Now we also have <a href="http://www.mailboxapp.com">Mailbox</a> which made my email organized, soon we&#8217;ll also have <a href="http://www.dotmailapp.com">.Mail</a>.</p>
<h3>Current State</h3>
<p>Presently I have to use 3 different applications to check and manage my emails.</p>
<ul>
<li><strong>Gmail</strong> : Whenever I need to see any email conversation thread, and have to search any email.</li>
<li><strong>Mailbox</strong> : For organizing and prioritizing stuff</li>
<li><strong>Mail App</strong> : To read and check new email.</li>
</ul>
<p>Overall it doesn&#8217;t feel right to use 3 different applications for single task of reading and managing emails.</p>
<p>Out of these three, I just don&#8217;t want to use Native mail application. Its very limiting when it is compared with other of its compititors. But somehow I keep coming back to it, becuase of its <strong>speed</strong>. As soon I get notification for a new mail, there is an instant urge to check it, but if you check it using any app other then native Mail you&#8217;ll have to wait for the message to download. And this wait time is really annoying.</p>
<h3>iWish</h3>
<p>Here, I&#8217;d wish Apple to comeup with some mechanism so that, applications other than native could also get full email messages in background. So that, when I open their notifications, email/messages are there (no loading indicator).</p>
<p>It would also be great if magically somehow, search and autosuggest of gmail&#8217;s app could also be there in other applications. If this could happen then I can peacefully just use Mailbox (which I am loving by the way).</p>
<p>This is how I use email application, what about you? Are you also stuck in hell of email apps.</p>
<p>The post <a href="http://www.nitinh.com/2013/05/state-of-email-applications-on-iphone/">Hell of email applications on iPhone</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p><img src="http://feeds.feedburner.com/~r/TheCodeDreamer/~4/ftDS0gmJTmI" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nitinh.com/2013/05/state-of-email-applications-on-iphone/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.nitinh.com/2013/05/state-of-email-applications-on-iphone/</feedburner:origLink></item>
		<item>
		<title>Vertically Responsive Design : Keeping Things Above The Fold</title>
		<link>http://feedproxy.google.com/~r/TheCodeDreamer/~3/cfoOS1lBhKY/</link>
		<comments>http://www.nitinh.com/2013/03/vertically-responsive-design-keeping-things-above-the-fold/#comments</comments>
		<pubDate>Fri, 08 Mar 2013 02:00:43 +0000</pubDate>
		<dc:creator>nitin</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[design]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[metro]]></category>
		<category><![CDATA[responsive]]></category>

		<guid isPermaLink="false">http://www.nitinh.com/?p=557</guid>
		<description><![CDATA[<p><p style="text-align: center;"><img class="aligncenter size-full wp-image-615" alt="Responsive Design" src="http://www.nitinh.com/wp-content/uploads/2013/03/what-is-responsive-web-design-700x466.png" width="700" height="466" /></p>
<p>In last couple of years you must have seen countless examples of responsive designs. Most of the websites are either already responsive or are planing for a responsive re-design. As we see more and more devies, this trend is likely to continue in near future as well. <a href="http://mashable.com/author/pete-cashmore/">Pete Cashmore</a> from Mashable has already <a href="http://mashable.com/2012/12/11/responsive-web-design/">declared</a> 2013 as the year of Responsive Designs.</p>
<p>Developers mostly uses <a href="http://alistapart.com/article/fluidgrids">Fluid Grid</a>, or <a href="http://www.w3.org/TR/css3-mediaqueries/">Media queries</a> to make the website adaptive. The basic technique is to viewport width and render content according to that.</p> <a href="http://www.nitinh.com/2013/03/vertically-responsive-design-keeping-things-above-the-fold/" class="read_more">Read More</a></p><p>The post <a href="http://www.nitinh.com/2013/03/vertically-responsive-design-keeping-things-above-the-fold/">Vertically Responsive Design : Keeping Things Above The Fold</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter size-full wp-image-615" alt="Responsive Design" src="http://www.nitinh.com/wp-content/uploads/2013/03/what-is-responsive-web-design-700x466.png" width="700" height="466" /></p>
<p>In last couple of years you must have seen countless examples of responsive designs. Most of the websites are either already responsive or are planing for a responsive re-design. As we see more and more devies, this trend is likely to continue in near future as well. <a href="http://mashable.com/author/pete-cashmore/">Pete Cashmore</a> from Mashable has already <a href="http://mashable.com/2012/12/11/responsive-web-design/">declared</a> 2013 as the year of Responsive Designs.</p>
<p>Developers mostly uses <a href="http://alistapart.com/article/fluidgrids">Fluid Grid</a>, or <a href="http://www.w3.org/TR/css3-mediaqueries/">Media queries</a> to make the website adaptive. The basic technique is to viewport width and render content according to that. You can refer <a href="http://mashable.com/2012/12/11/responsive-web-design/">these</a> <a href="http://www.abookapart.com/products/responsive-web-design">excellent</a> <a href="http://coding.smashingmagazine.com/2011/01/12/guidelines-for-responsive-web-design/">articles</a>, for more information on Responsive Design.</p>
<h2>Vertically Responsive Design</h2>
<p>Recently I came across a very simple yet brilliant technique to adjust the content based on available height as well. The website which implement this is of San Francisco advertising agency, <a href="http://www.venablesbell.com/latest">Venables Bell and Partners</a>. Just go and have a look at the website, also try changing the height of the browser.</p>
<p>You must have noticed that the content width also changes as per available height. The information blocks are resized while maintaining aspect ratio. I found this technique very useful, as it can also be used to show important messages <a href="http://en.wikipedia.org/wiki/Above_the_fold">above the fold</a>. This could surely increase the visibility of important links, buttons.</p>
<h3>Pure CSS Approach</h3>
<p>Everything with the Vanables website was perfect expect for the fact that it was using Javascript to figure out viewport size. Viewport is then used to calculate container width/height. As today’s browsers are getting more and more advanced and with these new CSS capabilities I thought similar functionality could also be replicated using CSS only. I quickly mocked up a demo which was purely built using CSS3 without using any javascript.</p>
<p>You can have a look at the demo here:</p>
<p><a class="btn" href="http://www.nitinh.com/static/above-fold/">Vertically Responsive Design Demo</a></p>
<p>Try playing with the browser height, and watch how “Sign up” block keeps at the bottom of the page. The container auto scales based on the viewport size while maintaining aspect ratio.</p>
<h3>Now some code</h3>
<p>The CSS technique which came for the rescue are <a href="https://developer.mozilla.org/en-US/docs/CSS/length#Viewport-percentage_lengths">Viewport Percentage Length</a> and <a href="https://developer.mozilla.org/en-US/docs/CSS/calc">CSS Calc</a>. The main css properties for the upper block are</p>
<pre lang="css">.container{
	min-width: 600px;
	max-width: 1080px;
	min-height: calc(690px * (90/150));
	height: 90vh;
	width: 150vh;
}</pre>
<p>Setting height as 90vh, means 90% of the viewport height. Later we simply can relatively place signup container inside that. Utilizing Viewport Percentage Length make it easier to keep the aspect ratio maintained at any given viewport size.</p>
<h5>Browser Support</h5>
<p>Viewport Percentage Length is supported across Chrome 21+, Firefox 19+, IE 10+, Safari 6+. For detailed and updated browser refer <a href="http://caniuse.com/#feat=viewport-units">CanIuse : Viewport Units</a> and <a href="http://caniuse.com/#feat=calc">CanIuse : CSS Calc</a>.</p>
<p>In my opinion its pretty interesting way to position important content. What your say on this?</p>
<p>The post <a href="http://www.nitinh.com/2013/03/vertically-responsive-design-keeping-things-above-the-fold/">Vertically Responsive Design : Keeping Things Above The Fold</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p><img src="http://feeds.feedburner.com/~r/TheCodeDreamer/~4/cfoOS1lBhKY" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nitinh.com/2013/03/vertically-responsive-design-keeping-things-above-the-fold/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.nitinh.com/2013/03/vertically-responsive-design-keeping-things-above-the-fold/</feedburner:origLink></item>
		<item>
		<title>Quick Hack To Get VerticalAlign Working On KineticJS.Text</title>
		<link>http://feedproxy.google.com/~r/TheCodeDreamer/~3/bh3Z5ipUL3U/</link>
		<comments>http://www.nitinh.com/2013/03/quick-hack-to-get-verticalalign-working-kineticjs-text/#comments</comments>
		<pubDate>Sat, 02 Mar 2013 01:56:10 +0000</pubDate>
		<dc:creator>nitin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[2d]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[kineticjs]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://www.nitinh.com/?p=549</guid>
		<description><![CDATA[<p><p><img class="size-full wp-image-561 alignnone" alt="Javascript Programming" src="http://www.nitinh.com/wp-content/uploads/2013/03/Know-more-about-coding-languages-like-Javascript-C-and-C++.jpg" width="640" height="480" /></p>
<p>In the jungle of Javascript 2D <a href="http://en.wikipedia.org/wiki/Javascript_graphics_library">Canvas</a> <a href="https://docs.google.com/spreadsheet/ccc?key=0Aqj_mVmuz3Y8dHNhUVFDYlRaaXlyX0xYSTVnalV5ZlE#gid=0">Libraries</a> we have chosen KineticJS for the development of Polo. As there were so many libraries, It was a tough choice. Each library comes with their own pros and cons. We have selected KineticJS mainly for following reasons:</p>
<ul>
<li>Its has got an easy api to let us draw <a href="http://kineticjs.com/docs/symbols/Kinetic.Shape.php">shapes</a>, <a href="http://kineticjs.com/docs/symbols/Kinetic.Group.php">group</a> them together with <a href="http://kineticjs.com/docs/symbols/Kinetic.Layer.php">layering</a> support</li>
<li>Collection of <a href="http://www.html5canvastutorials.com/kineticjs/">rich examples</a>, showcase of each feature give quick understanding</li>
<li>Currently under <a href="https://github.com/ericdrowell/KineticJS/">active development</a>, so we can assume timely updates and quick issue resolution</li>
</ul>
<p><span id="more-549"></span></p>
<h3>About verticalAlign</h3>
<p>During the development I had to place some text vertically in middle of its container.</p> <a href="http://www.nitinh.com/2013/03/quick-hack-to-get-verticalalign-working-kineticjs-text/" class="read_more">Read More</a></p><p>The post <a href="http://www.nitinh.com/2013/03/quick-hack-to-get-verticalalign-working-kineticjs-text/">Quick Hack To Get VerticalAlign Working On KineticJS.Text</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><img class="size-full wp-image-561 alignnone" alt="Javascript Programming" src="http://www.nitinh.com/wp-content/uploads/2013/03/Know-more-about-coding-languages-like-Javascript-C-and-C++.jpg" width="640" height="480" /></p>
<p>In the jungle of Javascript 2D <a href="http://en.wikipedia.org/wiki/Javascript_graphics_library">Canvas</a> <a href="https://docs.google.com/spreadsheet/ccc?key=0Aqj_mVmuz3Y8dHNhUVFDYlRaaXlyX0xYSTVnalV5ZlE#gid=0">Libraries</a> we have chosen KineticJS for the development of Polo. As there were so many libraries, It was a tough choice. Each library comes with their own pros and cons. We have selected KineticJS mainly for following reasons:</p>
<ul>
<li>Its has got an easy api to let us draw <a href="http://kineticjs.com/docs/symbols/Kinetic.Shape.php">shapes</a>, <a href="http://kineticjs.com/docs/symbols/Kinetic.Group.php">group</a> them together with <a href="http://kineticjs.com/docs/symbols/Kinetic.Layer.php">layering</a> support</li>
<li>Collection of <a href="http://www.html5canvastutorials.com/kineticjs/">rich examples</a>, showcase of each feature give quick understanding</li>
<li>Currently under <a href="https://github.com/ericdrowell/KineticJS/">active development</a>, so we can assume timely updates and quick issue resolution</li>
</ul>
<p><span id="more-549"></span></p>
<h3>About verticalAlign</h3>
<p>During the development I had to place some text vertically in middle of its container. The quick way to do that could have been to set container and text-block to same size and then vertically align text in center.</p>
<p>But on searching I came to realize that the support for verticalAlign has been temporarily dropped from KineticJS. You can see references for the same <a href="http://stackoverflow.com/questions/13114344/kineticjs-why-was-kinetic-text-verticalalign-property-removed-alternatives">here</a> and <a href="https://github.com/ericdrowell/KineticJS/issues/281">here</a>. The maintainer of KineticJS <a href="https://github.com/ericdrowell">ericdrowell</a> says that, the support for the same will be added back in the <a href="https://github.com/ericdrowell/KineticJS/wiki/Release-Schedule">v4.3.5 release</a>.</p>
<p>So in the meanwhile to solve this issue I did a quick patch in the source. Just replace following lines in KineticJS.Text drawFunc function.</p>
<pre lang="javascript">// Temporary fix for verticalAlign
// this issue is set to be resolved in ver:4.3.5
// https://github.com/ericdrowell/KineticJS/issues/281
var verticalpos = 0;
if(this.attrs.verticalAlign === 'bottom') {
    verticalpos = this.getHeight() - this._getTextSize(text).height - p * 2;
}
else if(this.attrs.verticalAlign === 'middle') {
    verticalpos = (this.getHeight() - this._getTextSize(text).height - p * 2) / 2;
}

// horizontal alignment
context.save();
if(this.getAlign() === RIGHT) {
    context.translate(totalWidth - width - p * 2, verticalpos);
}
else if(this.getAlign() === CENTER) {
    context.translate((totalWidth - width - p * 2) / 2, verticalpos);
}</pre>
<p>These lines have to come in place of horizontal alignment code. For more information please see this <a href="https://github.com/nitinhayaran/KineticJS/commit/ce8228209364dd85d3a2d1abb067936067d418df">commit</a>.</p>
<p>With this I was able to position text vertically in MIDDLE, TOP, BOTTOM. I have not submitted a pull request for the same, as I am not aware of its dependencies. Nevertheless this issue is already in the pipeline and will be resolved by, v.4.3.5.</p>
<p>It was a quick fix just to get this going. Hope this will help you as well.</p>
<p>Happy Coding <img class="wp-smiley" alt=":-)" src="http://www.nitinh.com/wp-includes/images/smilies/icon_smile.gif" /></p>
<p>The post <a href="http://www.nitinh.com/2013/03/quick-hack-to-get-verticalalign-working-kineticjs-text/">Quick Hack To Get VerticalAlign Working On KineticJS.Text</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p><img src="http://feeds.feedburner.com/~r/TheCodeDreamer/~4/bh3Z5ipUL3U" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nitinh.com/2013/03/quick-hack-to-get-verticalalign-working-kineticjs-text/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.nitinh.com/2013/03/quick-hack-to-get-verticalalign-working-kineticjs-text/</feedburner:origLink></item>
		<item>
		<title>Facebook, Twitter, Instapaper Connect Buttons</title>
		<link>http://feedproxy.google.com/~r/TheCodeDreamer/~3/usOqpVu9aE8/</link>
		<comments>http://www.nitinh.com/2011/05/facebook-twitter-instapaper-connect-buttons/#comments</comments>
		<pubDate>Sun, 15 May 2011 15:07:57 +0000</pubDate>
		<dc:creator>nitin</dc:creator>
				<category><![CDATA[Freebies]]></category>

		<guid isPermaLink="false">http://www.nitinh.com/?p=535</guid>
		<description><![CDATA[<p><p>For one of my project I had to use social connect buttons, with Facebook, Twitter, and Instapaper. I tried searching for any buttons that fits my bill, but that went in vain. Later I created these buttons myself using Photoshop. I am releasing these buttons source, may be it&#8217;ll save others time.<span id="more-535"></span><br />
Here is the ScreenShot of these buttons.</p>
<p style="text-align: center;"><a href="http://www.nitinh.com/wp-content/uploads/2011/05/social-connect-botton.png"><img class="size-full wp-image-536 aligncenter" title="Social Connect Buttons" src="http://www.nitinh.com/wp-content/uploads/2011/05/social-connect-botton.png" alt="Social Connect Buttons" width="400" height="200" /></a></p>
<p>Download it here : <a href="http://www.nitinh.com/static/social-connect-botton.psd">Social Connect Buttons [psd]</a></p>
<p>&#160;</p> <a href="http://www.nitinh.com/2011/05/facebook-twitter-instapaper-connect-buttons/" class="read_more">Read More</a></p><p>The post <a href="http://www.nitinh.com/2011/05/facebook-twitter-instapaper-connect-buttons/">Facebook, Twitter, Instapaper Connect Buttons</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>For one of my project I had to use social connect buttons, with Facebook, Twitter, and Instapaper. I tried searching for any buttons that fits my bill, but that went in vain. Later I created these buttons myself using Photoshop. I am releasing these buttons source, may be it&#8217;ll save others time.<span id="more-535"></span><br />
Here is the ScreenShot of these buttons.</p>
<p style="text-align: center;"><a href="http://www.nitinh.com/wp-content/uploads/2011/05/social-connect-botton.png"><img class="size-full wp-image-536 aligncenter" title="Social Connect Buttons" src="http://www.nitinh.com/wp-content/uploads/2011/05/social-connect-botton.png" alt="Social Connect Buttons" width="400" height="200" /></a></p>
<p>Download it here : <a href="http://www.nitinh.com/static/social-connect-botton.psd">Social Connect Buttons [psd]</a></p>
<p>&nbsp;</p>
<p>The post <a href="http://www.nitinh.com/2011/05/facebook-twitter-instapaper-connect-buttons/">Facebook, Twitter, Instapaper Connect Buttons</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p><img src="http://feeds.feedburner.com/~r/TheCodeDreamer/~4/usOqpVu9aE8" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nitinh.com/2011/05/facebook-twitter-instapaper-connect-buttons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.nitinh.com/2011/05/facebook-twitter-instapaper-connect-buttons/</feedburner:origLink></item>
		<item>
		<title>How to Properly Hide and Show Elements Using Javascript</title>
		<link>http://feedproxy.google.com/~r/TheCodeDreamer/~3/i8jE143zL1o/</link>
		<comments>http://www.nitinh.com/2011/05/how-to-properly-hide-and-show-elements-using-javascript/#comments</comments>
		<pubDate>Sun, 15 May 2011 14:50:09 +0000</pubDate>
		<dc:creator>nitin</dc:creator>
				<category><![CDATA[Javascript]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[hide]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://www.nitinh.com/?p=529</guid>
		<description><![CDATA[<p><p>What is the first solution comes to your mind, when someone asks you</p>
<blockquote><p>How can I dynamically hide any element using Javascript ?</p></blockquote>
<p>The obvious solutions to this is to set &#8220;display&#8221; style to &#8220;none&#8221;. Something like this:</p>
<pre lang="javascript">document.getElementById('element').style.display = 'none';</pre>
<p>This will surely work, but is it the correct way to do so? May be not, as you would face problems in showing that element again. The problem in showing that element is that you don&#8217;t know the original display property of that element.</p> <a href="http://www.nitinh.com/2011/05/how-to-properly-hide-and-show-elements-using-javascript/" class="read_more">Read More</a></p><p>The post <a href="http://www.nitinh.com/2011/05/how-to-properly-hide-and-show-elements-using-javascript/">How to Properly Hide and Show Elements Using Javascript</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>What is the first solution comes to your mind, when someone asks you</p>
<blockquote><p>How can I dynamically hide any element using Javascript ?</p></blockquote>
<p>The obvious solutions to this is to set &#8220;display&#8221; style to &#8220;none&#8221;. Something like this:</p>
<pre lang="javascript">document.getElementById('element').style.display = 'none';</pre>
<p>This will surely work, but is it the correct way to do so? May be not, as you would face problems in showing that element again. The problem in showing that element is that you don&#8217;t know the original display property of that element. Whether it was a &#8220;Block&#8221; level element or an &#8220;inline&#8221; element. So, basically you&#8217;ll have to do something like this, depending upon type of element:</p>
<pre lang="javascript">document.getElementById('element').style.display = 'block';
document.getElementById('element').style.display = 'inline';</pre>
<p>Can we do it in some better way?</p>
<h3>Now do it proper way</h3>
<p>An improved way to achieve similar thing  is to create a css class like this:</p>
<pre lang="css">.hide{display:none !important;}</pre>
<p>And now just add or remove this class to hide and show elements.</p>
<pre lang="javascript">document.getElementById('element').className = 'hide';</pre>
<p>or write $(&#8220;element&#8221;).addClass(&#8216;hide&#8217;); if you are using mootools.</p>
<p>The post <a href="http://www.nitinh.com/2011/05/how-to-properly-hide-and-show-elements-using-javascript/">How to Properly Hide and Show Elements Using Javascript</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p><img src="http://feeds.feedburner.com/~r/TheCodeDreamer/~4/i8jE143zL1o" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nitinh.com/2011/05/how-to-properly-hide-and-show-elements-using-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		<feedburner:origLink>http://www.nitinh.com/2011/05/how-to-properly-hide-and-show-elements-using-javascript/</feedburner:origLink></item>
		<item>
		<title>GitHub Setup on Webfaction : How To ?</title>
		<link>http://feedproxy.google.com/~r/TheCodeDreamer/~3/jGqnykNQ6G4/</link>
		<comments>http://www.nitinh.com/2011/02/github-setup-on-webfaction-how-to/#comments</comments>
		<pubDate>Wed, 09 Feb 2011 08:00:47 +0000</pubDate>
		<dc:creator>nitin</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[revision]]></category>
		<category><![CDATA[versioning]]></category>
		<category><![CDATA[webfaction]]></category>

		<guid isPermaLink="false">http://www.nitinh.com/?p=521</guid>
		<description><![CDATA[<p><p><a href="http://git-scm.com/">Git</a> is a very popular distributed revision control system with an emphasis on speed. Recently for my projects I need to setup up a private Git Setup on <a href="http://www.webfaction.com/">Webfaction</a> Server. So here is the way to Install and start using Git on Webfaction.</p>
<h3>How to Install Git on Webfaction</h3>
<ol>
<li>Log into your Webfaction Control Panel</li>
<li>Navigate toÂ <strong>Domains/Websites Â» Applications</strong></li>
<li>ClickÂ <strong>Add New</strong></li>
<li>EnterÂ <em>git</em> as the application name in theÂ <strong>Name</strong> field</li>
<li>SelectÂ <em>git</em> from theÂ <strong>App category</strong> menu</li>
<li>Enter a password for the default user in theÂ <strong>Extra Info</strong> field</li>
<li>Click theÂ <strong>Create</strong> button</li>
</ol>
<p>The Git application provides a subdirectory,Â <tt>bin</tt>, which contains the Git executables.</p> <a href="http://www.nitinh.com/2011/02/github-setup-on-webfaction-how-to/" class="read_more">Read More</a></p><p>The post <a href="http://www.nitinh.com/2011/02/github-setup-on-webfaction-how-to/">GitHub Setup on Webfaction : How To ?</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><a href="http://git-scm.com/">Git</a> is a very popular distributed revision control system with an emphasis on speed. Recently for my projects I need to setup up a private Git Setup on <a href="http://www.webfaction.com/">Webfaction</a> Server. So here is the way to Install and start using Git on Webfaction.</p>
<h3>How to Install Git on Webfaction</h3>
<ol>
<li>Log into your Webfaction Control Panel</li>
<li>Navigate toÂ <strong>Domains/Websites Â» Applications</strong></li>
<li>ClickÂ <strong>Add New</strong></li>
<li>EnterÂ <em>git</em> as the application name in theÂ <strong>Name</strong> field</li>
<li>SelectÂ <em>git</em> from theÂ <strong>App category</strong> menu</li>
<li>Enter a password for the default user in theÂ <strong>Extra Info</strong> field</li>
<li>Click theÂ <strong>Create</strong> button</li>
</ol>
<p>The Git application provides a subdirectory,Â <tt>bin</tt>, which contains the Git executables. It also provides a subdirectory,Â <tt>repos</tt>, to store your Git repositories.Â <tt>repos/proj.git</tt> has been created automatically as an example.</p>
<p>Later you&#8217;ll have to create a Website (Domain/Website -&gt; Website, in Control Panel), which maps this newly created Git application to some subdomain. For further explanation i&#8217;ll assume this domain to be <em><strong>&#8220;git.domain.com&#8221;</strong></em></p>
<p>If you want you can delete existing proj.git by simply deleting this directory.<br />
<code>rmÂ -rÂ ~/webapps/<em>git</em>/repos/<em>proj</em>.git</code></p>
<h3>Create a new Git Repository</h3>
<ol>
<li>Open an SSH session to your webfaction account:Â <code>ssh username@username.webfactional.com</code></li>
<li><code>cd ~/webapps/git/</code></li>
<li><code>./bin/git init --bare ./repos/<em>reponame</em>.git</code><br />
This will create a new repository, whereÂ <em>reponame</em>is the name of your repository</li>
<li><code>cd repos/<em>repo</em>.git</code></li>
<li><code>../../bin/git config http.receivepack true</code><br />
This will enable HTTP push to repository</li>
</ol>
<h3>Pushing local code to this repository</h3>
<ol>
<li><code>cd /path/to/your/local/repository/</code></li>
<li><code>git init</code> If itâ€™s not already under version control</li>
<li><code>git add .</code></li>
<li><code>git commit -a -m 'Initial commit.'</code></li>
<li>If you want to use <strong>SSH mode</strong> then<br />
<code>git remote add origin ssh://username@git.domain.com/~/webapps/git/repos/reponame.git</code><br />
For <strong>HTTP Mode</strong><br />
<code>git remote add origin http://username@git.domain.com/reponame.git</code></li>
<li><code>git push origin master</code></li>
<li><code>git push</code></li>
</ol>
<p>Final Command should give you <code>Everything up-to-date</code> message.</p>
<h3>Introduce Yourself to Git Server</h3>
<p>It is a good idea to introduce yourself to git with your name and public email address before doing any operation. The easiest way to do so is:<br />
<code>git config --global user.name "Nitin Hayaran"</code><br />
<code>git config --global user.email you@yourdomain.example.com</code></p>
<h4>Troubleshooting</h4>
<p>On giving <code>git push origin master</code> command git may throw error <code>error: RPC failed; result=22, HTTP code = 411</code>. It will show you message like this:</p>
<blockquote><p>Compressing objects: 100% (792/792), done.<br />
error: RPC failed; result=22, HTTP code = 411<br />
Writing objects: 100% (1148/1148), 18.79 MiB | 13.81 MiB/s, done.<br />
Total 1148 (delta 356), reused 944 (delta 214)</p></blockquote>
<p>This error comes when either your code size is big, or there is any file with big size. To solve this problem you need to increase buffer size in Git configuration.<br />
<code>git config http.postBuffer 524288000</code></p>
<h3>Clone Your Repository Somewhere New</h3>
<p>With SSH Mode Setup<br />
<code>git clone username@git.domain.com:webapps/git/repos/reponame.git</code><br />
For HTTP Push Mode<br />
<code>git clone http://username@git.domain.com/reponame.git</code></p>
<h4>Further Information</h4>
<ul>
<li><a href="http://docs.webfaction.com/software/git.html">Webfactionâ€™s Git Documentation</a></li>
</ul>
<p>The post <a href="http://www.nitinh.com/2011/02/github-setup-on-webfaction-how-to/">GitHub Setup on Webfaction : How To ?</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p><img src="http://feeds.feedburner.com/~r/TheCodeDreamer/~4/jGqnykNQ6G4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nitinh.com/2011/02/github-setup-on-webfaction-how-to/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.nitinh.com/2011/02/github-setup-on-webfaction-how-to/</feedburner:origLink></item>
		<item>
		<title>Facebook Hacker Cup : Studious Student Problem Solution</title>
		<link>http://feedproxy.google.com/~r/TheCodeDreamer/~3/B9kwHEn6isU/</link>
		<comments>http://www.nitinh.com/2011/01/facebook-hacker-cup-studious-student-problem-solution/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 16:25:40 +0000</pubDate>
		<dc:creator>nitin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[contest]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[hacker cup]]></category>
		<category><![CDATA[studious student]]></category>

		<guid isPermaLink="false">http://www.nitinh.com/?p=517</guid>
		<description><![CDATA[<p><p align="center"><img style="display: block; float: none; margin-left: auto; margin-right: auto" title="Studious Student" alt="Photo Credit" src="http://farm1.static.flickr.com/47/133110591_ef97eb0f4e.jpg" /><span style="font-size: 11px">Photo Credit : <a href="http://www.flickr.com/photos/96499767@N00/133110591/">Helen Morgan</a></span></p>
<p>The Third and final problem of the Facebook Qualification 2011 Round was Studious Student. The problem goes like this: </p>
<h3>Studious Student</h3>
<blockquote><p>You&#8217;ve been given a list of words to study and memorize. Being a diligent student of language and the arts, you&#8217;ve decided to not study them at all and instead make up pointless games based on them. One game you&#8217;ve come up with is to see how you can concatenate the words to generate the lexicographically lowest possible string.</p></blockquote> <a href="http://www.nitinh.com/2011/01/facebook-hacker-cup-studious-student-problem-solution/" class="read_more">Read More</a></p><p>The post <a href="http://www.nitinh.com/2011/01/facebook-hacker-cup-studious-student-problem-solution/">Facebook Hacker Cup : Studious Student Problem Solution</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p align="center"><img style="display: block; float: none; margin-left: auto; margin-right: auto" title="Studious Student" alt="Photo Credit" src="http://farm1.static.flickr.com/47/133110591_ef97eb0f4e.jpg" /><span style="font-size: 11px">Photo Credit : <a href="http://www.flickr.com/photos/96499767@N00/133110591/">Helen Morgan</a></span></p>
<p>The Third and final problem of the Facebook Qualification 2011 Round was Studious Student. The problem goes like this: </p>
<h3>Studious Student</h3>
<blockquote><p>You&#8217;ve been given a list of words to study and memorize. Being a diligent student of language and the arts, you&#8217;ve decided to not study them at all and instead make up pointless games based on them. One game you&#8217;ve come up with is to see how you can concatenate the words to generate the lexicographically lowest possible string.</p>
<h5>Input</h5>
<p>As input for playing this game you will receive a text file containing an integer <strong>N</strong>, the number of word sets you need to play your game against. This will be followed by <strong>N</strong> word sets, each starting with an integer <strong>M</strong>, the number of words in the set, followed by <strong>M</strong> words. All tokens in the input will be separated by some whitespace and, aside from <strong>N</strong> and <strong>M</strong>, will consist entirely of lowercase letters.</p>
<p><strong>Output</strong></p>
<p>Your submission should contain the lexicographically shortest strings for each corresponding word set, one per line and in order.</p>
<p><strong>Constraints</strong></p>
<p>1 &lt;= <strong>N</strong> &lt;= 100       <br />1 &lt;= <strong>M</strong> &lt;= 9       <br />1 &lt;= all word lengths &lt;= 10</p>
<p><strong>Example input        <br /></strong></p>
<p>5      <br />6 facebook hacker cup for studious students       <br />5 k duz q rc lvraw       <br />5 mybea zdr yubx xe dyroiy       <br />5 jibw ji jp bw jibw       <br />5 uiuy hopji li j dcyi</p>
<p><strong>Example output</strong></p>
<p>cupfacebookforhackerstudentsstudious      <br />duzklvrawqrc       <br />dyroiymybeaxeyubxzdr       <br />bwjibwjibwjijp       <br />dcyihopjijliuiuy</p>
</blockquote>
<h4>Analysis and Solution</h4>
<p>This problem is a most confusing out of the lot. Me myself made a silly mistake while solving this problem. On first look it looks like the problem should get solved by sorting and joining the strings, but its not like that.</p>
<p>Consider this following input:</p>
<blockquote><p><b>jibw ji jp bw jibw</b></p>
</blockquote>
<p>By sorting and concatenate, the answer should be is:</p>
<blockquote><p><b>bwjijibwjibwjp</b></p>
</blockquote>
<p>However, lexicographically lowest possible string will be:</p>
<blockquote><p><b>bwjibwjibwjijp</b></p>
</blockquote>
<p>Notice in the above words, &quot;<b>ji</b>&quot; is the prefix of &quot;<b>jibw</b>&quot;. The &quot;<i>sort and concatenate</i>&quot; method definitely does not work when there is a case where a word is a prefix of one or more other words.</p>
<p>Some of the contestants solved this problem with brute force, as input range was not that big. With M&lt;=9 one could have only 9!= <b>362880</b> possible permutations. And answer can be obtained by sorting these permutations. </p>
<p>However, I didnâ€™t went this approach. I used python internal Sort function with custom compare. Here is my code</p>
<p> <script src="https://gist.github.com/776381.js?file=studious_student.py"></script></p>
<p>The post <a href="http://www.nitinh.com/2011/01/facebook-hacker-cup-studious-student-problem-solution/">Facebook Hacker Cup : Studious Student Problem Solution</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p><img src="http://feeds.feedburner.com/~r/TheCodeDreamer/~4/B9kwHEn6isU" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nitinh.com/2011/01/facebook-hacker-cup-studious-student-problem-solution/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.nitinh.com/2011/01/facebook-hacker-cup-studious-student-problem-solution/</feedburner:origLink></item>
		<item>
		<title>Facebook Hacker Cup : Peg Game Problem Solution</title>
		<link>http://feedproxy.google.com/~r/TheCodeDreamer/~3/SDNlMOpOb-4/</link>
		<comments>http://www.nitinh.com/2011/01/facebook-hacker-cup-peg-game-problem-solution/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 16:03:35 +0000</pubDate>
		<dc:creator>nitin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[contest]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[hacker cup]]></category>
		<category><![CDATA[peg game]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.nitinh.com/?p=515</guid>
		<description><![CDATA[<p><p><img style="display: block; float: none; margin-left: auto; margin-right: auto;" src="http://i.imgur.com/Gbi90.jpg" alt="" /></p>
<p>Continuing with my earlier solution of the First Problem â€œ<a href="http://www.nitinh.com/2011/01/facebook-hacker-cup-double-squares-problem-solution/">Double Square</a>â€, here is solution and analysis for Second Problem â€œ<strong>Peg Game</strong>â€</p>
<h3>Peg Game</h3>
<blockquote><p>At the arcade, you can play a simple game where a ball is dropped into the top of the game, from a position of your choosing. There are a number of pegs that the ball will bounce off of as it drops through the game. Whenever the ball hits a peg, it will bounce to the left with probability 0.5 and to the right with probability 0.5.</p></blockquote> <a href="http://www.nitinh.com/2011/01/facebook-hacker-cup-peg-game-problem-solution/" class="read_more">Read More</a></p><p>The post <a href="http://www.nitinh.com/2011/01/facebook-hacker-cup-peg-game-problem-solution/">Facebook Hacker Cup : Peg Game Problem Solution</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><img style="display: block; float: none; margin-left: auto; margin-right: auto;" src="http://i.imgur.com/Gbi90.jpg" alt="" /></p>
<p>Continuing with my earlier solution of the First Problem â€œ<a href="http://www.nitinh.com/2011/01/facebook-hacker-cup-double-squares-problem-solution/">Double Square</a>â€, here is solution and analysis for Second Problem â€œ<strong>Peg Game</strong>â€</p>
<h3>Peg Game</h3>
<blockquote><p>At the arcade, you can play a simple game where a ball is dropped into the top of the game, from a position of your choosing. There are a number of pegs that the ball will bounce off of as it drops through the game. Whenever the ball hits a peg, it will bounce to the left with probability 0.5 and to the right with probability 0.5. The one exception to this is when it hits a peg on the far left or right side, in which case it always bounces towards the middle.<br />
When the game was first made, the pegs where arranged in a regular grid. However, it&#8217;s an old game, and now some of the pegs are missing. Your goal in the game is to get the ball to fall out of the bottom of the game in a specific location. Your task is, given the arrangement of the game, to determine the optimal place to drop the ball, such that the probability of getting it to this specific location is maximized.</p>
<p>The image below shows an example of a game with five rows of five columns. Notice that the top row has five pegs, the next row has four pegs, the next five, and so on. With five columns, there are four choices to drop the ball into (indexed from 0). Note that in this example, there are three pegs missing. The top row is row 0, and the leftmost peg is column 0, so the coordinates of the missing pegs are (1,1), (2,1) and (3,2). In this example, the best place to drop the ball is on the far left, in column 0, which gives a 50% chance that it will end in the goal.</p>
<pre>x.x.x.x.x
 x...x.x
x...x.x.x
 x.x...x
x.x.x.x.x
 G  

'x' indicates a peg, '.' indicates empty space.</pre>
<h5>Input</h5>
<p>You should first read an integer <strong>N</strong>, the number of test cases. Each of the next <strong>N</strong> lines will then contain a single test case. Each test case will start with integers <strong>R</strong> and <strong>C</strong>, the number of rows and columns (<strong>R</strong> will be odd). Next, an integer <strong>K</strong> will specify the target column. Finally, an integer <strong>M</strong> will be followed by <strong>M</strong> pairs of integer <strong>r<sub>i</sub></strong> and <strong>c<sub>i</sub></strong>, giving the locations of the missing pegs.</p>
<p>Constraints</p>
<ul>
<li>1 â‰¤ <strong>N</strong> â‰¤ 100</li>
<li>3 â‰¤ <strong>R</strong>,<strong>C</strong> â‰¤ 100</li>
<li>The top and bottom rows will not have any missing pegs.</li>
<li>Other parameters will all be valid, given <strong>R</strong> and <strong>C</strong></li>
</ul>
<h5>Output</h5>
<p>For each test case, you should output an integer, the location to drop the ball into, followed by the probability that the ball will end in columns <strong>K</strong>, formatted with exactly six digits after the decimal point (round the last digit, don&#8217;t truncate).</p>
<p><strong>Notes</strong></p>
<p>The input will be designed such that minor rounding errors will not impact the output (i.e. there will be no ties or near &#8212; up to 1E-9 &#8212; ties, and the direction of rounding for the output will not be impacted by small errors).</p>
<h5>Example input</h5>
<p>4<br />
5 4 0 1 2 2<br />
3 3 1 2 1 1 1 0<br />
3 4 0 2 1 0 1 1<br />
3 4 0 1 1 1</p>
<h5>Example Output</h5>
<p>0 0.375000<br />
1 1.000000<br />
0 1.000000<br />
0 0.500000</p></blockquote>
<h4>Analysis and Solution</h4>
<p>This is the hardest problem of the lot, and I also spent hours to understand the problem statement. If you are also among those who havenâ€™t got this problem then, I would recommend you to read its explanation <a href="http://illya-keeplearning.blogspot.com/2011/01/peg-game-explanation.html">here</a>.</p>
<p>Once I understood problem statement, next hurdle was to have map this in programming paradigm. I went with a double size two-dimension array [row*2, col*2], to hold complete Input. Basically it was holding both <strong>Pegs, </strong>and <strong>Pits</strong>(blank space from where ball can pass).</p>
<p>For solving the problem I approached it from bottom, assuming that to get ball at X and probability 1. Then we move to above row and back calculate possible probabilities for every <strong>pit.</strong></p>
<p>The code to solve this problem is:</p>
<p><script src="https://gist.github.com/776348.js?file=peg_game.py"></script></p>
<p>The post <a href="http://www.nitinh.com/2011/01/facebook-hacker-cup-peg-game-problem-solution/">Facebook Hacker Cup : Peg Game Problem Solution</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p><img src="http://feeds.feedburner.com/~r/TheCodeDreamer/~4/SDNlMOpOb-4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nitinh.com/2011/01/facebook-hacker-cup-peg-game-problem-solution/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		<feedburner:origLink>http://www.nitinh.com/2011/01/facebook-hacker-cup-peg-game-problem-solution/</feedburner:origLink></item>
		<item>
		<title>Facebook Hacker Cup : Double Squares Problem Solution</title>
		<link>http://feedproxy.google.com/~r/TheCodeDreamer/~3/DZ9H3rAz2Q4/</link>
		<comments>http://www.nitinh.com/2011/01/facebook-hacker-cup-double-squares-problem-solution/#comments</comments>
		<pubDate>Wed, 12 Jan 2011 15:31:40 +0000</pubDate>
		<dc:creator>nitin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[context]]></category>
		<category><![CDATA[double square]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[hacker cup]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.nitinh.com/?p=511</guid>
		<description><![CDATA[<p><p><img style="margin: 0px 10px 10px 0px; float: left;" src="http://i.imgur.com/ReZ6Z.jpg" alt="" /></p>
<p>A lot of people have participated and qualified in <a href="http://www.facebook.com/hackercup/problems.php?round=4">Qualification Round</a> of <a href="http://www.facebook.com/hackercup">Facebook Hacker Cup</a>. Luckily I am also qualified for <a href="http://www.facebook.com/event.php?eid=108867785836213&#38;index=1">First Round</a>. Facebook Hacker Cup Qualification Round consisted 3 problems. All of these problems were programmatically easy but tricky. Lots of people made very simple mistakes while solving these problem(including me).</p>
<p>First Problem of the round was:</p>
<h3>Double Squares</h3>
<blockquote><p>A double-square number is an integer <strong>X</strong> which can be expressed as the sum of two perfect squares. For example, 10 is a double-square because 10 = 3<sup>2</sup>+ 1<sup>2</sup>.</p></blockquote> <a href="http://www.nitinh.com/2011/01/facebook-hacker-cup-double-squares-problem-solution/" class="read_more">Read More</a></p><p>The post <a href="http://www.nitinh.com/2011/01/facebook-hacker-cup-double-squares-problem-solution/">Facebook Hacker Cup : Double Squares Problem Solution</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p>]]></description>
				<content:encoded><![CDATA[<p><img style="margin: 0px 10px 10px 0px; float: left;" src="http://i.imgur.com/ReZ6Z.jpg" alt="" /></p>
<p>A lot of people have participated and qualified in <a href="http://www.facebook.com/hackercup/problems.php?round=4">Qualification Round</a> of <a href="http://www.facebook.com/hackercup">Facebook Hacker Cup</a>. Luckily I am also qualified for <a href="http://www.facebook.com/event.php?eid=108867785836213&amp;index=1">First Round</a>. Facebook Hacker Cup Qualification Round consisted 3 problems. All of these problems were programmatically easy but tricky. Lots of people made very simple mistakes while solving these problem(including me).</p>
<p>First Problem of the round was:</p>
<h3>Double Squares</h3>
<blockquote><p>A double-square number is an integer <strong>X</strong> which can be expressed as the sum of two perfect squares. For example, 10 is a double-square because 10 = 3<sup>2</sup>+ 1<sup>2</sup>. Your task in this problem is, given <strong>X</strong>, determine the number of ways in which it can be written as the sum of two squares. For example, 10 can only be written as 3<sup>2</sup> + 1<sup>2</sup> (we don&#8217;t count 1<sup>2</sup> + 3<sup>2</sup> as being different). On the other hand, 25 can be written as 5<sup>2</sup> + 0<sup>2</sup> or as 4<sup>2</sup> + 3<sup>2</sup>.</p>
<p><strong>Input</strong></p>
<p>You should first read an integer <strong>N</strong>, the number of test cases. The next <strong>N</strong> lines will contain <strong>N</strong> values of <strong>X</strong>.</p>
<h5>Constraints</h5>
<p>0 â‰¤ <strong>X</strong> â‰¤ 2147483647<br />
1 â‰¤ <strong>N</strong> â‰¤ 100</p>
<p><strong>Output</strong></p>
<p>For each value of <strong>X</strong>, you should output the number of ways to write <strong>X</strong> as the sum of two squares.</p>
<p>Example input</p>
<p>5<br />
10<br />
25<br />
3<br />
0<br />
1</p>
<p>Example output</p>
<p>1<br />
2<br />
0<br />
1<br />
1</p></blockquote>
<h4>Analysis and Solution</h4>
<p>This problem was by far the easiest of the lot. But as Facebook title for the problem said â€œ<em>Too hard for brute force, switching to dp</em>â€, this problem was almost impossible to be solved with Brute Force.</p>
<p>The strategy I used was quite simple. If we consider M is the given number, and we want to find out x, y such that:</p>
<blockquote><p>M = x^2 + y^2</p></blockquote>
<p>So basically weâ€™ll loop from 0 to sqrt(M) and will find out D such that:</p>
<blockquote><p>D = M â€“ i*i</p></blockquote>
<p>and if D is square root is an integer then, this number is a double square.</p>
<p>The python code of this problem is:</p>
<p><script src="https://gist.github.com/776298.js?file=double_square.py"></script></p>
<p>The post <a href="http://www.nitinh.com/2011/01/facebook-hacker-cup-double-squares-problem-solution/">Facebook Hacker Cup : Double Squares Problem Solution</a> appeared first on <a href="http://www.nitinh.com">NitinH.com</a>.</p><img src="http://feeds.feedburner.com/~r/TheCodeDreamer/~4/DZ9H3rAz2Q4" height="1" width="1"/>]]></content:encoded>
			<wfw:commentRss>http://www.nitinh.com/2011/01/facebook-hacker-cup-double-squares-problem-solution/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<feedburner:origLink>http://www.nitinh.com/2011/01/facebook-hacker-cup-double-squares-problem-solution/</feedburner:origLink></item>
	</channel>
</rss>
