<?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>RV &#124; Developers</title>
	<atom:link href="http://developers.redventures.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://developers.redventures.com</link>
	<description>Banter from the IT trenches</description>
	<lastBuildDate>Tue, 26 Jul 2011 14:19:47 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Memoization</title>
		<link>http://developers.redventures.com/2011/07/memoization/</link>
		<comments>http://developers.redventures.com/2011/07/memoization/#comments</comments>
		<pubDate>Tue, 26 Jul 2011 14:19:47 +0000</pubDate>
		<dc:creator>Garrett Johnson</dc:creator>
				<category><![CDATA[Public]]></category>

		<guid isPermaLink="false">http://developers.redventures.com/?p=279</guid>
		<description><![CDATA[I was recently cleaning up a snippet of JavaScript that did something like the following.

var run = function(){

	var links = document.getElementById('results').getElementsByTagName('a');

	// some more code dealing with the DOM
	// bla bla bla.....

	// test for host and make decision based off or it
	if (document.location.host === 'google.com') {
		//...
	} else if (document.location.host === 'bing.com') {
		//...
	} else if (document.location.host === [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently cleaning up a snippet of JavaScript that did something like the following.</p>
<pre class="brush: jscript; title: ;">
var run = function(){

	var links = document.getElementById('results').getElementsByTagName('a');

	// some more code dealing with the DOM
	// bla bla bla.....

	// test for host and make decision based off or it
	if (document.location.host === 'google.com') {
		//...
	} else if (document.location.host === 'bing.com') {
		//...
	} else if (document.location.host === 'yahoo.com') {
		//...
	}

};

window.addEventListener('load', run, false);
window.addEventListener('hashchange', run, false);
</pre>
<p>While this does get the job done, it’s a bit repetitive, especially when being invoked multiple times. Once the page loads, we know what the host is, why should our functions be forced to do branching logic on something we already know? We could clean this up a good deal if we could just remember what our decisions the first time our function was called. This is a concept known as memoization.</p>
<pre class="brush: jscript; title: ;">
var run = (function(){

	var links = document.getElementById('results').getElementsByTagName('a');

	// some more code dealing with the DOM
	// bla bla bla.....

	// test for host and make decision based off or it
	if (document.location.host === 'google.com') {
		return function() {
			// ...
		};
	} else if (document.location.host === 'bing.com') {
		return function() {
			// ...
		};
	} else if (document.location.host === 'yahoo.com') {
		return function(){
			// ...
		};
	}

})();

window.addEventListener('load', run, false);
window.addEventListener('hashchange', run, false);
</pre>
<p>Since JavaScript is awesome, we can simply just return another function from our function into a variable when the page initially loads, and from there on out, we will only be invoking a function that cares about the context which we are in. This also forms a closure, so our function still has a reference to the links variable.</p>
<p>No more waiting precious milliseconds figuring out something we already know. Yay for smarter code!</p>
]]></content:encoded>
			<wfw:commentRss>http://developers.redventures.com/2011/07/memoization/feed/</wfw:commentRss>
		<slash:comments></slash:comments>
		</item>
		<item>
		<title>The 10 Commandments of Programmers</title>
		<link>http://developers.redventures.com/2011/07/the-10-commandments-of-programmers/</link>
		<comments>http://developers.redventures.com/2011/07/the-10-commandments-of-programmers/#comments</comments>
		<pubDate>Mon, 25 Jul 2011 14:09:26 +0000</pubDate>
		<dc:creator>Mardochee</dc:creator>
				<category><![CDATA[Public]]></category>
		<category><![CDATA[Abstract Principle]]></category>
		<category><![CDATA[DRY]]></category>
		<category><![CDATA[KISS]]></category>
		<category><![CDATA[SOC]]></category>

		<guid isPermaLink="false">http://developers.redventures.com/?p=289</guid>
		<description><![CDATA[Over the years of programming, most of these commandments came naturally to me and I didn’t even realize there was a term for some of them.  Code is not something you just write and it gets executed by the machine. Ok, yeah, it’s something that you just write and gets executed by the machine. But, [...]]]></description>
			<content:encoded><![CDATA[<p>Over the years of programming, most of these commandments came naturally to me and I didn’t even realize there was a term for some of them.  Code is not something you just write and it gets executed by the machine. Ok, yeah, it’s something that you just write and gets executed by the machine. But, Code is poetry. I always want it to be a beautiful piece to write, a joy to refactor and a pleasure to be executed by the machine. Technically, it’s me talking to the machine, right…? (E.T phone home?)</p>
<p>So after walking thru long miles in the desert, splitting the Red Sea, coming back from the Mount Sinai, I bring you the 10 Commandments of Programmers.  (For those who don’t know, I’m referencing Moses in the bible)</p>
<p style="text-align: center;"><img class="aligncenter" src="http://img.dailymail.co.uk/i/pix/2008/03_01/mosesHeston2703_468x611.jpg" alt="" width="270" height="352" /></p>
<h2><strong><span style="text-decoration: underline;">DRY</span></strong>: (Don’t repeat yourself)</h2>
<p>It’s fundamental in programming that allows you to not repeat yourself. When the DRY principle is applied successfully, a modification of any single element of a system does not change other logically-unrelated elements</p>
<p><a href="http://en.wikipedia.org/wiki/Don%27t_repeat_yourself" target="_blank">http://en.wikipedia.org/wiki/Don%27t_repeat_yourself</a></p>
<h2><strong><span style="text-decoration: underline;">KISS</span></strong>: (Keep it Simple Stupid)</h2>
<p>A common problem among software engineers and developers today is that they tend to over complicate problems. Simplicity (and avoiding complexity) should always be a key goal. Simple code takes less time to write, has fewer bugs, and is easier to modify.</p>
<p><a href="http://people.apache.org/~fhanik/kiss.html" target="_blank">http://people.apache.org/~fhanik/kiss.html</a></p>
<h2><strong><span style="text-decoration: underline;">Separation of Concerns</span></strong></h2>
<p>Separation of concern is the process of separating a computer program into distinct features that overlap in functionality as little as possible.</p>
<p><a href="http://developers.redventures.com/2011/02/on-the-to-changes-separation-of-concerns/" target="_blank">http://developers.redventures.com/2011/02/on-the-to-changes-separation-of-concerns/</a></p>
<h2><strong><span style="text-decoration: underline;">Open/Close Principle</span></strong></h2>
<p>Software entities (classes, functions, etc.) should be open for extension, but closed for modification. In other words, don&#8217;t write classes that people can modify, write classes that people can extend. This is especially valuable in a production environment, where changes to source code may necessitate code reviews, unit tests, and other such procedures to qualify it for use in a product: code obeying the principle doesn&#8217;t change when it is extended, and therefore needs no such effort.</p>
<p><a href="http://en.wikipedia.org/wiki/Open_Closed_Principle" target="_blank">http://en.wikipedia.org/wiki/Open_Closed_Principle</a></p>
<h2><strong><span style="text-decoration: underline;">Abstraction Principle</span></strong>.</h2>
<p>Related to DRY is the abstraction principle “Each significant piece of functionality in a program should be implemented in just one place in the source code.”</p>
<p><a href="http://en.wikipedia.org/wiki/Abstraction_principle_(programming)" target="_blank">http://en.wikipedia.org/wiki/Abstraction_principle_(programming)</a></p>
<h2><strong><span style="text-decoration: underline;">Single Responsibility Principle</span></strong></h2>
<p>In object-oriented programming, the <strong>single responsibility principle</strong> states that every object should have a single responsibility, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility.</p>
<p>The reason it is important to keep a class focused on a single concern is that it makes the class more robust. Continuing with the foregoing example, if there is a change to the report compilation process, there is greater danger that the printing code will break if it is part of the same class.</p>
<p><a href="http://en.wikipedia.org/wiki/Single_responsibility_principle" target="_blank">http://en.wikipedia.org/wiki/Single_responsibility_principle</a></p>
<h2><strong><span style="text-decoration: underline;">Code Reuse </span></strong></h2>
<p>Related to the DRY principle. Code reuse is the idea that a partial or complete computer program written at one time can be, should be, or is being used in another program written at a later time. The reuse of programming code is a common technique which attempts to save time and energy by reducing redundant work.</p>
<p><a href="http://en.wikipedia.org/wiki/Code_reuse" target="_blank">http://en.wikipedia.org/wiki/Code_reuse</a></p>
<h2><strong><span style="text-decoration: underline;">Maximize Cohesion</span></strong>:</h2>
<p>Code that has similar functionality should be found within the same component. <strong>Cohesion</strong> is a measure of how strongly-related or focused the responsibilities of a single module are. As applied to object-oriented programming, if the methods that serve the given class tend to be similar in many aspects, then the class is said to have high cohesion. In a highly-cohesive system, code readability and the likelihood of reuse is increased, while complexity is kept manageable.</p>
<p><a href="http://en.wikipedia.org/wiki/Cohesion_(computer_science)" target="_blank">http://en.wikipedia.org/wiki/Cohesion_(computer_science)</a></p>
<h2><strong><span style="text-decoration: underline;">Minimize coupling: </span></strong></h2>
<p>Any section of code (code block, function, class, etc) should minimize the dependencies on other areas of code. This is achieved by using shared variables as little as possible. “Low coupling is often a sign of a well-structured computer system and a good design, and when combined with high cohesion, supports the general goals of high readability and maintainability”</p>
<p><a href="http://en.wikipedia.org/wiki/Coupling_(computer_programming)" target="_blank">http://en.wikipedia.org/wiki/Coupling_(computer_programming)</a></p>
<h2><strong><span style="text-decoration: underline;">POLA: Principle of Least Astonishment</span></strong></h2>
<p>Code should surprise the reader as little as possible. The means following standard conventions, code should do what the comments and name suggest, and potentially surprising side effects should be avoided as much as possible.</p>
<p><a href="http://en.wikipedia.org/wiki/Principle_of_least_astonishment" target="_blank">http://en.wikipedia.org/wiki/Principle_of_least_astonishment</a></p>
<p>Follow these commandments and your code will be like heaven&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://developers.redventures.com/2011/07/the-10-commandments-of-programmers/feed/</wfw:commentRss>
		<slash:comments></slash:comments>
		</item>
		<item>
		<title>The Rise of NoSQL</title>
		<link>http://developers.redventures.com/2011/05/the-rise-of-nosql/</link>
		<comments>http://developers.redventures.com/2011/05/the-rise-of-nosql/#comments</comments>
		<pubDate>Fri, 06 May 2011 14:54:42 +0000</pubDate>
		<dc:creator>Mardochee</dc:creator>
				<category><![CDATA[Public]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[nosql]]></category>
		<category><![CDATA[scalability]]></category>

		<guid isPermaLink="false">http://developers.redventures.com/?p=196</guid>
		<description><![CDATA[
SQL databases have been rocking the programming world since the 70’s.  Lots of stuff have changed since, we have something called “internets”  and it’s revolutionizing how stuff was done before.  We buy, sell, contact, write, play, entertain, watch movies (in 3D heck yeah!), get scammed by Nigerian, tweet about cat, download music for free on [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter" src="http://agilevietnam.com/wp-content/uploads/2010/08/nosql.png" alt="" width="278" height="256" /></p>
<p>SQL databases have been rocking the programming world since the 70’s.  Lots of stuff have changed since, we have something called “<strong><a href="http://www.youtube.com/watch?v=LKTH6f1JfX8" target="_blank">internets</a></strong>”  and it’s revolutionizing how stuff was done before.  We buy, sell, contact, write, play, entertain, watch movies (in 3D heck yeah!), get scammed by Nigerian, tweet about cat, download music for free on the INTERNETS etc.  And some people have been jailed, sued,  reprimanded because of the INTERNETS. So, “<strong><a href="http://www.youtube.com/watch?v=CMNry4PE93Y" target="_blank">I like turtle</a></strong>”. Yeah!  Famous quotes can make you become an internet sensation.  “<strong><a href="http://www.youtube.com/watch?v=hMtZfW2z9dw&amp;hd=1" target="_blank">So hide your wife, hide your kids and hide your husband, &#8230;</a></strong>.  ”, because there is a bed intruder out there.</p>
<p>Because of the internet, data has grown to a point where relational databases are not the right fit . Not all data are relational. Hence several companies (Google, Facebook, Amazon…) start building their own datastore.</p>
<p>2010, in my opinion,  was the year of scalability, big data, and the rise of the NoSQL movement.</p>
<p>NoSQL was first defined as NO to SQL. But later was changed to Not Only SQL, because SQL still excels in some area while NoSQL DB will kick SQL’s derriere in some.  <strong>The term “NoSQL” typically refers to non-relational, distributed databases that do not require fixed-table schemas.</strong></p>
<p>NoSQL databases are schema-less, schema-full,  schema-mixed.  And the best part, they don’t require any <strong>JOIN</strong>s.  What? Yes sir! No JOINs.</p>
<p>Most modern relational databases have shown poor performance on certain data-intensive applications, including indexing a large number of documents, serving pages on high traffic websites and delivering streaming media.  NoSQL on the other side provides heavy read/write workloads. It allows rapid application development and your schema lives within your application.</p>
<p>Some people will find it really hard to understand how the NoSQL DB work.  One thing I will suggest first, <strong>is not to think like SQL</strong> (UNSQL yourself);  But unfortunately after  writing  “SELECT * FROM TABLE” so many times, it’s hard to get out of there.  But I’m going to try my best to break it down…. But on some real &#8220;shizzle&#8221;, one should make his/her own extended  research on the NoSQL DB to know more.</p>
<p>Let’s get to know some of the most popular, and we’ll leave the best,  for last (playing african drum in your head and sing: Mongo, Mongo, Mongo…)</p>
<h2><strong>Classes of NoSQL DB</strong><img class="alignright" src="http://www.hackerspacepp.org/wp-content/uploads/2011/01/nosql-databases.png" alt="" width="340" height="187" /></h2>
<p>There are three main classes of NoSQL DB.</p>
<p><strong>Key/Val</strong><strong>ue Store</strong>. It holds data as Key-Value pair such that values are indexed to be retrieved by keys. Key/Value Store DB can hold structured and unstructured data.  In this family of DB there are <a href="http://wiki.basho.com/" target="_blank">Riak</a> , <a href="http://redis.io/" target="_blank">Redis</a>.</p>
<p><strong>Column-Oriented DB</strong>.  It contains one extendable column of closely related data rather than sets of information in a strictly structured table of columns and rows as is found in relational databases.  In this family there is <a href="http://cassandra.apache.org" target="_blank">Cassandra</a>, <a href="http://hbase.apache.org/">HBase</a>.</p>
<p><strong>Document  Based DB</strong>. Data is stored and organized as a collection of documents. Users are allowed to add any number of fields of any length to a document. They tend to store JSON-based documents in their database. In this class, there is <a href="http://www.mongodb.org" target="_blank">MongoDB</a>, <a href="http://couchdb.apache.org" target="_blank">CouchDB</a>.</p>
<p>For a full list of NoSQL DB, <a href="http://nosql-database.org/" target="_blank">CLICK HERE</a> (you see what I did here?)</p>
<p>Of course before choosing  a database from  any of these classes one should make their due diligence, tests and benchmarks. So many people jumped from relational to NOSQL  just to go back to relational again because they were doing it wrong or didn&#8217;t know what they were doing.</p>
<p>Anyway&#8230;</p>
<p><a href="http://www.inflexwetrust.com/wp-content/uploads/2011/03/Tiger-Blood-Drink.jpg"><img class="size-medium wp-image-203 alignleft" src="http://www.inflexwetrust.com/wp-content/uploads/2011/03/Tiger-Blood-Drink.jpg" alt="" width="200" height="300" /></a></p>
<h2><strong>MongoDB is the Tiger Blood of Database. When you use it, it&#8217;s #Winning.</strong></h2>
<p>Now among all the NoSQL db, I prefer Mongo. Well, MongoDB makes sense. It is the scripting language of the databases.  I’ve been working with it for more than a year now.  While it may not solve all relational database issues, putting the right thought in your application and your database schema will make you kick relational databases&#8217; butt (and it&#8217;s fun to do).</p>
<p>Installing and running MongoDB is super easy. You just download, and launch the mongod file.  Upgrading to the latest version is as easy as making coffee after 2pm. You just replace the old binaries with the new one and you are up to date and MongoDB comes with replication and sharding.</p>
<p>Like most NoSQL DB, MongoDB is Webscale, you can use it for MapReduce, you can store files in it. You can make it “Like Turtle” technically do anything. It is just a versatile storage engine.  Whenever you feel like looking at a NoSQL database that have a similarity to your favorite relational database, check out MongoDB.</p>
<p><span style="text-decoration: underline;">How would a document look like in Mongo?</span></p>
<p>MongoDB Documents are like JSON, and is trongly typed. It can hold: String, Array, Integer, Float etc&#8230;</p>
<p>The collection below holds three documents.</p>
<pre class="brush: php; title: ;">

{
 &quot;compID&quot;: 1111, // Holds integer

 &quot;companyName&quot;: &quot;RedVentures&quot;, // holds string

 &quot;isLive&quot;: true, // hold boolean

 &quot;uniqueContactFields&quot;:[&quot;Address&quot;,&quot;PhoneNumber&quot;], // Holds array

 &quot;avgLoadTime&quot;:0.17, // holds float
}

{
 &quot;compID&quot;: 2222,

 &quot;companyName&quot;: &quot;DirectTV&quot;,

 &quot;isLive&quot;: true,

 &quot;uniqueContactFields&quot;:[&quot;LastName&quot;,&quot;HomePhone&quot;,&quot;Zip&quot;],

 &quot;avgLoadTime&quot;:0.15,
}

{
 &quot;compID&quot;: 333,

 &quot;companyName&quot;: &quot;NurfSquad&quot;,

 &quot;isLive&quot;: false,

 &quot;uniqueContactFields&quot;:[&quot;LastName&quot;,&quot;Zip&quot;,&quot;PhoneNumber&quot;],

 &quot;avgLoadTime&quot;:0.12,
}
</pre>
<p>Let get some terminology before we go into more codes.</p>
<p>10Gen, the company behind MongoDB, made sure there are some similarities between SQL and Mongo while keeping it NoSQL in a non relational world.</p>
<p>In MongoDB a database is just like a database in relational db. &#8220;Duh!&#8221;</p>
<p>Collections in MongoDB can be like Tables and Documents are like Rows.</p>
<p>So a Document is in a Collection, and the Collection is in the Database. And of course a Collection will have more than one Document, and a database can have more than one Collection.</p>
<p>So the similarities are there except it&#8217;s bananas fun!</p>
<p>Now let&#8217;s connect to the DB:</p>
<pre class="brush: php; title: ;">

$Mongo = new mongo();

$MongoCorpDB = $Mongo-&gt;selectDB(“RVWins”)

$Companies = $MongoCorpDB-&gt;selectCollection(“Companies”);
</pre>
<p>Get all the companies:</p>
<pre class="brush: php; title: ;">

$allCompanies = $Companies-&gt;find();
</pre>
<p>Now, get all companies that are live</p>
<pre class="brush: php; title: ;">

$allCompanies = $Companies-&gt;find(array(“isLive”=&gt;true));
</pre>
<p>It will return the documents having companyName: RedVentures &amp; DirectTV  All companies that are not live</p>
<pre class="brush: php; title: ;">

$allCompanies = $Companies-&gt;find(array(“isLive”=&gt;false));
</pre>
<p>It will return the documents having companyName: NurfSquad.</p>
<p>Now let&#8217;s find documents based on criteria having values in an array.  All Companies where uniqueContactFields = PhoneNumber</p>
<pre class="brush: php; title: ;">

$allCompanies = $Companies-&gt;find(array(“uniqueContactFields”=&gt;”PhoneNumber”))
</pre>
<p>It will return the documents having companyName:  RedVentures and NurfSquad.  As you can see, uniqeContactFields is an array, and Mongo can find documents matching a criteria in an array.  Now let&#8217;s get all the documents again. It will sort all document by avgLoadTime from highest to lowest, and return only 10.</p>
<pre class="brush: php; title: ;">

  $allCompanies = $Companies-&gt;find()-&gt;sort(array(&quot;avgLoadTime&quot;=&gt;-1))-&gt;limit(10);

  foreach($allCompanies as $company){

      print(&quot;{$company[companyName]} average load time: {$company[avgLoadTime]}&quot;);

      print(&quot;&lt;br&gt;&quot;);

  }
</pre>
<p>As you ca see, working with MongoDB is like working with your own classes in your own projects. That&#8217;s #bi-winning.</p>
<p>And what if I want to update some data.  Well let&#8217;s change the avgLoadTime for the compID: 2222 to 0.25</p>
<pre class="brush: php; title: ;">

$Companies-&gt;update(array(compID:222),array('$set'=&gt;array(&quot;avgLoadTime&quot;:0.25)));
</pre>
<p>That was easy right? Now let&#8217;s say someone wants to add one extra field for only the companyName NurfSquad.  Let&#8217;s add a field hasHaitian, where it&#8217;s a boolean.</p>
<pre class="brush: php; title: ;">

$Companies-&gt;update(array(compID:333),array('$set'=&gt;array(&quot;hasHaitian&quot;:true)));
</pre>
<p>Now the NurfSquad document has a field called hasHaitian, while the others don&#8217;t have it.  Now let&#8217;s look at our final db data. I also added a members fields, where it holds an object of all members with their properties</p>
<pre class="brush: php; title: ;">
{

                &quot;compID&quot;: 1111,

                &quot;companyName&quot;: &quot;RedVentures&quot;,

                &quot;isLive&quot;: true,

                &quot;uniqueContactFields&quot;:[&quot;Address&quot;,&quot;PhoneNumber&quot;],

                &quot;avgLoadTime&quot;:0.17,

}

{

                &quot;compID&quot;: 2222,

                &quot;companyName&quot;: &quot;DirectTV&quot;,

                &quot;isLive&quot;: true,

                &quot;uniqueContactFields&quot;:[&quot;LastName&quot;,&quot;HomePhone&quot;,&quot;Zip&quot;],

                &quot;avgLoadTime&quot;:0.25,

}

{

                &quot;compID&quot;: 333,

                &quot;companyName&quot;: &quot;NurfSquad&quot;,

                &quot;isLive&quot;: false,

                &quot;uniqueContactFields&quot;:[&quot;LastName&quot;,&quot;Zip&quot;,&quot;PhoneNumber&quot;],

                &quot;avgLoadTime&quot;:0.12,

                &quot;hasHaitian&quot;:true,

                &quot;members&quot;:[

                                                {

                                                  &quot;name&quot;:&quot;Colin&quot;,

                                                  &quot;seat&quot;:&quot;2-W-123&quot;

                                                },

                                                {

                                                  &quot;name&quot;:&quot;Brandon&quot;,

                                                  &quot;seat&quot;:&quot;2-V-12&quot;

                                                },

                                                {

                                                  &quot;name&quot;:&quot;Mardix&quot;,

                                                  &quot;seat&quot;:&quot;1-V-34&quot;,

                                                  &quot;isHaitian&quot;:true

                                                },

                                                {

                                                  &quot;name&quot;:&quot;Ryan&quot;,

                                                  &quot;seat&quot;:&quot;3-A-13&quot;

                                                },

                                                {

                                                  &quot;name&quot;:&quot;Deny&quot;,

                                                  &quot;seat&quot;:&quot;4-P-235&quot;

                                                },

                                                {

                                                  &quot;name&quot;:&quot;Kyle&quot;,

                                                  &quot;seat&quot;:&quot;1-W-123&quot;

                                                },

                                                {

                                                  &quot;name&quot;:&quot;Stephens&quot;,

                                                  &quot;seat&quot;:&quot;2-Q-12&quot;

                                                },

                                ]

}
</pre>
<p>That&#8217;s how the document database look like. As simple as it is, as simple you get the data.  I hope you get a good idea, and this can spin your imagination to the world of NoSQL.</p>
<p>Next time you have a project and you can decide which database to pick, take a look at <a href="http://mongodb.org" target="_blank">MongoDB</a>, you will be #winning!</p>
<pre>
<div style="width: 1px; height: 1px; overflow: hidden;"> "compID": 1111,
"companyName": "RedVentures",

"isLive": true,

"uniqueContactFields":["Address","PhoneNumber"],

"avgLoadTime":0.17,
 }

{
 "compID": 2222,

"companyName": "DirectTV",

"isLive": true,

"uniqueContactFields":["LastName","HomePhone","Zip"],

"avgLoadTime":0.25,
 }

{
 "compID": 333,

"companyName": "NurfSquad",

"isLive": false,

"uniqueContactFields":["LastName","Zip","PhoneNumber"],

"avgLoadTime":0.12,

"hasHaitian":true,

"members":[
 {
 "name":"Colin",
 "seat":"2-W-123"
 },
 {
 "name":"Brandon",
 "seat":"2-V-12"
 },
 {
 "name":"Mardix",
 "seat":"1-V-34",
 "isHaitian":true
 },
 {
 "name":"Ryan",
 "seat":"3-A-13"
 },
 {
 "name":"Deny",
 "seat":"4-P-235"
 },
 {
 "name":"Kyle",
 "seat":"1-W-123"
 },
 {
 "name":"Stephens",
 "seat":"2-Q-12"
 },

]

}</div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://developers.redventures.com/2011/05/the-rise-of-nosql/feed/</wfw:commentRss>
		<slash:comments></slash:comments>
		</item>
		<item>
		<title>Cookie Curiosity</title>
		<link>http://developers.redventures.com/2011/04/cookie-curiosity/</link>
		<comments>http://developers.redventures.com/2011/04/cookie-curiosity/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 14:30:35 +0000</pubDate>
		<dc:creator>Kyle Getson</dc:creator>
				<category><![CDATA[Public]]></category>

		<guid isPermaLink="false">http://developers.redventures.com/?p=177</guid>
		<description><![CDATA[While I was reading HTTP RFC information (everyone reads this stuff right?), I came across a section labeled &#8216;Implementation Limits&#8217;. Like most poeple, I don&#8217;t think there there is such a thing as too many cookies (assuming you have a glass of milk), but apparently browsers feel differently. According to the RFC documentation on the Set-Cookie header, there [...]]]></description>
			<content:encoded><![CDATA[<p>While I was reading <a href="http://www.ietf.org/rfc/rfc2109.txt" target="_blank">HTTP RFC</a> information (everyone reads this stuff right?), I came across a section labeled &#8216;Implementation Limits&#8217;. Like most poeple, I don&#8217;t think there there is such a thing as too many cookies (assuming you have a glass of milk), but apparently browsers feel differently. According to the RFC documentation on the Set-Cookie header, there is a minimum amount that a browser should set the maximum amount to be. That&#8217;s a bit confusing, so I&#8217;ll state it differently, according to the documentation, a browser should accept at least 300 cookies total (for all visited sites), at least 20 cookies per hostname, with 4096 bytes of space per cookie.<br />
<span id="more-177"></span></p>
<p>After googling a bit, I couldnt find any reliable documentation that specified limits on today&#8217;s popular browsers, such as Internet Explorer, Firefox, Chrome, or Safari. So I wrote a php script to test out a few things. I had two main goals in mind with this,<strong> find the maximum number of cookies for various browsers</strong> (if there is one), and<strong> find out what happens when that limit is exceeded</strong>. This isnt meant to be a comprehensive list, but just interesting results that I&#8217;ve found. This was all done on windows.</p>
<style>
.test_details td { border: 1px solid #000;}
</style>
<table class="test_details">
<tbody>
<tr>
<td>Browser</td>
<td width="160">Per HostName Limit</td>
<td>What Happens When Exceeded</td>
</tr>
<tr>
<td>FireFox</td>
<td>50</td>
<td>Only the most recent 50 cookies are sent with requests</td>
</tr>
<tr>
<td>Chrome</td>
<td>~150</td>
<td>Once the the number of cookies gets close to 150, Chromes behavior is inconsistent. It seems to send an inconsistent set of cookies during requests, generally around 150.</td>
</tr>
<tr>
<td>IE 8</td>
<td>50</td>
<td>Only the most recent 50 cookies are sent</td>
</tr>
<tr>
<td>Safari (Windows)</td>
<td>297</td>
<td>Only the most recent 297 cookies are sent</td>
</tr>
</tbody>
</table>
<p>Obviously, this test does not cover all browsers or operating systems, but does show you that there are real limits, that you should be aware of, if you&#8217;re relying heavily on a cookies. This test does not test javascript&#8217;s ability to access the cookies, since the browser receives the Set-Cookie headers, the cookies <strong>could </strong>still be accessible via javascript, or plugins/extensions on your browser. This test also does not look at a total cookie maximum, only per hostname restrictions.</p>
<h2>What does this mean for you?</h2>
<p>Hopefully nothing. Hopefully, your pages are not sending more than 50 cookies from a single host name, however, it can happen. For example, when using sessions in PHP, there will be a PHPSESSIONID cookie, when using Google Analytics, you get at least 4 cookies &#8216;utmz&#8217;, &#8216;utma&#8217;, &#8216;utmb&#8217;, and &#8216;utmc&#8217;, without any code you may have written, thats 10% of Firefox and IE available amount of cookies. Using CMS systems, blogs, or ecommerce systems will likely have their own cookies as well, but since the limitation is per hostname, keeping seperate system on seperate hostnames, like blog.mydomain.com or crm.mydomain.com, can help you avoid this problem. If you are sending more than 50 cookies, you may be getting unreliable results. You can use <a href="http://www.fiddler2.com/fiddler2/" target="_blank">Fiddler</a>, an HTTP debugging proxy to view the Set-Cookie headers being sent from your pages, as well as your Cookie headers your browser is sending to servers during your requests.</p>
]]></content:encoded>
			<wfw:commentRss>http://developers.redventures.com/2011/04/cookie-curiosity/feed/</wfw:commentRss>
		<slash:comments></slash:comments>
		</item>
		<item>
		<title>PHP Design Pattern</title>
		<link>http://developers.redventures.com/2011/03/php-design-pattern/</link>
		<comments>http://developers.redventures.com/2011/03/php-design-pattern/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 14:37:33 +0000</pubDate>
		<dc:creator>Mardochee</dc:creator>
				<category><![CDATA[Developers Only]]></category>

		<guid isPermaLink="false">http://developers.redventures.com/?p=159</guid>
		<description><![CDATA[Sorry, this is a private post meant only for Red Ventures Developers. If you are a developer, log in here: http://developers.redventures.com/wp-admin/]]></description>
			<content:encoded><![CDATA[Sorry, this is a private post meant only for Red Ventures Developers. If you are a developer, log in here: http://developers.redventures.com/wp-admin/]]></content:encoded>
			<wfw:commentRss>http://developers.redventures.com/2011/03/php-design-pattern/feed/</wfw:commentRss>
		<slash:comments></slash:comments>
		</item>
		<item>
		<title>On The Road To Changes: Separation of Concerns</title>
		<link>http://developers.redventures.com/2011/02/on-the-to-changes-separation-of-concerns/</link>
		<comments>http://developers.redventures.com/2011/02/on-the-to-changes-separation-of-concerns/#comments</comments>
		<pubDate>Mon, 21 Feb 2011 15:27:14 +0000</pubDate>
		<dc:creator>Mardochee</dc:creator>
				<category><![CDATA[Public]]></category>
		<category><![CDATA[mvc]]></category>

		<guid isPermaLink="false">http://developers.redventures.com/?p=143</guid>
		<description><![CDATA[The goal of this article is to promote and give an overview of Separation of Concerns.
So, when I first started to make websites, I would have one HTML page that had all the CSS and JS. Looked great, awesome!
Then ten years ago I started to learn PHP, I was in 10th/11th grade.  I started to [...]]]></description>
			<content:encoded><![CDATA[<p>The goal of this article is to promote and give an overview of Separation of Concerns.</p>
<p>So, when I first started to make websites, I would have one HTML page that had all the CSS and JS. Looked great, awesome!</p>
<p>Then ten years ago I started to learn PHP, I was in 10<sup>th</sup>/11<sup>th</sup> grade.  I started to create dynamic websites. A PHP file would have PHP, HTML, CSS, JS code in it.    Some of you is probably saying “ok what’s wrong with it?”  Well, when you dived in the codes, it was like an Olive Garden restaurant, pasta everywhere, <strong><em>spaghetti</em></strong> was the only dish served.  Now,  just say  I had five php files, wow, imagine when I had to make a change and I had to edit all of them.  Then I started to “include()” header and footer, but still, PHP,CSS,HTML, JS were everywhere.</p>
<p>One of the growing problem, as the site was getting bigger, I had to maintain each part. But sometimes, I didn’t even need to encounter with a CSS or JS line. But what if I wanted to change a JS section? ARRRRR!!!!! <strong><em> Mixing everything is just a bad design</em></strong>.  Maintaining and extending part of the codes became a burden.  As the application became bigger and bigger, more trouble was coming ahead. So to solve this issue, I had to rely on a concept called <strong>Separation of Concerns.</strong></p>
<p><strong>Separation of Concerns, </strong> a concept probably coined by <a href="http://en.wikipedia.org/wiki/Edsger_W._Dijkstra">Edsger W. Dijkstra</a> in his 1974 paper &#8220;<a href="http://www.cs.utexas.edu/users/EWD/transcriptions/EWD04xx/EWD447.html">On the role of scientific thought</a>”,<strong> </strong>is the process of separating a computer program into distinct features that overlap in functionality as little as possible.</p>
<p>Translating this into a web application, we now have, for a super basic one page site:<br />
- mysite. JS<br />
- mysite.CSS<br />
- mysite.PHP  (contain PHP &amp; HTML)</p>
<p>The main advantage of having such structure,  I can concentrate my attention at updating one piece of functionality at a time, instead of running through the HTML,CSS, JS all at once trying to see what’s going.</p>
<p>That was pretty easy, wasn’t it? Now, what about separating our PHP logic from our View?  We can now add a view file:<br />
- mysite. JS<br />
- mysite.CSS<br />
- mysite.PHP<br />
- mysite.HTML (View)</p>
<p>Now <em><strong>mysite.PHP</strong></em> has only  the PHP logic. It processes data to be sent to the view, while <em><strong>mysite.HTML</strong> (the view)</em> will only have my HTML.</p>
<p>Now what do we get here? We’ve just separated our application into maintainable “concerns”,  piece of interest.</p>
<p>If I have a JavaScript error, I would just edit <em><strong>mysite.JS</strong></em>. Oh lord, I just saw a PHP parse error, well I go straight to <em><strong>mysite.PHP</strong></em>. But I forgot to add the company’s  logo, well I’ll add the image tag in the <em><strong>mysite.HTML</strong></em>.</p>
<p>At its best, Separation of Concerns allow us to organize an application where each part fulfill a meaning and intuitive role while maximizing its ability to adapt to change. It allows us to maintain and debug our application with class. And extend any part of it without sacrificing the purpose of any.</p>
<p>What other benefits does the Separation of Concerns have?</p>
<p>It allows designers and developers to stay in their turf and not disturbe the flow of the other .</p>
<p>Imagine you’ve got some HTML page well laid out, all your elements well arranged, just for a php developer to come in and do this <em><strong>&lt;? IPutMyCodesInYourCodes(); ?&gt;</strong></em>.  Or do you want a designer to start messing with your PHP codes, just to add a new <em><strong>DIV</strong></em>?</p>
<p>Separation of Concerns separates your application into distinct features that overlap in functionality as little as possible.</p>
<p>I practice the “Separation of Concerns” in all of my applications. While there may be more files in my applications, I do have greater flexibility to update, maintain and extend my application.</p>
<p>So, <em>On the Road to Changes, “Separation of Concerns”</em> is going to lead us to  Model-View-Controller (MVC) concept. But until then, <em>C Ya!</em></p>
]]></content:encoded>
			<wfw:commentRss>http://developers.redventures.com/2011/02/on-the-to-changes-separation-of-concerns/feed/</wfw:commentRss>
		<slash:comments></slash:comments>
		</item>
		<item>
		<title>Awesome examples on how to unit test XML with PHPUnit</title>
		<link>http://developers.redventures.com/2011/02/awesome-examples-on-how-to-unit-test-xml-with-phpunit/</link>
		<comments>http://developers.redventures.com/2011/02/awesome-examples-on-how-to-unit-test-xml-with-phpunit/#comments</comments>
		<pubDate>Tue, 15 Feb 2011 22:03:22 +0000</pubDate>
		<dc:creator>James Huston</dc:creator>
				<category><![CDATA[Public]]></category>
		<category><![CDATA[phpunit]]></category>
		<category><![CDATA[unit testing]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://developers.redventures.com/2011/02/awesome-examples-on-how-to-unit-test-xml-with-phpunit/</guid>
		<description><![CDATA[Not only can this be used to test XML but it can also be used to test HTML output from things like render methods and such. Using cURL you could even use some of these techniques to automatically test output on remote sites. All kinds of fun stuff.
http://qafoo.com/blog/007_practical_phpunit_testing_xml_generation.html
]]></description>
			<content:encoded><![CDATA[<p>Not only can this be used to test XML but it can also be used to test HTML output from things like render methods and such. Using cURL you could even use some of these techniques to automatically test output on remote sites. All kinds of fun stuff.</p>
<p><a href="http://qafoo.com/blog/007_practical_phpunit_testing_xml_generation.html" target="_blank">http://qafoo.com/blog/007_practical_phpunit_testing_xml_generation.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://developers.redventures.com/2011/02/awesome-examples-on-how-to-unit-test-xml-with-phpunit/feed/</wfw:commentRss>
		<slash:comments></slash:comments>
		</item>
		<item>
		<title>jQuery 1.5 Changes Part I</title>
		<link>http://developers.redventures.com/2011/01/jquery-1-5-changes-part-i/</link>
		<comments>http://developers.redventures.com/2011/01/jquery-1-5-changes-part-i/#comments</comments>
		<pubDate>Thu, 20 Jan 2011 13:07:35 +0000</pubDate>
		<dc:creator>Garrett Johnson</dc:creator>
				<category><![CDATA[Public]]></category>

		<guid isPermaLink="false">http://developers.redventures.com/?p=132</guid>
		<description><![CDATA[jQuery&#8217;s Ajax module was completely rewritten for the up and coming 1.5 release by Julian Aubourg. It added a new signature, new options, pluggable dataTypes, and a completely new architecture for what is returned by Ajax calls. The new signature for $.ajax is now:

	$.ajax(url, options);

But it is completely backwards compatible, so no worries. I personally [...]]]></description>
			<content:encoded><![CDATA[<p>jQuery&#8217;s Ajax module was completely rewritten for the up and coming 1.5 release by <a href="http://jaubourg.net/">Julian Aubourg</a>. It added a new signature, new options, pluggable dataTypes, and a completely new architecture for what is returned by Ajax calls. The new signature for $.ajax is now:</p>
<pre class="brush: jscript; title: ;">
	$.ajax(url, options);
</pre>
<p>But it is completely backwards compatible, so no worries. I personally like the new signature as it aligns up nicer with $.get and $.post. I will come back to the other features such as new options, and custom dataTypes in the next post, for now were going to skip ahead to the new underlying architecture.  Prior to this release ajax calls in jQuery simply returned and passed around the raw XHR object, it was not all that handy in my opinion. However, starting at 1.5 an augmented XHR object has replaced it. You may see it referred to as the jXHR object or a promise.</p>
<p>So what does the promise allow us to do? Well to sum it up, we can bind callbacks to an object whose current task will eventually complete.</p>
<pre class="brush: jscript; title: ;">
	var jxhr = $.ajax('/foo.php', {type:'get', dataType:'json'});

	jxhr.success(function(response){
		// do something with the resposne
	});
	jxhr.error(function(jxhr){
		// do something with jxhr
	});

	console.log('whats up?');
</pre>
<p>Or you could accomplish something similar using the &#8220;then&#8221; binding which takes a done and fail callback.</p>
<pre class="brush: jscript; title: ;">
	$.getJSON('foo.php').then(function(response){
		console.log(response);
	}, function(jxhr){
		console.log(jxhr);
	});

	console.log('whats up?');
</pre>
<p>Or you can even chain the bindings and/or conditionally add new bindings which is a huge advantage of nesting tons callbacks in previous versions.</p>
<pre class="brush: jscript; title: ;">
	var jxhr = $.ajax('foo.php', {
			type: 'get',
			dataType: 'json',
			success: function (response) {
				console.log('1');
				jxhr.success(function(r){
					console.log('4');
				});
			}
	});

	jxhr.success(function(response){
		console.log('2');
	});

	jxhr.success(function(response){
		console.log('3');
		if (response[0] === 'one') {
			jxhr.complete(function(response){
				console.log('5');
			});
		}
	});

	console.log('whats up?');
</pre>
<p>So let&#8217;s say in the previous examples foo.php took 4 seconds to respond, it doesn&#8217;t matter, the ajax call will return a promise to us that will let us go ahead and bind a set of predefined events to it (success, done, complete, error and fail). It will later resolve based on what happened once the asynchronous task as completed and it will invoke the correct callbacks. As you can imagine there are a million ways to Sunday that you could formulate these calls. I personally like calling the success and error manually, at least in the case of Ajax. Check out https://github.com/jquery/jquery/blob/master/test/unit/Ajax.js for the various ways they are doing it. I would love to see what most people consider to be the &#8220;correct&#8221; way.</p>
<p>Another important thing to note is they have exposed the underlying deferred mechanics for your own use. So you can easily create promise like objects for your own asynchronous programming needs.</p>
<pre class="brush: jscript; title: ;">
	var def = new $.Deferred(), data = [1,2,3,4,5];

	setTimeout(function(){
		def.resolve(data);
	}, 5000);

	def.then(function(data){
		console.log(data);
	});

	console.log('whats up?');
</pre>
<p>So just like our ajax calls, we can bind a set of predefined callbacks to run once an asynchronous task has resolved. So check out $.Deferred and see what kind of asynchronous magic you can do. The whole concept of deferred/promises can puzzle many developers, including me. So check out the links below for more information, they were quite helpful in writing this post and correct me if you notice some incorrect information in this post.</p>
<ul>
<li><a href="http://blog.rebeccamurphey.com/deferreds-coming-to-jquery">http://blog.rebeccamurphey.com/deferreds-coming-to-jquery</a></li>
<li><a href="http://jaubourg.net/38261410">http://jaubourg.net/38261410</a></li>
<li><a href="http://oksoclap.com/6Y26bm1ZsB">http://oksoclap.com/6Y26bm1ZsB</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://developers.redventures.com/2011/01/jquery-1-5-changes-part-i/feed/</wfw:commentRss>
		<slash:comments></slash:comments>
		</item>
		<item>
		<title>Working with xpath with Firebug</title>
		<link>http://developers.redventures.com/2010/12/working-with-xpath-with-firebug/</link>
		<comments>http://developers.redventures.com/2010/12/working-with-xpath-with-firebug/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 15:32:42 +0000</pubDate>
		<dc:creator>James Huston</dc:creator>
				<category><![CDATA[Public]]></category>
		<category><![CDATA[firebug]]></category>
		<category><![CDATA[selenium]]></category>
		<category><![CDATA[xpath]]></category>

		<guid isPermaLink="false">http://developers.redventures.com/?p=107</guid>
		<description><![CDATA[Very few Firebug users know about this, so take note: Firebug adds a $x function that can be called from the console. It takes an XPath in the form of a String and will spit out the HTML elements that it evaluates to directly back in the console. You can then mouse over the elements and check that the XPath is working correctly:

 $x("//input[@class='cart-domain-pr-option'][1]");]]></description>
			<content:encoded><![CDATA[<p>from: http://blog.browsermob.com/2009/04/test-your-selenium-xpath-easily-with-firebug/</p>
<p>The author goes on to suggest Firebug as a great tool for doing this kind of work, which we tend to agree with and have covered previously. But they missed one of the most important functions: the ability to easily test XPath expressions from within Firebug!</p>
<p>Very few Firebug users know about this, so take note: Firebug adds a $x function that can be called from the console. It takes an XPath in the form of a String and will spit out the HTML elements that it evaluates to directly back in the console. You can then mouse over the elements and check that the XPath is working correctly:</p>
<p>$x(&#8220;//input[@class='cart-domain-pr-option'][1]&#8220;);</p>
<p>Also worth a read:</p>
<p>http://www.chinhdo.com/20080829/web-scraping-htmlxml-parsing-and-firebugs-copy-xpath-feature/</p>
]]></content:encoded>
			<wfw:commentRss>http://developers.redventures.com/2010/12/working-with-xpath-with-firebug/feed/</wfw:commentRss>
		<slash:comments></slash:comments>
		</item>
		<item>
		<title>Find the last monday before a date in MySQL</title>
		<link>http://developers.redventures.com/2010/11/find-the-last-monday-before-a-date-in-mysql/</link>
		<comments>http://developers.redventures.com/2010/11/find-the-last-monday-before-a-date-in-mysql/#comments</comments>
		<pubDate>Tue, 16 Nov 2010 21:14:59 +0000</pubDate>
		<dc:creator>James Huston</dc:creator>
				<category><![CDATA[Public]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://developers.redventures.com/2010/11/find-the-last-monday-before-a-date-in-mysql/</guid>
		<description><![CDATA[DATE_SUB(O.ScheduledDate, INTERVAL WEEKDAY(O.ScheduledDate) DAY) AS LastMonday
]]></description>
			<content:encoded><![CDATA[<p>DATE_SUB(O.ScheduledDate, INTERVAL WEEKDAY(O.ScheduledDate) DAY) AS LastMonday</p>
]]></content:encoded>
			<wfw:commentRss>http://developers.redventures.com/2010/11/find-the-last-monday-before-a-date-in-mysql/feed/</wfw:commentRss>
		<slash:comments></slash:comments>
		</item>
	</channel>
</rss>

