<?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>Learn Some Things</title>
	<atom:link href="http://www.learnsomethings.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learnsomethings.com</link>
	<description>Things I picked up along the way ...</description>
	<lastBuildDate>Sun, 05 May 2013 16:54:25 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Twitter bootstrap, fly out contact or feedback form with validation and Ajax submission</title>
		<link>http://www.learnsomethings.com/2013/05/05/twitter-bootstrap-fly-out-contact-or-feedback-form-with-validation-and-ajax-submission/</link>
		<comments>http://www.learnsomethings.com/2013/05/05/twitter-bootstrap-fly-out-contact-or-feedback-form-with-validation-and-ajax-submission/#comments</comments>
		<pubDate>Sun, 05 May 2013 16:49:07 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[HTML 5]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[Just Javascript]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2758</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
Ok, I have taken a look at several of the contact or feedback forms on the internet in the past few weeks and they all work great, however, they require varying numbers of includes, and in some cases images, or &#8230; <a href="http://www.learnsomethings.com/2013/05/05/twitter-bootstrap-fly-out-contact-or-feedback-form-with-validation-and-ajax-submission/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>Ok, I have taken a look at several of the contact or feedback forms on the internet in the past few weeks and they all work great, however, they require varying numbers of includes, and in some cases images, or even completely different versions of JQuery to get them up and running. The solutions that take advantage of HTML and the latest version of bootstrap.js are practically non-existent.  So I thought why not roll my own then pass it on, after all it comes in at six lines of JavaScript code for the toggle (I added a form validation and ajax submit for those that need help there) , some CSS, and a good old fashioned HTML form tag. At the very least will introduce you to a few JavaScript features that you may not have been used to seeing.</p>
<p><strong>Ingredients</strong></p>
<p>Twitter bootstap -&gt; <a href="http://twitter.github.io/bootstrap/index.html">http://twitter.github.io/bootstrap/index.html</a></p>
<p>Let’s start with the end first (here&#8217;s what you are getting yourself into):</p>
<p style="text-align: center;"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/05/Screen-Shot-2013-05-05-at-12.16.11-PM.png"><img class="size-medium wp-image-2759 aligncenter" alt="Screen Shot 2013-05-05 at 12.16.11 PM" src="http://www.learnsomethings.com/wp-content/uploads/2013/05/Screen-Shot-2013-05-05-at-12.16.11-PM-300x277.png" width="300" height="277" /></a></p>
<p>I am posting the code to github as well as including it in this post, so feel free to pull it down from there and *hint* *hint* fork it and improve the validation methods if can ….  as it will probably come down in a cleaner format than cut and paste would have given you.</p>
<p><a href="https://github.com/jmcdonald69124/jQuery-Bootstrap-Feedback-Sliding-Form" target="_blank">https://github.com/jmcdonald69124/jQuery-Bootstrap-Feedback-Sliding-Form</a></p>
<pre class="brush: css; title: ; notranslate">
.rotate {
/* Safari, Chrome */
-webkit-transform: rotate(-90deg);
/* Firefox */
-moz-transform: rotate(-90deg);
/* IE */
-ms-transform: rotate(-90deg);
/* Opera */
-o-transform: rotate(-90deg);
/* Older versions of IE */
	filter: progid:DXImageTransform.Microsoft.BasicImage(rotation=3);
/* CSS3 standard as defined here: http://www.w3.org/TR/css3-transforms/ */
	transform: rotate(-90deg);
}
		
.required {
	background-color:#F2DEDE !important;
	border: 1px #F00 solid !important;
}
		
.feedback {
	position	: fixed; /* This will never scroll out of view */
	background-color: #2F96B4;
	border		: 5px solid #333;
	color		: #FFF;
	font-weight	: bold;
	font-size	: 16px;
	padding	: 15px;
}
		
.feedback-form-wrapper {
/*
This is the CSS for the feedback div that is fixed to the top left hand side
of the screen. 
*/
display		: block;
	z-index		: 9999; /* Make sure it floats a little higher than the feedback form div below */
	top		: 100px;	
	left		: -395px; /* Bring the div in and hide the left (top) border */
	width		: 350px;
}
		
/* This will put some distance between the input box and the next label */
.feedback input{
	margin-bottom:5px;	
}
		
.feedback legend{
	color		: #FFF;	
}
		
.feedback-toggle {
/*
This is the CSS for the feedback div that is fixed to the top left hand side
of the screen. This div should slide with the form so that it provides a 
close button when the form is slid into view.
*/
left		: -49px; /* Bring the div in and hide the left (top) border */
	left		: -10px\9; /* Less Than IE9 Hack - Bring the div in and hide the left (top) border */
	top			: 200px;
	cursor		: pointer;
	padding-left: -75px;
	width		: 90px; /* Since this is getting rotated width appears as height to the eye*/
	height		: 15px; /* Since this is getting rotated height appears as width to the eye*/
	text-align	: center;
	border-top	: 5px solid #2F96B4;
	border-left	: 4px solid #333;
	border-right: 4px solid #333;
	z-index		: 10000; /* Make sure it floats above the content */
}
</pre>
<p>Of course, before I explain it would be nice to see the HTML that this code is modifying.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;!-- 
	This is the feedback form that gets toggles in and out of view
	based on the user clicking the 'feedback_toggle' div.
--&gt;
&lt;!-- **************************************************************  --&gt; 

&lt;div class=&quot;feedback feedback-toggle rotate&quot; &gt;Feedback&lt;/div&gt;
&lt;div class=&quot;feedback feedback-form-wrapper&quot;&gt;
&lt;form id=&quot;feedback-form&quot; class=&quot;form-horizontal&quot;&gt;
      &lt;legend&gt;Please give us feedback .. &lt;/legend&gt;
          	&lt;div class=&quot;alert alert-error&quot; 	style=&quot;display:none&quot;&gt;
	&lt;h4&gt;Uh-Oh&lt;/h4&gt; 
                    Looks like some of the required fields are not complete!
	&lt;/div&gt;
                &lt;div class=&quot;alert alert-success&quot; 	style=&quot;display:none&quot;&gt;
	&lt;h4&gt;Thanks!&lt;/h4&gt; 
                    Your feedback has been submitted, we'll get back to you as soon as we can!
	&lt;/div&gt;
                &lt;div class=&quot;alert alert-block&quot; 	style=&quot;display:none&quot;&gt;
                  &lt;h4&gt;Warning!&lt;/h4&gt;
                  Something happened and the form did not get submitted...
                &lt;/div&gt;
            	&lt;label&gt;Name&lt;/label&gt;
                    &lt;input type=&quot;text&quot; id=&quot;username&quot;  	data-validation='{&quot;required&quot;:true,&quot;type&quot;:&quot;text&quot;}' 	name=&quot;username&quot; class=&quot;input-block-level&quot;   &gt;
                &lt;label&gt;Email&lt;/label&gt;
                    &lt;input type=&quot;email&quot; 	name=&quot;email&quot;  	data-validation='{&quot;required&quot;:true,&quot;type&quot;:&quot;email&quot;}'  class=&quot;input-block-level&quot;  &gt;
                &lt;label&gt;Message&lt;/label&gt;
                    &lt;textarea id=&quot;comment&quot; 	name=&quot;comment&quot;  data-validation='{&quot;required&quot;:true,&quot;type&quot;:&quot;text&quot;}' 	class=&quot;input-block-level&quot; style=&quot;margin-bottom:10px;&quot;  rows=&quot;4&quot; cols=&quot;30&quot;&gt;&lt;/textarea&gt;
                &lt;button class=&quot;btn btn-inverse btn-large pull-right&quot;  float=&quot;right&quot;&gt;Send&lt;/button&gt;
 &lt;/form&gt;
&lt;/div&gt;
&lt;!-- **************************************************************  --&gt;
</pre>
<p>And finally, the JavaScript that is needed to make all of this work:</p>
<pre class="brush: jscript; title: ; notranslate">
// This is the Feedback toggle functionality it slides the feedback form in and out
// of view when the user clicks the div with the class .feedback-toggle
$('.feedback-toggle').click( function(){
	var 	left = parseFloat($('.feedback')[0].style.left.match(/[0-9]+/g)) || 49,
		tgl	 = '+=390';
	      	(left &gt; 49)  ? tgl = '-=390' : tgl = '+=390';
		$('.feedback').animate({ left: tgl}, 500);
});
		
/*
This is the custom validation for the feedback form 
	I have left the types open in the switch statement feel free 
	to add.
*/
validate = function(form,element){
    var isValid = false, // Assume that everything starts off invalid
          fields  = $(form).find('[data-validation]'), //&lt;-- Should return all input elements in that specific form.
         data,
         validationProps;
       $.each(fields, function(index, value){
	validationProps 	= $(value).data('validation');
  
	if(validationProps.required){
	      ($(value).val().length &gt; 0 )? $(value).removeClass(&quot;required&quot;) : $(value).addClass(&quot;required&quot;);	
	}
					  
	if(!typeof validationProps.minlength === 'undefined' &amp;&amp; parseFloat(validationProps.minlength) &gt; 0){
	      ($(value).val().length &gt; parseFloat(validationProps.minlength))? $(value).removeClass(&quot;required&quot;) : $(value).addClass(&quot;required&quot;);
  }
					  
 switch(validationProps.type)
{
	case &quot;email&quot;:
		var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/;  
		//console.log(validationProps.type);
		//console.log($(value).val().match(re));
		 ($(value).val().match(re))? $(value).removeClass(&quot;required&quot;) : $(value).addClass(&quot;required&quot;);	
	break;
	case &quot;phone&quot;:
		// add code here 
	 break;
	case &quot;numeric&quot;:
		// add code here 
	break;
	default:
	}
});
	isValid = ($(form).children().is('.required'))? false : true;	
	 (isValid)? $(form).find('.alert-error').fadeOut('fast') : $(form).find('.alert-error').fadeIn('fast') ;
	return isValid;
}
		
// This handles the on focus and on focus lost validation
$('input,textarea').on('blur', function(){
  	validate($(this).parent('form'),$(this).attr('id'));
}).on('focus', function(){
  	$(this).removeClass(&quot;required&quot;);
});
		
// This is the form submission AJAX code which also
// hides the feednack form.
		
$(&quot;#feedback-form .btn&quot;).click(function() {
	var url  	= &quot;path/to/your/script.php&quot;, // the script where you handle the form input.
	data 	= $(&quot;#feedback-form&quot;).serialize(),
	isValid   = validate(&quot;#feedback-form&quot;);
	if(isValid){
		$.ajax({
			type	: &quot;POST&quot;,
			url	: url,
			data	: data , // serializes the form's elements.
			success	: function(data){
				$('.feedback').find('.alert-error').fadeIn('fast');
				$('.feedback').animate({ left: '-=390'}, 500);
			},
			error	: function(data){
				$('.feedback').find('.alert-block').fadeIn('fast');
				return false;  
			}
		});
	}
	return false; // avoid to execute the actual submit of the form.
});
</pre>
<p>Ok, now for the explanation, rotate is pretty simple, as it just rotates the div that will serve as the ‘tab’ for the feedback page. It’s important to wrap your head around this concept, once the div is rotated the left hand side of the div is the bottom, the right the top, and the top the left, you get the idea, so if you want to make changes to the height, as you see it, you are making changes to the width.</p>
<p><strong> The CSS</strong></p>
<p>The feedback class contains the background color, font color and size, and border color / size for both the tab and the main form. The feedback form wrapper class contains the code that will be applied to a div that surrounds the actual web form, this CSS will bring the feedback form above the actual page by setting the z-index to 9999, and will position the form outside of the viewable area of the page by setting the value of left to be at -395. Notice the width is 350 pixels. To give the effect of having the tab the toggle area is raised above the form wrapper with a z-index of 10000, and is given a left that positions the top of the div (remember it’s been rotated) right off of the left hand side of the screen. There is a hack here to deal with IE versions less than 9. Ok, so now our CSS is set up and everything should be positioned right when we start to place out HTML code into the page.</p>
<p><strong> The HTML</strong></p>
<p>Ok, the form tag uses the bootstrap CSS class form-horizontal and has the ID feed-back form, the ID will be instrumental in the operation of this widget later on when we get into the JavaScript part of the tutorial. Under the legend tag are three DIVs that contain three different messages which we will use to indicate a successful AJAX submission, an unsuccessful AJAX submission, and finally, a problem with the required input AKA a validation error. Moving on to the input and text area elements, you will notice that they all have the class input-block-level, which also comes from the bootstrap CSS and just makes the element scale to the width of the container, and gives it that cool rounded look.</p>
<p>One thing that may strike you is the use of the HTML5 data attribute, and the fact that is some JSON in the value, this will be used to tell the JavaScript what type of validation should be done on each of these elements. I will explain this in the JavaScript explanation section. The button has several classes applied to it, and all of them come from the bootstrap CSS. Again, it looks cool, that’s why you decided to use it, right! Anyway, this is how you get that great button in no time flat.</p>
<p><strong> The JavaScript</strong></p>
<p>Ok, now for the JavaScript, which will come in and do all of the heavy lifting. First, we need to be able to slide the form into the page and back out again. The trick here is that the tab needs to be attached and needs to slide in at exactly the same time as the main form. This takes only six lines of code.</p>
<pre class="brush: jscript; title: ; notranslate">&lt;br /&gt;
$('.feedback-toggle').click( function(){&lt;br /&gt;
	var left = parseFloat($('.feedback')[0].style.left.match(/[0-9]+/g)) || 49,&lt;br /&gt;
		tgl	 = '+=390';&lt;br /&gt;
		 (left &amp;gt; 49)  ? tgl = '-=390' : tgl = '+=390';&lt;br /&gt;
		$('.feedback').animate({ left: tgl}, 500);&lt;br /&gt;
});&lt;br /&gt;
</pre>
<p>Ok, so line one we attach the function to the feedback-toggle div, nothing fancy, remember that we have the class feedback which controlled the font and background properties. Breaking these common elements out into a separate class was great in itself, but now we are going to use it to sort of tie the form to the tag by making the slide out / in code act on the feedback class. The second line gets the current value for the left hand position of the feedback DIV, the variable tgl is set by default to +=390 which will be the amount that we want to increase the CSS value of left for that DIV. The line after that contains a ternary operator which tests for left greater than 49, if that is true set tgl to -+390 otherwise, well, you know. Finally, the line <code> $('.feedback').animate({ left: tgl}, 500);</code> is what actually does the sliding.</p>
<p>Moving on we come to the custom validation part of the form, I needed to do this, because , once again, there seemed to be no good validation plugin that worked with the latest version of jQuery which is bundled with bootstrap. I plan to reuse it so it just takes the form id as a parameter, the form element is something I want to expand on in a later post. Notice the lines below:</p>
<pre class="brush: jscript; title: ; notranslate">&lt;br /&gt;
// This handles the on focus and on focus lost validation&lt;br /&gt;
    $('input,textarea').on('blur', function(){&lt;br /&gt;
        validate($(this).parent('form'),$(this).attr('id'));&lt;br /&gt;
    }).on('focus', function(){&lt;br /&gt;
                $(this).removeClass(&quot;required&quot;);&lt;br /&gt;
            });&lt;br /&gt;
</pre>
<p>This code attaches the validate event to all of the textareas and input elements on the page. You could easily change it to be form specific by placing a dom selector before the first section of code. Basically, this calls the validate event on focus and on lose focus of each of those elements. The form id is being passed to the function as well as the attribute id.</p>
<p>Once the code hits the validate function, it checks to see if there is a value in the data attribute data-validation. The code is set up to take a JSON string that contains the basic validation settings, so far, these are:</p>
<p>required -&gt; true or false</p>
<p>minlegth -&gt; number only</p>
<p>type -&gt; email, phone, or numeric, of which only email has been coded as of yet.</p>
<p>Tests are made against the values in the input elements based on the settings above, and a simple true or false boolean is returned.</p>
<p>Finally, the code to submit the form data is fairly straightforward, first, check to see if the form is valid before submitting, then post the values to some server side script, and display the appropriate message to the user depending on what happened with the validation and submission. If all goes well hide the form by sliding it back out.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2013/05/05/twitter-bootstrap-fly-out-contact-or-feedback-form-with-validation-and-ajax-submission/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter Bootstrap &amp; JQuery Pagination – The missing JavaScript Example</title>
		<link>http://www.learnsomethings.com/2013/04/25/twitter-bootstrap-jquery-pagination-the-missing-javascript-example/</link>
		<comments>http://www.learnsomethings.com/2013/04/25/twitter-bootstrap-jquery-pagination-the-missing-javascript-example/#comments</comments>
		<pubDate>Thu, 25 Apr 2013 23:47:09 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[JQuery]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[user interface design]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2752</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
Ok, so you can find the pagination tutorial in the bootstrap documentation, and it looks great, works great, but there is one thing that is missing, the JavaScript that actually links the pagination widget to the pages that you create &#8230; <a href="http://www.learnsomethings.com/2013/04/25/twitter-bootstrap-jquery-pagination-the-missing-javascript-example/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>Ok, so you can find the pagination tutorial in the bootstrap documentation, and it looks great, works great, but there is one thing that is missing, the JavaScript that actually links the pagination widget to the pages that you create in your application. This article will explain in detail how you can connect the pagination widget to a series of div’s that contain well, whatever you want them to.</p>
<p>First, you should go to the Bootstrap page http://twitter.github.io/bootstrap/components.html#pagination and take a look at the pagination example. The code from the page above is below.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div class=&quot;pagination&quot;&gt;
&lt;ul&gt;
&lt;li class=&quot;disabled&quot;&gt;&lt;a href=&quot;#&quot;&gt;&amp;laquo;&lt;/a&gt;&lt;/li&gt;
&lt;li class=&quot;active&quot;&gt;&lt;a href=&quot;#&quot;&gt;1&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
</pre>
<p>That’s all there is to building the widget that provides the pagination bar on your page, and admit it looks pretty cool out of the box, but this is just the UI, there is nothing on the page to show you how to use it. Now that you have taken a look let’s set up a real world working set of div’s and the corresponding li options.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;div class=&quot;pagination-container&quot; &gt;

   &lt;div data-page=&quot;1&quot; &gt;
    	Content for Div Number 1
   &lt;/div&gt;
   &lt;div data-page=&quot;2&quot; style=&quot;display:none;&quot;&gt;
    	Content for Div Number 2
   &lt;/div&gt;
   &lt;div data-page=&quot;3&quot; style=&quot;display:none;&quot;&gt;
    	Content for Div Number 3
   &lt;/div&gt;
   &lt;div data-page=&quot;4&quot; style=&quot;display:none;&quot;&gt;
    	Content for Div Number 4
   &lt;/div&gt;
   &lt;div data-page=&quot;5&quot; style=&quot;display:none;&quot;&gt;
    	Content for Div Number 5
   &lt;/div&gt;

   &lt;div class=&quot;pagination pagination-centered pagination-large&quot; style=&quot;position:absolute; bottom:0;&quot;&gt;
       &lt;ul class=&quot;page_control &quot;&gt;
            &lt;li data-page=&quot;-&quot; &gt;&lt;a href=&quot;#&quot; &gt;&amp;lt;&lt;/a&gt;&lt;/li&gt;
            &lt;li class=&quot;active&quot; data-page=&quot;1&quot;&gt;
                &lt;a href=&quot;#&quot; &gt;1&lt;/a&gt;
            &lt;/li&gt;
            &lt;li data-page=&quot;2&quot;&gt;&lt;a href=&quot;#&quot; &gt;2&lt;/a&gt;&lt;/li&gt;
            &lt;li data-page=&quot;3&quot;&gt;&lt;a href=&quot;#&quot; &gt;3&lt;/a&gt;&lt;/li&gt;
            &lt;li data-page=&quot;4&quot;&gt;&lt;a href=&quot;#&quot; &gt;4&lt;/a&gt;&lt;/li&gt;
            &lt;li data-page=&quot;5&quot;&gt;&lt;a href=&quot;#&quot; &gt;5&lt;/a&gt;&lt;/li&gt;
            &lt;li data-page=&quot;+&quot;&gt;&lt;a href=&quot;#&quot; &gt;&amp;gt;&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
   &lt;/div&gt;

&lt;/div&gt;
</pre>
<p>Now, let me explain what has been added to the example code from the Bootstrap page. To start things off I wrapped the content div’s as well as the pagination widget in a div named pagination-container, this step is crucial as the JQuery JavaScript will later use this as a way to find the child div tags. Next, notice the inclusion of the div’s that will contain the content you would like to switch out. Inside these tags you will have noticed that there is an attribute named data-page and each div has a numerical value starting at 1. The data attribute is a new to HTML5 and allows you to store name, value pairs inside of any HTML tag. This tag is intended to be a custom data element that should store private data for which there are no more appropriate attributes or elements. You can read more about the data attribute at <a href="http://www.w3.org/html/wg/drafts/html/master/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes" target="_blank">w3.org</a>. JQuery happens to have a nice set of built in methods that allow you to access and use the values that can be found in the data attribute. For an in depth look at Jquery.data() take a look at the following resource (<a href="http://api.jquery.com/jQuery.data/" target="_blank">http://api.jquery.com/jQuery.data/</a>). After looking at the content holders , you may have noticed the inclusion of the inline style attribute on the container that holds the bootstrap.</p>
<pre class="brush: css; title: ; notranslate">
style=&quot;position:absolute; bottom:0;&quot;
</pre>
<p>The CSS above just positions the paginator to the bottom of the pagination-container div. This is pretty important as you want to give the appearance that the paginator is static, and it would jump when the height of the content tags change otherwise.</p>
<div>
<p>The changes in the li tags that make up the bootstrap paginator’s ‘buttons’ include the addition of the data attributes. After careful inspection, you notice that the data element values and name matches with the data elements that can be found on in the top level div tags.</p>
<p>Now let’s take a look at the script that runs the paginator. We’ll add a function in the script tags named paginationHandler, the code for the function can be found below.</p>
<pre class="brush: jscript; title: ; notranslate">
var paginationHandler = function(){
	$('.page_control li').unbind('click', paginationHandler);
	var currentPage		= $(this).data('page'),
	       activePage		= $(this).parent().find('.active').data('page'),
	       num_elements 	= $(this).parent().children().length,
// This equals the first data-page value after the &lt; button.
	       start		= 1,
 // This is the end of the actual pages, remember it is offset by the &lt; and &gt; buttons.
	      end			= num_elements – 2;
	if(currentPage === '+' ){
	    (activePage &lt; end) ? currentPage = activePage + 1 : currentPage = start;
	}

	if(currentPage === '-'){
	    (activePage &gt; start) ? currentPage = activePage - 1 : currentPage = end;
	}
// Remove the active class to the li
	$(this).parent().find('.active').removeClass('active');

// Add the active class to the appropriate li taking
        	$(this).parent().find('li[data-page*=' + currentPage + ']').addClass('active');

// Add a fade out / in effect to the div holding the
// actual data. You must have a div with the data-page
// attribute for every li tag that contains the same
// data attribute or you will get unreliable
// results.

$(this).parents(&quot;div .pagination-container&quot;).find('div[data-page*=' + activePage + ']').fadeOut('fast', function(){
       $(this).parents(&quot;div .pagination-container&quot;).find('div[data-page*=' + currentPage + ']').fadeIn('fast');
	$('.page_control li').bind('click', paginationHandler);
	});
}
</pre>
<p>Next, we have to bind the function to the li tags that reside in the div with the class .page_control. The code to do so is below.</p>
<pre class="brush: jscript; title: ; notranslate">
$('.page_control li').bind('click', paginationHandler );
</pre>
<p>Now let me explain. The first line in our function unbinds the event from the li tag. This is done because if the user decides to click repeatedly on say the ‘next’ button before the fade in animation has completed then all hell will break loose and you may have several div tags displayed at one.<br />
$(this).data(&#8216;page&#8217;) actually gets the value in the data attribute and stores it in the current page variable. The next line goes up to the parent tag of the li that was clicked, which is of course, the ul tag and finds the element that contains the active class, and gets the value in the data element of that li tag. This gives you the active page number. The next line gets the total length of the pagination elements, so say if you wanted to make this example work for ten elements instead of five just add the li tags and div tags, no need to modify the JavaScript. Start is always going to be one and remember we have two elements that are not actually pages, they are the next and previous buttons, so deduct two from the total number of elements to get the ending page.</p>
<p>The two if statements handle the user pressing the next and the previous button. One feature I added was the ability to go back to start so to speak if you page past the last element, you may need to modify the code here to 1) add more elements, or 2) just stop at the end, it’s your call.</p>
<p>The line below removes the active class from the pagination widget, and the second line adds the active class to the new current page of the widget.</p>
<pre class="brush: jscript; title: ; notranslate">
// Remove the active class to the li
$(this).parent('ul').children('.active:first').removeClass('active');

// Add the active class to the appropriate li taking
$(this).parent().find('li[data-page*=' + currentPage + ']').addClass('active');
</pre>
<p>This next piece fades out the current content div and then fades in the new content div, and last but not least, we rebind the function to the li elements so that the user can once again click the li tags and change the content.</p>
<pre class="brush: jscript; title: ; notranslate">
// Add a fade out / in effect to the div holding the
// actual data. You must have a div with the data-page
// attribute for every li tag that contains the same
// data attribute or you will get unreliable
// results.

$(this).parents(&quot;div .pagination-container&quot;).find('div[data-page*=' + activePage + ']').fadeOut('fast', function(){
$(this).parents(&quot;div .pagination-container&quot;).find('div[data-page*=' + currentPage + ']').fadeIn('fast');
$('.page_control li').bind('click', paginationHandler );
});
</pre>
<p>You will need:<br />
<a href="http://twitter.github.io/bootstrap/index.html" target="_blank">http://twitter.github.io/bootstrap/index.html</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2013/04/25/twitter-bootstrap-jquery-pagination-the-missing-javascript-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Importing Flat File data into SQL Server with SSIS</title>
		<link>http://www.learnsomethings.com/2013/02/24/importing-flat-file-data-into-sql-server-with-ssis/</link>
		<comments>http://www.learnsomethings.com/2013/02/24/importing-flat-file-data-into-sql-server-with-ssis/#comments</comments>
		<pubDate>Sun, 24 Feb 2013 13:42:58 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[Database Stuff]]></category>
		<category><![CDATA[data]]></category>
		<category><![CDATA[sql server 2008]]></category>
		<category><![CDATA[sql stuff]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2663</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
Ok, so one of the problems that we come across in the development field is the fact that data is not always consumable in formats that we would wish to get, it may come in tab delimited, pipe delimited, in &#8230; <a href="http://www.learnsomethings.com/2013/02/24/importing-flat-file-data-into-sql-server-with-ssis/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>Ok, so one of the problems that we come across in the development field is the fact that data is not always consumable in formats that we would wish to get, it may come in tab delimited, pipe delimited, in CSV files, whatever &#8211; the main thing here is we need to automate a process that imports the data into your database that has as few moving parts as possible (so when not if you have to dig back in the code you are not left wondering how the hell you built the thing in the first place.)</p>
<p>Turns out it is very doable but a long drawn out process in SQL Server to build a .dtsx package that accomplishes the entire task! I have detailed the steps below as I just know that this will come back and be of use later.</p>
<p><strong> Creating a Job in SQL Server to Import Flat Files</strong></p>
<p><strong>What You Need:</strong></p>
<p>Microsoft SQL Server Management Studio</p>
<p>MSFT SQL server</p>
<p><strong>Overview:</strong></p>
<p>When data comes in from outside sources in flat files that are delimited you need a way to open the files, import the data into the database, and archive the files just in case you have a need to rerun the job, or to take a look at the raw data files in the future. The script will archive the files that have already been processed in folders bearing the month and the year that corresponds with the date the job ran that kicks off the .dtsx package.</p>
<p><strong>Tables:</strong></p>
<ul>
<li>processed_files – This table will hold the files that have been processed so that 1) you have a record of what has been done, and 2) if the job fails you at least know where it failed.</li>
<li>data_table – This is the table that you are importing data into and will change depending on the files that you are importing.</li>
</ul>
<p><strong>Steps:</strong></p>
<ul>
<li>Set up Variables</li>
<li>Set up data connections</li>
<li>Displaying and using the toolbox</li>
<li>Add Foreach Loop Container</li>
<li>Add Execute SQL Task (Check Processed)</li>
<li>Add data Flow Task
<ul>
<li>Add Flat File Source</li>
<li>Add Multicast</li>
<li>Add OLE DB Destination</li>
<li>Add Row Count</li>
<li>Insert Constraint between Check processed and the Import file Data Flow Task</li>
</ul>
</li>
<li>Add Execute SQL Task (Register Processing)</li>
<li>Add Script Task</li>
<li>Add File System Task (Move Files)</li>
<li>Add Execute SQL Task (Update processed table)</li>
</ul>
<p><strong>Create processed files table:</strong></p>
<pre class="brush: sql; title: ; notranslate">
CREATE TABLE [dbo].[file_control]

(

[ImportedFilename] [varchar](100)   NOT NULL,

[RecordsImported]  [int]            NOT NULL,

[ProcessDate]      [datetime]       NOT NULL

)
</pre>
<p><strong>Set up Variables</strong>:</p>
<p>To display the variables window in Microsoft SQL Server Management Studio hover over the ‘View’ menu item then scroll down to the ‘Other Windows’ option, the resulting fly-out menu should display the variables display option.</p>
<p align="center"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image001.png"><img class="size-full wp-image-2670 aligncenter" alt="image001" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image001.png" width="454" height="410" /></a></p>
<p align="center">Figure 1 &#8211; View Menu Bar</p>
<p>The table below lists all of the variables needed to set up the file import solution on the server. These variables will be manipulated later by scripts as well as used as output and input parameters in several of the steps we are about to perform.</p>
<table border="1" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td valign="top" width="100">
<p align="center">Name</p>
</td>
<td valign="top" width="99">
<p align="center">Scope</p>
</td>
<td valign="top" width="63">
<p align="center">Data Type</p>
</td>
<td valign="top" width="133">
<p align="center">Value</p>
</td>
<td valign="top" width="84">
<p align="center">Example</p>
</td>
</tr>
<tr>
<td valign="top" width="100">Destination Folder</td>
<td valign="top" width="99">DTS Package Level</td>
<td valign="top" width="63">String</td>
<td valign="top" width="133">Archive folder. However, you will need to insert the fully qualified name to the source folder or you will get the error that is visible in Figure 2 &#8211; FilePath error is variable is left empty.</td>
<td valign="top" width="84">Fully qualified path. End with a forward slash (\). If you are developing this on a network do not use mapped drive letters use the \\ format.</td>
</tr>
<tr>
<td valign="top" width="100">Destination Root</td>
<td valign="top" width="99">DTS Package Level</td>
<td valign="top" width="63">String</td>
<td valign="top" width="133">Path to the root of the archive folder.</td>
<td valign="top" width="84">Fully qualified path. End with a forward slash (\). If you are developing this on a network do not use mapped drive letters use the \\ format.</td>
</tr>
<tr>
<td valign="top" width="100">FilePath</td>
<td valign="top" width="99">DTS Package Level</td>
<td valign="top" width="63">String</td>
<td valign="top" width="133">The path and name of the current file in the Foreach loop container. You will need to insert the fully qualified name to the source folder or you will get the error that is visible in Figure 2 &#8211; FilePath error is variable is left empty.</td>
<td valign="top" width="84">Fully qualified path. End with a forward slash (\). If you are developing this on a network do not use mapped drive letters use the \\ format.</td>
</tr>
<tr>
<td valign="top" width="100">FilePattern</td>
<td valign="top" width="99">DTS Package Level</td>
<td valign="top" width="63">String</td>
<td valign="top" width="133">The extension or name that you want to use as a filter when determining which files the Foreach loop container will process.</td>
<td valign="top" width="84">*.txt, or SALES*.txt</td>
</tr>
<tr>
<td valign="top" width="100">MonthNameFormat</td>
<td valign="top" width="99">DTS Package Level</td>
<td valign="top" width="63">String</td>
<td valign="top" width="133">The Visual basic or C# format specifier for the month part of the date. More information can be found in the script section of this document.</td>
<td valign="top" width="84">MMMM or MMM</td>
</tr>
<tr>
<td valign="top" width="100">Processed</td>
<td valign="top" width="99">DTS Package Level</td>
<td valign="top" width="63">Int32</td>
<td valign="top" width="133">Will hold a flag that will be set to true if the file has already been processed.</td>
<td valign="top" width="84">0</td>
</tr>
<tr>
<td valign="top" width="100">Records</td>
<td valign="top" width="99">DTS Package Level</td>
<td valign="top" width="63">Int32</td>
<td valign="top" width="133">Will hold the record count, or the number of rows that are present on the file.</td>
<td valign="top" width="84">0</td>
</tr>
<tr>
<td valign="top" width="100">SourceFolder</td>
<td valign="top" width="99">DTS Package Level</td>
<td valign="top" width="63">String</td>
<td valign="top" width="133">The source folder where the files that you will be processing reside. will be</td>
<td valign="top" width="84">Fully qualified path. End with a forward slash (\). If you are developing this on a network do not use mapped drive letters use the \\ format.</td>
</tr>
</tbody>
</table>
<p align="center"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image004.gif"><img class="size-full wp-image-2701 aligncenter" alt="image004" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image004.gif" width="304" height="304" /></a></p>
<p align="center">Figure 2 &#8211; FilePath error is variable is left empty</p>
<p><strong>A word about scope:</strong></p>
<p><strong>                 </strong> Scope is very important in the processing of the files, you may be tempted to go with the thought that a variable.</p>
<p><strong>Set up data connections</strong></p>
<p style="text-align: center;"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image006.gif"><img class="size-full wp-image-2703" alt="image006" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image006.gif" width="301" height="211" /></a></p>
<p align="center">Figure 3 &#8211; Connection Managers tab with context menu.</p>
<p><strong>                 </strong> This .dtsx package will need three connections to add a data connection you will need to right click on the blank area in the ‘Connection Managers’ tab. You will need three connections:</p>
<ul>
<li><strong></strong>New Flat File Connection<strong></strong></li>
<li><strong></strong>New File Connection<strong></strong></li>
<li><strong></strong>New OLE DB Connection<strong></strong></li>
</ul>
<p><strong>New Flat File Connection</strong></p>
<p>The connection to the file is where you will have to set up the column mappings in order to get the data from the file to the table in the database. In this example give the connection the name ‘TextFile_Connection’, the rows are separated by a carriage return {CR}{LF}, the format is delimited, and there is one header row that we have to skip before we get to the actual data. See Figure 4 &#8211; Flat File Connection General Tab for a view of these settings.</p>
<p>The ‘Columns’ tab is a bit counterintuitive as it is not where we define the actual columns, it is where we set the column delimiter and the row delimiter for the rows that follow the header. In this instance we are dealing with a tab delimited file and each record is separated from the next by a carriage return. See Figure 5 &#8211; Flat File Connection Columns Tab for a view of these settings. You may be tempted to skip the next step, especially if the preview pane shows actual data from your input file; if you do you will miss one of the most important steps. Conversely, if you do not see any data in the preview grid after you navigate to the file you want to import then don’t worry, this is actually pretty common, you can add the columns manually in the next tab.<strong> </strong></p>
<p>The ‘Advanced’ tab, allows you to change the name of the columns as well as change the data type of the columns. If you are dealing with a data file that does not include column headers, or for some other reason you are unable to get the flat file wizard to recognize the  file you have selected you can press the ‘new’ button on the bottom of the screen to add columns to the connection manager. Make sure you rename these columns and match the data type and length to the destination database table. The Advanced tab is displayed in Figure 7 &#8211; Flat File Connection Advanced Tab.</p>
<p style="text-align: center;"><strong> <a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image008.gif"><img class="size-full wp-image-2705" alt="image008" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image008.gif" width="386" height="311" /></a></strong><strong></strong></p>
<p align="center">Figure 4 &#8211; Flat File Connection General</p>
<p align="center"><strong><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image010.gif"><img class="size-full wp-image-2707 aligncenter" alt="image010" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image010.gif" width="431" height="345" /></a> </strong>Figure 5 &#8211; Flat File Connection Columns Tab</p>
<p align="center"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image012.gif"><img class="size-full wp-image-2709 aligncenter" alt="image012" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image012.gif" width="451" height="219" /></a></p>
<p align="center">Figure 6 &#8211; A test tab delimited text file with one header row</p>
<p align="center"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image014.gif"><img class="size-full wp-image-2711 aligncenter" alt="image014" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image014.gif" width="396" height="358" /></a></p>
<p align="center">Figure 7 &#8211; Flat File Connection Advanced Tab<strong> </strong></p>
<p><strong>New File Connection (A connection that points to the Processed Folder)</strong></p>
<p align="center"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image016.gif"><img class="size-full wp-image-2713 aligncenter" alt="image016" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image016.gif" width="360" height="172" /></a></p>
<p align="center">Figure 8 &#8211; New File Connection dialog box</p>
<p>                  To set up a connection to the folder that will contain all of the archived files (in their dated folders) you will need to add a file connection. This is pretty straight forward, just change the usage type to ‘Existing Folder’ and browse to the folder on the server. Note that if you are using mapped drives you will need to type the location in the Folder textbox using the server name on this format \\servername\somefolder\destfolder.  The folder you are pointing to must exist before you complete this step.  The File Connection Manager Editor can be seen in Figure 8 &#8211; New File Connection dialog box.</p>
<p><strong>New OLE DB Connection</strong></p>
<p style="text-align: center;"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image018.gif"><img class="size-full wp-image-2715" alt="image018" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image018.gif" width="358" height="368" /></a></p>
<p align="center">Figure 9 &#8211; New OLEDB Connection manager  window</p>
<p><strong>Displaying and using the toolbox</strong></p>
<p style="text-align: center;"><b> <a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image019.png"><img class="size-full wp-image-2716" alt="image019" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image019.png" width="285" height="353" /></a></b></p>
<p align="center">Figure 10 &#8211; Show / Hide the Toolbox</p>
<p><b>                  </b>The toolbox provides drag and drop elements that can be added to the control flow and data flow tabs in SQL Servers Management Studio. It is important to note that the options available within the toolbox change depending on the tab that you are working in. This distinction is usually ignored in many of the online tutorials that you will find, which in leaves the reader wondering why they do not see those options.</p>
<p>To display the Toolbox pane click on the view menu item then press the toolbox icon, or just use the shortcut keys Ctrl+Alt+X.</p>
<p><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image022.gif"><img class="size-full wp-image-2719 aligncenter" alt="image022" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image022.gif" width="211" height="186" /></a></p>
<p style="text-align: center;">Figure 11 &#8211; Toolbox when Control Flow is displayed</p>
<p style="text-align: center;"><img class="size-full wp-image-2721 aligncenter" alt="image024" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image024.gif" width="213" height="186" /></p>
<p style="text-align: center;">Figure 12 &#8211; Toolbox when Data Flow is shown.</p>
<p>The figures above illustrate the different toolboxes. The next section will focus on the items necessary to complete the data import task.</p>
<p><strong>Add Foreach Loop Container</strong></p>
<p style="text-align: center;"><strong> <a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image026.gif"><img class="size-full wp-image-2723" alt="image026" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image026.gif" width="470" height="181" /></a></strong></p>
<p style="text-align: center;">Figure 13 &#8211; The Foreach loop Container</p>
<p>The Foreach loop container allows you to loop through a collection of objects. To configure the container double click on it to display the Foreach loop editor which is shown in Figure 14 &#8211; Foreach Loop Editor General Tab.</p>
<p>In the General tab change the Name to ‘Loop thru files’.</p>
<p>The next tab is the Collection tab; this is where you will be able to let the container know which directory it is supposed to loop through, as well as which files it should process. In this tab you will have to enter a value in the Folder textbox in the Enumerator configuration section of the application. The Files textbox works just like a file search in windows explorer, so if you wanted to loop through all the text files in a folder you would have to add ‘*.txt’.</p>
<p>The third tab is the ‘Variable Mappings’ tab, and is where we will connect the variable that is specified in the ‘Collection’ tab under the Enumerator configuration section. The variable in this instance will be set to the fully qualified file name.</p>
<p>Finally, in the expressions tab we will set up the variables that will hold the Directory and FileSpec values, this way we can go in later and change them by simply updating the variable’s value. To map the variables just click on the ellipsis in the right hand column of the expressions line of the Foreach Loop editor. Once the Property Expression Editor is displayed you can select a value in the right hand box that you would like to assign the variables value to.  Figure 17 &#8211; The Expressions tab of the Foreach Loop Editor shows both the Expressions tab and the Property Expression Editor.</p>
<p align="center"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image028.gif"><img class="size-full wp-image-2725 aligncenter" alt="image028" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image028.gif" width="346" height="288" /></a></p>
<p align="center">Figure 14 &#8211; Foreach Loop Editor General Tab</p>
<p align="center"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image030.gif"><img class="size-full wp-image-2727 aligncenter" alt="image030" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image030.gif" width="344" height="281" /></a></p>
<p align="center">Figure 15 &#8211; The Collection tab of the Foreach Loop Editor<strong><br clear="all" /> </strong></p>
<p align="center"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image032.gif"><img class="size-full wp-image-2729 aligncenter" alt="image032" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image032.gif" width="354" height="288" /></a></p>
<p align="center">Figure 16 &#8211; The Variable Mappings tab of the Foreach Loop Editor</p>
<p align="center"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image034.gif"><img class="size-full wp-image-2731 aligncenter" alt="image034" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image034.gif" width="356" height="291" /></a></p>
<p align="center">Figure 17 &#8211; The Expressions tab of the Foreach Loop Editor</p>
<p><strong>Add Execute SQL Task</strong></p>
<p><strong>                 </strong> When looping through the files the application will expect that the incoming data conform to the specifications that are set later in the data flow task. If for some reason the data does not conform to the specifications it will cause the entire job to stop executing. In order to determine where the job stopped running and to provide a means of restarting the job without deleting the data that was successfully input before the job failed it is important to log the file that has been processed and check that this file is not imported twice. This task will check the file log and determine if the file has been run already.</p>
<p><strong>                  </strong>First drop the Execute SQL Task Control Flow Item into the Foreach loop container.  Next double click on the container to view the Execute SQL Task Editor, shown in the figure below.</p>
<p style="text-align: center;"><strong><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image036.gif"><img class="size-full wp-image-2733" alt="image036" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image036.gif" width="411" height="350" /></a><br />
</strong></p>
<p align="center">Figure 18 The General tab of the Execute SQL Task Editor<strong></strong></p>
<p><strong>                  </strong>In the tab above change the name to read ‘Check Processed’. Change the result set from None to Single Row, then drop down the connection and if you have not added a connection to the database yet click on &lt;New Connection&gt; and add a connection to the database. Given the table structure for the processed files table found on page one place the following SQL in the SQL Statement area.</p>
<p><em>SELECT COUNT(*) AS Processed FROM file_control WHERE ImportedFilename = ?</em></p>
<p><strong>                  </strong>Notice the question mark in the sql statement, this will receive the value in the parameter mapping tab that we will set up now. In the ‘Variable Name’ column drop down the box and select the FilePath variable that was set up earlier. Note that all variables that are user created will be prefixed with the word User and two colons (::). The directions should be Input, the Data Type is VARCHAR, and of course, this is the 0<sup>th</sup> parameter so place 0 in the Parameter Name column.  Adjust Parameter Size according to your file path size; here 200 will cover anything that is thrown at it.</p>
<p style="text-align: center;"><strong> <a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image038.gif"><img class="size-full wp-image-2735" alt="image038" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image038.gif" width="410" height="348" /></a></strong></p>
<p align="center">Figure 19 &#8211; The Parameter Mapping tab of the Execute SQL Task Edito<b>n</b></p>
<p><strong>                  </strong>Next click on the ‘Result Set’ tab and in the Result Name column type in ‘Processed’, and in the variable column drop down the box and select the user defined variable named User::Processed.</p>
<p style="text-align: center;"><strong> <a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image040.gif"><img class="size-full wp-image-2737" alt="image040" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image040.gif" width="441" height="374" /></a></strong></p>
<p align="center">Figure 20 &#8211; The Result Set tab of the Execute SQL Task Editor</p>
<p><strong>Add data Flow Task</strong></p>
<p style="text-align: center;"><b> <a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image042.gif"><img class="size-full wp-image-2676" alt="image042" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image042.gif" width="251" height="352" /></a></b></p>
<p align="center">Figure 21 &#8211; Data Flow Task with Context Menu visible as well as the data Flow tab visible</p>
<p>Next we will add the data flow task by dragging it inside the Loop thru files container. First, drag the green arrow that comes from the Check processed task that you just created to the new data Flow Task and connect the two.</p>
<p>Double clicking on the data Flow Task will take you to the data Flow tab pictured in the image above, which will allow you to drag and drop additional elements inside of the data flow task. The elements that are available will differ when inside the data flow tab. To rename the Data Flow Task you will have to right click on it and select Rename, at this point give the task the name ‘Import file’.</p>
<p><strong>                 </strong> Next , double click the Import file task to change your view to the data Flow tab. Once inside the data flow tab we will need to drag four elements from the toolbox to the tab.<strong>         </strong></p>
<ul>
<li><strong></strong>Flat File Source element</li>
<li>Multicast element</li>
<li>OLE DB Destination element</li>
<li>Row Count element</li>
</ul>
<p>After adding these elements connect them by dragging the green lines as shown in the figure below.</p>
<p style="text-align: center;"><strong> <a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image044.gif"><img class="size-full wp-image-2678" alt="image044" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image044.gif" width="358" height="298" /></a></strong></p>
<p align="center">Figure 22 &#8211; Arraignment of elements in the Import file task<strong> </strong></p>
<p><strong>Add Flat File Source</strong></p>
<p style="text-align: center;"><strong> <a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image046.gif"><img class="size-full wp-image-2680" alt="image046" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image046.gif" width="416" height="360" /></a></strong></p>
<p align="center">Figure 23 &#8211; The Connection Manager  tab of Flat File Source Editor<b><br />
</b></p>
<p><strong>                 </strong> Double click on the Flat File source element to display the editor window. In the Connection Manager tab you should have the option of selecting the connection manager that points to the flat file you would like to import. You can refer to the file in Figure 6 &#8211; A test tab delimited text file with one header row for the file that we are using in this case. Once you have selected the connection move on to the ‘Columns’ section of the editor (pictured in the figure below). The Columns tab will allow you to rename the output from the file into names that actually mean something to you. Here I would suggest using the actual names in the destination table as it will make it easier to map the columns when you get to the OLE DB Destination part of this task. To change the names just click in the Output Column cell and type the name that you would like to be sent to the Multicast element. Once you complete these steps the small red X in the top right hand corner of the element should disappear. You can think of this X as an error in the compiler if you were writing code.</p>
<p style="text-align: center;"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image048.gif"><img class="size-full wp-image-2682" alt="image048" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image048.gif" width="409" height="356" /></a></p>
<p align="center">Figure 24 &#8211; The Columns  tab of Flat File Source Editor</p>
<p><strong>Add Multicast </strong></p>
<p><strong>                  </strong>The Multicast element is one of the few that does not need any changes once placed. This element will simply take the input from the Flat File Source and route it to two locations. In this instance those locations are the DB destination, to actually insert the data into the database, and the row count element to determine how many rows were inserted for logging purposes.</p>
<p><strong>Add OLE DB Destination</strong></p>
<p><strong>                 </strong> The OLE DB Destination will point to the table that will receive the data from the file. The SQL to create the test table that corresponds with the test data file in Figure 6 &#8211; A test tab delimited text file with one header row is below:</p>
<pre class="brush: sql; title: ; notranslate">
CREATE TABLE [dbo].[file_import_test](

[TestColumn1] [int] NULL,

[TestColumn2] [varchar](200) NULL,

[TestColumn3] [float] NULL,

[TestColumn4] [float] NULL

)
</pre>
<p><strong>                </strong>  First, double click on the DB connection to display the OLE DB Destination Editor (pictured in the image below).  Next, drop down the connection manager and select the connection that points to your database, which should have been set up earlier. You will want to select ‘table or View’ for the data Access Mode, and finally select the actual table where you want the file data to be routed to in the name of the table or the view dropdown box. Finally, we will map the columns from the file to the table columns. Click on the Mappings tab in the left window pane.</p>
<p style="text-align: center;"><strong> <a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image050.gif"><img class="size-full wp-image-2684" alt="image050" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image050.gif" width="417" height="390" /></a></strong></p>
<p align="center">Figure 25 &#8211; The Connection Manager tab of the OLE DB Destination Editor</p>
<p>If you configured your flat file column names to match the table column names then this part will be pretty easy, just verify that they link up. If not you are left with the task of connecting the file column outputs with the table columns and then connecting them by dragging and dropping the lines between them to the correct columns. Once you complete this task the small red X in the OLE DB Destination element should disappear.</p>
<p align="center"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image052.gif"><img class="size-full wp-image-2686 aligncenter" alt="image052" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image052.gif" width="365" height="317" /></a></p>
<p align="center">Figure 26 &#8211; The Mappings tab of the OLE DB Destination Editor</p>
<p><strong>Add Row Count Element</strong></p>
<p><b>                  </b>The row count element will count the rows that have been read from the file and store them in the variable that has been designated in the custom properties section of the Component properties tab pictured below. All that needs to be done here is the variable User::Records should be selected from the drop down box in the column next to variable name.</p>
<p align="center"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image054.gif"><img class="size-full wp-image-2688 aligncenter" alt="image054" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image054.gif" width="385" height="348" /></a></p>
<p align="center">Figure 27 &#8211; The Advanced Editor for Row Count</p>
<p><strong>Insert Constraint between Check processed and the Import file Data Flow Task</strong></p>
<p>The final step in the addition of the Import file data flow task is to set up a constraint between the check processed SQL task and the data flow itself. The constraint will make sure that duplicate records do not get inserted into the table. To accomplish this double click the green arrow that connects the two elements to display the Precedence Constraint Editor.</p>
<p align="center"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image056.gif"><img class="size-full wp-image-2690 aligncenter" alt="image056" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image056.gif" width="388" height="289" /></a></p>
<p align="center">Figure 28 &#8211; Precedence Constraint Editor</p>
<p>                  In the window pictured above change the drop down box from the default setting of Constraint to Expression and Constraint. Once this has been completed the Expression text box will open where you enter @Processed == 0, which corresponds to the variable being passed by the Check processed SQL task. Leave the default setting in Multiple Constrains where it is and press OK.<b> </b></p>
<p><strong>Add Execute SQL Task (Register Processing)</strong></p>
<p>Next , drag another Execute SQL task element to the Foreach Loop Container and drop it inside the container directly under the data flow task. Right click on the task and rename it ‘Register Processing’.</p>
<p style="text-align: center;"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image054.gif"><img class="size-full wp-image-2688" alt="image054" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image054.gif" width="385" height="348" /></a></p>
<p align="center">Figure 29 &#8211; The General tab of the Execute SQL Task Editor</p>
<p>                  In the General tab of the Execute SQL task Editor select the database connection from the connection dropdown box. In the SQL Statement text area insert the following SQL:</p>
<p><em><b>INSERT INTO file_control (ImportedFilename, RecordsImported) VALUES (?, ?)</b></em></p>
<p align="center"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image060.gif"><img class="size-full wp-image-2694 aligncenter" alt="image060" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image060.gif" width="409" height="349" /></a></p>
<p align="center">Figure 30 &#8211; The Parameter Mapping tab of the Execute SQL Task Editor</p>
<p>                  Next click on the parameter mapping tab and add the following parameters to the window on the right hand side, 1) User::FilePath with a direction of Input and a datatype of VARCHAR and a size of 200, and 2) User::Records with adirection of Input and a type of LONG and a size of -1. The parameter name of the first variable is 0 and the parameter name of the second variable is 1.</p>
<p><strong>Add Script Task</strong></p>
<p>Next drag the Script Task element from the toolbox and drop it directly under the Register Processing SQL task.  Right click on the element and give it the name Set Destination. Double click on the element to display the Script Task Editor window.  Make sure the Script language is set to Microsoft Visual Basic 2008 then press the Edit Script … button at the bottom of the window to bring up the code editor. The script that will create archive directories is below and will need to replace the code that is between the following lines:</p>
<pre class="brush: java; title: ; notranslate">
Public Sub Main()

…..

End Sub

&lt;b&gt;Microsoft Visual Basic 2008 Code&lt;/b&gt;

Dim varCollection As Variables = Nothing

Dts.VariableDispenser.LockForRead(&quot;User::FilePath&quot;)

Dts.VariableDispenser.LockForRead(&quot;User::DestinationRoot&quot;)

Dts.VariableDispenser.LockForRead(&quot;User::MonthStartPosition&quot;)

Dts.VariableDispenser.LockForRead(&quot;User::MonthNameFormat&quot;)

Dts.VariableDispenser.LockForWrite(&quot;User::DestinationFolder&quot;)

Dts.VariableDispenser.GetVariables(varCollection)

Dim SourceFilePath As String = varCollection(&quot;User::FilePath&quot;).Value.ToString()

Dim FileName As String = SourceFilePath.Substring(SourceFilePath.LastIndexOf(&quot;\&quot;) + 1)

Dim DestinationRoot As String = varCollection(&quot;User::DestinationRoot&quot;).Value.ToString()

Dim MonthStartPosition As Integer = Convert.ToInt32(varCollection(&quot;User::MonthStartPosition&quot;).Value)

Dim MonthValue As Integer = 0

Dim Yearvalue As Integer

Dim MonthNameFormat As String = varCollection(&quot;User::MonthNameFormat&quot;).Value.ToString()

Dim FolderName As String = String.Empty

Dim MonthwiseDirectory As String = String.Empty

MonthValue = Month(Now())

Yearvalue = Year(Now())

If FileName.Length &gt; 0 AndAlso MonthValue &gt; 0 Then

FolderName = New DateTime(1, MonthValue, 1).ToString(MonthNameFormat) &amp; &quot; &quot; &amp; Yearvalue

End If

MonthwiseDirectory = System.IO.Path.Combine(DestinationRoot, FolderName)

If Not System.IO.Directory.Exists(MonthwiseDirectory) Then

System.IO.Directory.CreateDirectory(MonthwiseDirectory)

End If

varCollection(&quot;User::DestinationFolder&quot;).Value = MonthwiseDirectory

Dts.TaskResult = ScriptResults.Success
</pre>
<p>The code above will create a folder structure for archiving the files that have been processed using a month / year naming convention as shown in Figure 31 &#8211; Example of the Archived File Structure.</p>
<p align="center"><a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image062.gif"><img class="size-full wp-image-2696 aligncenter" alt="image062" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image062.gif" width="389" height="54" /></a></p>
<p align="center">Figure 31 &#8211; Example of the Archived File Structure</p>
<p>                  The parent folder for these monthly folders is determined by the value in the variable DestinationFolder.</p>
<p><strong>Add File System Task (Move Files)</strong></p>
<p style="text-align: center;"><b> <a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image064.gif"><img class="size-full wp-image-2698" alt="image064" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image064.gif" width="409" height="347" /></a></b></p>
<p align="center">Figure 32 &#8211; File System Task Editor General Settings Tab</p>
<p>                  Next drag a File System Task element from the toolbox and drop it inside the Foreach Loop Container under the Script Task then connect the greed arrow from the Script Task to the File System Task. Right click on the element and rename it Move Files. This will be the element that physically moves the files to the archive location.</p>
<p>To move the processed files change the following settings <strong><i><span style="text-decoration: underline;">in this order, or it will not work</span></i>:</strong></p>
<p><strong>Destination Connection Section</strong></p>
<ul>
<li>IsDestinationPathVariable = true, this in turn changes the text in the box below it from Destination Connection to DestinationVariable</li>
<li>DestinationVariable = User::DestinationFolder</li>
<li>OverwriteDestination  =false</li>
</ul>
<p><strong>Source Connection Section</strong></p>
<ul>
<li>IsSourcePathVariable = true, this in turn changes the text in the box below it from SourceConnection to SourceVariable</li>
<li>Sourcevariable = User::FilePath</li>
</ul>
<p><strong>Add Execute SQL Task (Update processed table) </strong></p>
<p><strong>                  </strong>The last task that you have to complete before setting up the job that will kick off this entire process is to drag an Execute SQL Task element to the Foreach Loop Container and drop the element directly below the Move Files element that you just completed. Right click on the object and rename it ‘Update processed table’, as the name suggests this task will actually go out and rename the files appending the word processed to the imported file name so that the application will not skip the file when it is dropped in the new file location tomorrow (this assumes that you are working on files that will be coming in using the same name every day which is very common!).  You should be getting pretty good at the SQL Task object by now so here are the steps required to update the file names.</p>
<p style="text-align: center;"><strong> <a href="http://www.learnsomethings.com/wp-content/uploads/2013/02/image065.png"><img class="size-medium wp-image-2699" alt="image065" src="http://www.learnsomethings.com/wp-content/uploads/2013/02/image065-300x254.png" width="300" height="254" /></a></strong></p>
<p align="center">Figure 33 &#8211; Your completed .dtsx package should look like this</p>
<p><strong>Visual Basic and C# date Time Format Specifiers:</strong></p>
<p><a href="http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx?cs-save-lang=1&amp;cs-lang=vb#code-snippet-2">http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx?cs-save-lang=1&amp;cs-lang=vb#code-snippet-2</a><strong> </strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2013/02/24/importing-flat-file-data-into-sql-server-with-ssis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What! A month off</title>
		<link>http://www.learnsomethings.com/2013/01/01/what-a-month-off/</link>
		<comments>http://www.learnsomethings.com/2013/01/01/what-a-month-off/#comments</comments>
		<pubDate>Wed, 02 Jan 2013 00:16:36 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[ExtJs Stuff]]></category>
		<category><![CDATA[Sencha Touch]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2659</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
You may have noticed a month lag between posts, or more likely you didn’t and I was just giving myself more credit than was due. I have spent the past month enjoying Thanksgiving, Christmas, and coding an update to the &#8230; <a href="http://www.learnsomethings.com/2013/01/01/what-a-month-off/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>You may have noticed a month lag between posts, or more likely you didn’t and I was just giving myself more credit than was due. I have spent the past month enjoying Thanksgiving, Christmas, and coding an update to the TakeStock app that I originally released in response to the first Sencha contest. I wanted to use the command line tools, see if there were any improvements in local storage, as last time around I had to fall back on SqlLite to get the data stored locally on the client machine. I also wanted to take a small stab at skinning an app using SASS and SCSS. Of course, I am now nearing the end of this experiment and have had some time to gather everything together in a presentation designed to give you all the resources you will need to build your first Sencha Touch app in one place. Here’s the post:</p>
<p><a href="http://bit.ly/TFkRFe" target="_blank">http://bit.ly/TFkRFe</a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2013/01/01/what-a-month-off/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Saving SVG to PNG on your cold fusion server</title>
		<link>http://www.learnsomethings.com/2012/11/20/saving-svg-to-png-on-your-cold-fusion-server/</link>
		<comments>http://www.learnsomethings.com/2012/11/20/saving-svg-to-png-on-your-cold-fusion-server/#comments</comments>
		<pubDate>Wed, 21 Nov 2012 01:35:46 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[ExtJs Stuff]]></category>
		<category><![CDATA[cold fusion]]></category>
		<category><![CDATA[EXT]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[extjs4]]></category>
		<category><![CDATA[extjs4 overrides and plugins]]></category>
		<category><![CDATA[sencha]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2651</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
I built a client side javascript SVG to PNG converter that works on *modern* browsers, however, depending on your target audience the browsers that frequent your site may be less than modern – i.e. IE. In this situation you only &#8230; <a href="http://www.learnsomethings.com/2012/11/20/saving-svg-to-png-on-your-cold-fusion-server/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>I built a client side javascript SVG to PNG converter that works on *modern* browsers, however, depending on your target audience the browsers that frequent your site may be less than modern – i.e. IE. In this situation you only have one option, convert the image on the server side and then render it using the good old image tag.</p>
<p>First, cold fusion ships with some outdated batik files (which handle the cfimage tag) , so you will need to update those first, and add the missing files that will add your svg to -&gt; image processing ability. I used the steps found in this post to accomplish the task; I’ll list them here in short format so you can get into the ext chart part of this project.</p>
<ol>
<li>Stop your cold fusion service</li>
<li>Download the files from the batik website <a href="http://xmlgraphics.apache.org/batik/download.cgi">http://xmlgraphics.apache.org/batik/download.cgi</a></li>
<li>Rename the jar files in /wwwroot/WEB-INF/cfform/jars/  that start with batik by adding the extension .old</li>
<li>Copy the batik jar files into /wwwroot/WEB-INF/lib</li>
<li>Restart Cold Fusion</li>
</ol>
<p>Next, let’s assume that we have two files, one called convertImage.cfm and one called convertImage.cfc, of course, we want to pass the svg markup to the cfm which will pass the data to the cfc for processing.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;cfcase value=&quot;saveChart&quot;&gt;
        &lt;cfset saveChart = data.saveChart( svg=form.svg) /&gt;
        &lt;cfset json = &quot;{'success':'#saveChart#'}&quot; /&gt;
&lt;/cfcase&gt;
</pre>
<p>The code below goes in the cfc file.</p>
<pre class="brush: xml; title: ; notranslate">
&lt;cffunction name=&quot;saveChart&quot; &gt;
        &lt;cfargument name=&quot;svg&quot; /&gt;
            &lt;cftry&gt;
            &lt;cfset svgFile = &quot;c:\websites\temp.svg&quot; /&gt;
            &lt;cfset jpgFile = replace(&quot;c:\websites\temp.svg&quot;, &quot;.svg&quot;, &quot;.jpg&quot;) /&gt;
            &lt;cfset pngFile = (pngPath) /&gt;---&gt;
            &lt;cffile action=&quot;delete&quot; file=&quot;c:\websites\temp.jpg&quot; &gt;

	&lt;cfif FileExists(svgFile)&gt;
            	&lt;cffile action=&quot;delete&quot; file=&quot;c:\websites\temp.svg&quot; &gt;
            	&lt;cffile action=&quot;write&quot; file=&quot;c:\websites\temp.svg&quot; output=&quot;#svg#&quot; &gt;
           &lt;cfelse&gt;
           	&lt;cffile action=&quot;write&quot; file=&quot;c:\websites\temp.svg&quot; output=&quot;#svg#&quot;  &gt;
           &lt;/cfif&gt;

            &lt;cfset t = createObject(&quot;java&quot;, &quot;org.apache.batik.transcoder.image.JPEGTranscoder&quot;).init() /&gt;
            &lt;cfset svgURI = createObject(&quot;java&quot;, &quot;java.io.File&quot;).init(svgFile).toURL().toString() /&gt;
            &lt;cfset input 	= createObject(&quot;java&quot;, &quot;org.apache.batik.transcoder.TranscoderInput&quot;).init(svgURI) /&gt;
            &lt;cfset ostream 	= createObject(&quot;java&quot;, &quot;java.io.FileOutputStream&quot;).init(jpgFile) /&gt;
            &lt;cfset output 	= createObject(&quot;java&quot;, &quot;org.apache.batik.transcoder.TranscoderOutput&quot;).init(ostream) /&gt;
            &lt;cfset t.transcode(input, output) /&gt;
            &lt;cfset ostream.flush() /&gt;
            &lt;cfset ostream.close() /&gt;

            &lt;cfcatch type=&quot;any&quot;&gt;
          		 &lt;cfreturn &quot;false&quot; /&gt;
            &lt;/cfcatch&gt;
            &lt;/cftry&gt;
        &lt;cfreturn &quot;true&quot; /&gt;
    &lt;/cffunction&gt;
</pre>
<p>The function below would go in your javascript controller.</p>
<pre class="brush: jscript; title: ; notranslate">
   saveChart: function(me){
        this.dTask.delay(500, function(){
                var svg = me.up('panel').down('chart').save(
                    {
                        type    :'image/svg+xml'
                    }
                );

                Ext.Ajax.request({
                    url: 'convertImage.cfm?remoteEvent=saveChart',
                    params: {
                        svg: svg
                    },
                    success: function(){
                        // process server response here
                        window.open('temp.jpg');
                    }
                });
        });
    },
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/11/20/saving-svg-to-png-on-your-cold-fusion-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Versions everywhere ….  How to really use the Sencha Command Line Tools</title>
		<link>http://www.learnsomethings.com/2012/11/17/versions-everywhere-how-to-really-use-the-sencha-command-line-tools/</link>
		<comments>http://www.learnsomethings.com/2012/11/17/versions-everywhere-how-to-really-use-the-sencha-command-line-tools/#comments</comments>
		<pubDate>Sat, 17 Nov 2012 16:13:11 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[ExtJs Stuff]]></category>
		<category><![CDATA[Sencha Touch]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[extjs4]]></category>
		<category><![CDATA[javascript mobile development]]></category>
		<category><![CDATA[sencha]]></category>
		<category><![CDATA[sencha touch]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2646</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
What and Why I wanted to take advantage of Senchas touch 2 and update the Take Stock app I built way back when touch was being released using version 0.97. Over the summer I went to the Touch training that &#8230; <a href="http://www.learnsomethings.com/2012/11/17/versions-everywhere-how-to-really-use-the-sencha-command-line-tools/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p><strong>What and Why</strong><br />
I wanted to take advantage of Senchas touch 2 and update the Take Stock app I built way back when touch was being released using version 0.97. Over the summer I went to the Touch training that Sencha provided in Manhattan and got really excited about the prospects of the sencha command line tools that allow you to build a streamlined (compressed) version of your app and deploy it across multiple platforms with a few easy commands. To do this, the builder will take just the classes that you need opposed to the entire javascript library and combine them with your code then minimize the code using the YUI compressor.</p>
<p>Using Sencha without the command line tools is like driving an 18 wheeler to deliver the neighborhood mail when a small jeep will do just fine – so I guess what I want to say is yes, if you want responsive apps you will have to learn to love the command line tools or deal with the fact that your app will be burdened with extra weight and needless requests.</p>
<p>In order for all of this to work, your app needs to adhere to the Sencha MVC structure, and your code has to be tight – how tight? In the DateFilter there is a trailing comma which ships with Sencha and was throwing off my build process while the app worked fine.</p>
<p><strong>How</strong></p>
<p>Remember reading ‘in the summer’ a few paragraphs back? It looks like Sencha has been very busy over the past few months releasing beta version after beta version, what hasn’t been too clear is the documentation or the naming  conventions of the old Cmd vs Command vs the Command Line tools in the SDK. The names are so similar the chances of you finding and trying to use the wrong documentation for the version you are using is damn near 100%, however, the improvements are worth all of the time invested, and I cannot imagine starting another project without using Sencha Command!</p>
<p><strong>Easy Steps to a perfect install </strong></p>
<p><strong></strong>1. For Windows users make sure that you are installing everything from your profile otherwise chances are Ruby and Compass will give you errors, and Sencha Command uses both to create the CSS files for your new app during the build process.</p>
<p>2. Install RUBY by visiting <a href="http://www.ruby-lang.org/en/downloads/">http://www.ruby-lang.org/en/downloads/</a> and following the instructions for your operating system. If you are developing on a Mac Ruby is installed by default, however, you will need to follow the next few steps.</p>
<p>3. Install Compass (<a href="http://compass-style.org/install/">http://compass-style.org/install/</a> ). This can be done from the command line / or terminal by typing the following commands:</p>
<pre class="brush: xml; title: ; notranslate">
$ gem update –system
$ gem install compass
</pre>
<p>4. Ok, now here comes the tricky part, you have to install Version 3 of Sencha Command which can be found here for all platforms -&gt; <a href="http://www.sencha.com/products/sencha-cmd/download">http://www.sencha.com/products/sencha-cmd/download</a>.</p>
<p>5.) Now download Sencha Touch 2.1 or Extjs 4.1a. These are the only versions that will work with the new Sencha Command tools!</p>
<p>6.) Unzip your Sencha Touch or Extjs file to the root of your web directory. At this point you can safely refer to the Touch/Extjs files as your ‘SDK’.</p>
<p><strong>Congratulations, you just installed the command line and set up your web folder, now let’s start a quick Sencha Touch app using the command line tools.</strong></p>
<p><strong></strong>1.) Open the cmd window in Windows or terminal in everything else and change your directory to the ‘SDK’ otherwise known as the Extjs or Touch folder in your web root.</p>
<p>2) Now you will need to generate the basic MVC framework for your new Sencha Touch application, this can be done right from the command line by typing in the following command:</p>
<pre class="brush: xml; title: ; notranslate">
$ sencha generate app /path/to/your/app
</pre>
<p>3) You should now have a ‘starter’ application in the folder that you specified above (/path/to/your/app). The folder structure should look like this:</p>
<p><img class="alignnone" title="MVC Application Folder Structure" src="http://img3.sencha.com/files/learn/p2a.png" alt="" width="306" height="381" /></p>
<p>Notice that there is a .sencha folder which contains an app and workspace folder, inside the app folder there is a file named sencha.cfg, if you open this file you will see your app name, framework, and directory settings. This is where, you guessed it, you can change the name of your application.</p>
<p><strong>Great, now you have the application set up, let’s look at the steps required to deploy the application to a production environment.</strong></p>
<p>First let’s discuss what ‘builing’ an app does. If you take a look in your ‘SDK’ folder aka Sencha-Touch or extjs notice that there is a file named ext-all.js (around 1.2MB) or sencha-touch-all.js (around 900KB). The file name alludes to the fact that they contain all of the classes in ext or touch minus the UX classes. Chances are good that you don’t actually use all of the classes that are provided by sencha, so why force your users to download all the classes on top of your app.js and MVC javascript files?  If you open up the folder src in your extjs or sencha touch folder you can get a look at the sizes of the individual classes that make up ext-all or sencha-touch-all.</p>
<p>The builder will search your code for class dependencies and compile all of the classes that you need to run your application, next the builder will compile all of your views, models, stores, and controllers into one nice file. Finally, the builder takes the extjs javascript as well as your application javascript and merges the two into one single javascript file. After this is done, the builder then ‘minifies’ your javascript which saves additional space. You gain a few clear advantages:</p>
<ul>
<li>You minimize request overhead (<a href="https://developers.google.com/speed/docs/best-practices/payload#MinifyJS">https://developers.google.com/speed/docs/best-practices/payload#MinifyJS</a>)</li>
<li>You minimize round-trip times (<a href="https://developers.google.com/speed/docs/best-practices/rtt">https://developers.google.com/speed/docs/best-practices/rtt</a> )</li>
<li>You minimize payload size (<a href="https://developers.google.com/speed/docs/best-practices/payload">https://developers.google.com/speed/docs/best-practices/payload</a> )</li>
</ul>
<p><strong>To build your new app just type the following command in the terminal:</strong></p>
<pre class="brush: xml; title: ; notranslate">
$ sencha app build
</pre>
<p>The first time you issue this command the builder will create a folder named ‘build’ in which will be a folder with your app name. This folder contains your different ‘builds’. The folder named production contains the – you guessed it – production version of your application. Inside you will find the all-classes.js file which is your code plus the extjs code minimized, an ext folder which contains the CSS and any UX files that you may need in addition to any themes, and finally, your resources. It’s the files in this folder that you should push to your production server, they are all that is needed to run your new faster, sleeker, sencha application.</p>
<p>This is just the beginning of what can be accomplished using the new command tools, I’ll try and post some instructions on creating models, alternate versions, and so forth in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/11/17/versions-everywhere-how-to-really-use-the-sencha-command-line-tools/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extjs adding file extension validation client side</title>
		<link>http://www.learnsomethings.com/2012/10/18/extjs-adding-file-extension-validation-client-side/</link>
		<comments>http://www.learnsomethings.com/2012/10/18/extjs-adding-file-extension-validation-client-side/#comments</comments>
		<pubDate>Fri, 19 Oct 2012 00:32:35 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[ExtJs Stuff]]></category>
		<category><![CDATA[EXT]]></category>
		<category><![CDATA[extjs4]]></category>
		<category><![CDATA[extjs4 overrides and plugins]]></category>
		<category><![CDATA[sencha]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2640</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
One of the great things about extjs and all third party javascript libraries is the ease at which you can add the html file upload control to your page, and make it look professional. One of the things that almost &#8230; <a href="http://www.learnsomethings.com/2012/10/18/extjs-adding-file-extension-validation-client-side/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>One of the great things about extjs and all third party javascript libraries is the ease at which you can add the html file upload control to your page, and make it look professional. One of the things that almost every file upload application that I seen in use is a client side validation that is based on file extension, think about it would you like any file type making it to your server, including executables? The following code will add the file extension check to the upload on the client side. All you have to do is use the xtype &#8216;restfileupload&#8217;, and pass the extensions in an array without the period before the letters. Have Fun!</p>
<pre class="brush: jscript; title: ; notranslate">
/***********************************************
Adds extension validation at the client side
for the extjs File Upload field. You must
set the extension in an array of strings.
 **********************************************/
Ext.define('Ext.ux.restrictiveFileUpload', {
	extend  : 'Ext.form.field.File',
	alias   : 'widget.restfileupload',
	// Array of acceptable file extensions
	// overridden when decalred with a string
	// of extensions minus the period.
	accept      	: [],
	listeners   	: {
    	validitychange : function(me) {
        	// This gets the part of the file name after the last period
        	var indexofPeriod = me.getValue().lastIndexOf(&quot;.&quot;),
            	uploadedExtension = me.getValue().substr(indexofPeriod + 1, me.getValue().length - indexofPeriod);
 
        	// See if the extension is in the 
                //array of acceptable file extensions
        	if (!Ext.Array.contains(this.accept, uploadedExtension)){
            	// Add the tooltip below to 
                // the red exclamation point on the form field
      	      me.setActiveError('Please upload files with an extension of :  ' + this.accept.join() + ' only!');
           	// Let the user know why the field is red and blank!
            	Ext.MessageBox.show({
                	title   : 'File Type Error',
                	msg 	: 'Please upload files with an extension of :  ' + this.accept.join() + ' only!',
                	buttons : Ext.Msg.OK,
                	icon	: Ext.Msg.ERROR
            	});
            	// Set the raw value to null so that the extjs form submit
            	// isValid() method will stop submission.
            	me.setRawValue(null);
        	}
    	}
	}
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/10/18/extjs-adding-file-extension-validation-client-side/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Baltimore Marathon 2012</title>
		<link>http://www.learnsomethings.com/2012/10/17/baltimore-marathon-2012/</link>
		<comments>http://www.learnsomethings.com/2012/10/17/baltimore-marathon-2012/#comments</comments>
		<pubDate>Thu, 18 Oct 2012 02:45:26 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[ExtJs Stuff]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2617</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
Yesterday I got up at 4:30 AM nervous and unprepared for what I was about to take on, I drove the 45 minute drive to Baltimore faster than usual &#8211; I remember passing the sign on I 70 that read &#8230; <a href="http://www.learnsomethings.com/2012/10/17/baltimore-marathon-2012/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p><img alt="" src="http://farm9.staticflickr.com/8055/8086428738_95a31ceb64.jpg" class="alignright" width="300"  float="right" />Yesterday I got up at 4:30 AM nervous and unprepared for what I was about to take on, I drove the 45 minute drive to Baltimore faster than usual &#8211; I remember passing the sign on I 70 that read 25 miles to Baltimore and thinking, &#8220;What did I get myself into!&#8221;. The night before my daughter had some wise words of advice,Rule 1- &#8220;Don&#8217;t collapse in the street, walk if you have to.&#8221;</p>
<p>See, I spent the past three months deliberately not training as I overtrained for a 2010 marathon and had to sit out New York, yes that&#8217;s right I got into NY and missed it! Now I was second guessing my lack of training &#8212; but what the hell, I could run half and walk the rest if need be. This brings me to rule number 2, if this is your first marathon, finishing is a PR!</p>
<p>Anyway, by now It&#8217;s about 6ish in the morning and I made it to the ravens parking lot without any problems and pulled up right next to the finish line in front of the stadium. Rule number 3 &#8211; Parking matters &#8211; free and close beats the metro any day! You&#8217;ve heard the commercial on the radio with the guy that complains about walking too far to the car after finishing a marathon, there&#8217;s truth in it! At this point I&#8217;m nervous and excited at the same time. I spend the next hour drinking coffee and waiting until a fair amount of people start showing up in front of the stadium, time to walk. The last quarter mile of the race to the start which is right around the corner from the O&#8217;s stadium, which was bittersweet knowing that the night before they were taken out of the running by the Yankees. The night before the race I drove around the stadium when there was still hope in the air and people were gathered around a few taxicabs that had their radios on and tuned into the game.</p>
<p>I found the 4:30 pacer group and settled in, the crowd for the marathon was large but not overwhelming like some of the races down the road in DC. The mayor, and CEO of Under Armour spoke followed by the race princess, a six year young lady who has undergone nine major surgeries before the age of 5, then it was time to go. The confetti lasted so long that even after three minutes it was still raining down across the start.</p>
<p>The first three or so miles were all uphill until we reached Druid Hills Park and the Baltimore Zoo, someone on the side of the course was holding a sign that read, &#8220;Lion on the loose, casualty count 1,2,3,4, &#8230;..&#8221;. This scared me a bit being a fan of National Geographic i knew that he animals in the back of the pack were the first ones to go.</p>
<p>I turned the corner and made my way down to the zoo when I noticed a sign that said Marry Me, pretty cool, but I was wondering, couldn&#8217;t he place it on say an uphill section where you would want a break?</p>
<p>Through the gates and into the zoo where the zoo staff lined the next half mile or so all holding exotic birds, so I can say I ran past penguins, ravens, and owls while listening to elephants in the background. Next it was all downhill towards the inner harbor where we would meet up with the half marathon crew of like a million runners, of course with that many people you have a lot of spectators (like another million) lining the streets, some of the more memorable signs at this point were:</p>
<p>Chafe today brag forever &#8230;.</p>
<p>26.2 miles because 26.3 would be crazy, right?</p>
<p>It&#8217;s called a marathon, if it were easy it would be called your mom! (it took me half a mile to get that one)</p>
<p>Run bitches run ..</p>
<p>Back to the race, I was mentally prepared for a flat run around the inner harbor- why? &#8211; because this was the flat part of the course in the small elevation map on the website, so all I have to say is Federal Hill, really?</p>
<p>After the hill we ran under the Domino Sugar sign and around the Under Armor headquarters. The race had a contest where the loudest school on the course would get a cash prize, sorry, Federal Prep this one goes to Thomas Johnson. The course wound it&#8217;s way back through the inner harbor and we ran under the half marathon arch that was set up at the start &#8230;&#8230; Only 13.1 miles left! Next we were set to run through little Italy and the east side of Baltimore.</p>
<p>Favorite T-shirt on a runner, &#8220;Running Sucks&#8221;, around mile 15.</p>
<p>A few miles later we came over a ridge and all we could see was the wall of runners that had started the half marathon, and of course, hundreds of spectators lining the sides of the street, this was it &#8211; where the full marathon mixed with the half and we would all run, walk, or crawl together until the end.</p>
<p>The crowd slowed the pace considerably, and at some points I was walking faster than the crowds running pace. I made it to mile 20 in 3 hours and 20 minutes! Turns out that the next six would be the hardest six miles I have ever run, and take almost twice as long as my usual lunchtime run which is six miles long as well. I can remember looking at my Garmin around mile 24 thinking I didn&#8217;t know someone could move that slow!</p>
<p>The east side of Baltimore consisted of running uphill forever, but mile twenty marked the ring around lake Montebello like the Italian detective show on MHZ. Before hitting the lake I kept hoping that we would run by a gas station or something that was close to the street so I could get a coke or candy bar, however, the stores were few and far between. The lake would open into residential neighborhoods and a cold drink (other than gatorade or water) was out of the question! The ring around the lake made up a flat mile 21 and 22, at this point I was walking then running and walking, then running … I recall a band set up along the end of the lake but I can&#8217;t remember the web address they wrote down right now.</p>
<p>The next few miles were a series of small inclines, but after 20+ miles anything seemed like a mountain, then the hands down most motivating marathon &#8216;fans&#8217; appeared on top of a Toyota dancing, check out the video below:</p>
<p><object width="560" height="315"><param name="movie" value="http://www.youtube.com/v/zHeFxnMjys0?version=3&amp;hl=en_US&amp;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/zHeFxnMjys0?version=3&amp;hl=en_US&amp;rel=0" type="application/x-shockwave-flash" width="560" height="315" allowscriptaccess="always" allowfullscreen="true"></embed></object></p>
<p>This kept me laughing until a few blocks away you turned the corner and could see the finish line below, even tough it&#8217;s still a half mile or more out. It&#8217;s all downhill through camden yards to the finish!</p>
<p>I never paid much attention to the medal before the race, but if you look real close at the bottom it&#8217;s inscribed with the sentence, &#8220;what hills don&#8217;t kill you make you stronger&#8221;, excellent slogan for an excellent race.</p>
<p>Thanks Baltimore! The run couldn&#8217;t have been better!</p>
<p>Here&#8217;s the link to the stats and an interactive map if you want to check elevation gain loss in a larger screen: <a href="http://connect.garmin.com/activity/233056703" target="_blank">http://connect.garmin.com/activity/233056703</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/10/17/baltimore-marathon-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Gridpanel editor not firing when using locked columns in Extjs4</title>
		<link>http://www.learnsomethings.com/2012/10/17/gridpanel-editor-not-firing-when-using-locked-columns-in-extjs4/</link>
		<comments>http://www.learnsomethings.com/2012/10/17/gridpanel-editor-not-firing-when-using-locked-columns-in-extjs4/#comments</comments>
		<pubDate>Wed, 17 Oct 2012 21:07:53 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[ExtJs Stuff]]></category>
		<category><![CDATA[EXT]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[extjs4]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[sencha]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2612</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
I needed to use a locking grid and an editor in Extjs 4.1 today, and of course, there was a noted bug in the forums that mentioned that doing this would not be possible; the edit event would not fire. &#8230; <a href="http://www.learnsomethings.com/2012/10/17/gridpanel-editor-not-firing-when-using-locked-columns-in-extjs4/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>I needed to use a locking grid and an editor in Extjs 4.1 today, and of course, there was a noted bug in the forums that mentioned that doing this would not be possible; the edit event would not fire. I really, really needed this as I had promised the customer that it could be done and to use those famous last words that it would be *easy*.</p>
<p>It works, but (maybe not how you want it to work) ….. Here’s what I found out:</p>
<p>Why it looks like the edit event is not firing:</p>
<p>The extjs locking grid feature actually works by splitting your single grid into two grids, one with the columns that are locked and one with the columns that are not. Now let’s think about the document object model and how extjs generates html elements for a moment, in a lot of cases you are probably using an ID property in your grid, but when the user locks a column and effectively creates two grids from the initial grid what’s left are two auto-generated IDs. You may have heard many developers preach the evils of hardcoded IDs and now finally, we have a really concrete example of these IDs causing problems.</p>
<p>Problem 1: You created a grid gave it an ID or action property and set up your reference and / or listener on that grid like this:</p>
<pre class="brush: jscript; title: ; notranslate">
refs : [
{
    ref         :  'someGrid',
    selector    :  '#someGrid',
    autoCreate  :  true
}
]

</pre>
<p>Or  added a controller to the grid like this:</p>
<pre class="brush: jscript; title: ; notranslate">
'grid[id=someGrid]':{
    edit:this.onSomeGridEdit
}
</pre>
<p>Your code will not work, this ID no longer exists in the DOM, so no events will ever be called. You WILL need to set up a controller on the grid to listen to the edit event but this controller will have to work for both grids and will have to work independent of any IDs, so here is how you do it:</p>
<pre class="brush: jscript; title: ; notranslate">
'grid':{
    edit:this.onCellEdit
}
</pre>
<p>Notice that we used the xtype only so that the edit applies to both grids. Now you have to set up your onCellEdit function to handle the different columns that the user may edit, the code is below.</p>
<pre class="brush: jscript; title: ; notranslate">
onSomeGridEdit: function( editor, e ){
   if(e.originalValue != e.value){
       switch(e.field){
            case 'col_header_one':
                  //do something            
            break;
            case 'col_header_two':
                 //do something   
            break;
        }
    }
}
</pre>
<p>Finally, I had a few cells that actually popped up a window and I needed to know the ID of the grid so I could *gasp* use Ext.getCmp(), ( admit it this is why you think this feature is broke :-) )to do this I just used:</p>
<pre class="brush: jscript; title: ; notranslate">
this.up(‘grid’).getId();
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/10/17/gridpanel-editor-not-firing-when-using-locked-columns-in-extjs4/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dynamically changing the model and store in extjs4 based on dynamic column headers</title>
		<link>http://www.learnsomethings.com/2012/10/05/dynamically-changing-the-model-and-store-in-extjs4-based-on-dynamic-column-headers/</link>
		<comments>http://www.learnsomethings.com/2012/10/05/dynamically-changing-the-model-and-store-in-extjs4-based-on-dynamic-column-headers/#comments</comments>
		<pubDate>Fri, 05 Oct 2012 21:21:56 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[ExtJs Stuff]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[extjs4]]></category>
		<category><![CDATA[sencha]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2588</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
Modern day relational databases are able to perform some interesting feats like creating pivot tables with dynamic columns. I bet if you think about it for a minute you can figure out a million uses for data rolled up in &#8230; <a href="http://www.learnsomethings.com/2012/10/05/dynamically-changing-the-model-and-store-in-extjs4-based-on-dynamic-column-headers/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>Modern day relational databases are able to perform some interesting feats like creating pivot tables with dynamic columns. I bet if you think about it for a minute you can figure out a million uses for data rolled up in a pivot table, so chances are you will be asked to present data from your database in this format sooner or later. The first question that comes to mind when you dynamically send columns back to the client side browser is, &#8216;Wow, how do I tell my model, and grid to adapt without knowing what is coming?&#8217;.  The following approach takes the MVC approach to coding a fully dynamic grid and model. I must admit I was really surprised by how easy Ext handles this series of complex actions, so here we go:</p>
<p>Create a model that has a fields property that is blank like this:</p>
<pre class="brush: jscript; title: ; notranslate">
Ext.define('wcf.model.DataModel, {
extend: 'Ext.data.Model',
fields: []
});
</pre>
<p>Next create a store with the url that points to your server side script that will return the data. The important part to remember here is that autoLoad should be set to false, as we will be loading this store using an Ajax request later opposed to the usual store.load(). The other thing that is different here is that the sorters are critical in the store if you want to sort by some known column in your dataset like sales region as most database pivot functions will not allow an order by statement.</p>
<pre class="brush: jscript; title: ; notranslate">
Ext.define('wcf.store. DataStore, {
    extend      : 'Ext.data.Store',
    model       : 'wcf.model. DataModel,
    sorters: [{
        property: ' sales_region,
        direction: 'ASC'
    }],
        proxy: {
        type: 'ajax',
        url: '/resources/cfms/data.cfm?event=sales_report',
        reader: {
            type: 'json',
            root: 'data'
        }
    },
    autoLoad: false
});
</pre>
<p>Next you have to create the json on your back end to comply with the following format (or you have to go out and do multiple data calls, but really what&#8217;s the point in that since one call would yield all of the information you need).</p>
<p>Pass the columns in an array in the Json making sure to provide the correct data index and header text, plus anything else you would like to add.</p>
<pre class="brush: jscript; title: ; notranslate">
 'columns':[ {'dataIndex': 'something', 'text' : ' something' } ….. ]
 </pre>
<p>Pass the model in an array in the same Json object</p>
<pre class="brush: jscript; title: ; notranslate">
'fields':[{'name': 'something' } …. ]
</pre>
<p>Make sure you pass the data</p>
<pre class="brush: jscript; title: ; notranslate">
  'data':[ {'something': 'else'}, …..]
 </pre>
<p>Now that you have done all the hard work on the back end it&#8217;s time to connect your grid to the store and update the columns, model, and data.</p>
<pre class="brush: jscript; title: ; notranslate">
var      store       = Ext.getStore('DataStore'),
      // automatic getter when using MVC, otherwise reference the
     // dynamic grid.
            grid        = this.getDataGrid();

        Ext.Ajax.request({
            url     : '/resources/cfms/data.cfm?event=sales_report',
            success: function(response){
                var data = Ext.decode(response.responseText);
                store.model.setFields(data.fields);
                grid.reconfigure(store, data.columns);
                store.loadRawData(data.data, false);
            },
            failure: function(response){
	console.log(response);
            }
        });
</pre>
<p>Notice here we set the model fields with the data that was in the json response using exts store.model.setFields() method (<a href="http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Model-static-method-setFields" target="_blank">http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Model-static-method-setFields</a>). Next we reconfigured the grid with the columns from the json response using the reconfigure method of the grid and passing the store with the columns <a href="http://docs.sencha.com/ext-js/4-1/#!/api/Ext.grid.Panel-method-reconfigure" target="_blank">http://docs.sencha.com/ext-js/4-1/#!/api/Ext.grid.Panel-method-reconfigure</a>. Finally, we don&#8217;t want to call our query again so let&#8217;s populate the data using the store.loadRawdata() method and indicating false to make sure we remove the existing records <a href="http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Store-method-loadRawData" target="_blank">http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Store-method-loadRawData</a>.</p>
<p>Since the data does not load by itself using autoload I put the following in a function that is called on the grid&#8217;s activate event, but that is up to you, you may want to load it earlier rather than later.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/10/05/dynamically-changing-the-model-and-store-in-extjs4-based-on-dynamic-column-headers/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Hidden Overhead &#8211; how small things really add up</title>
		<link>http://www.learnsomethings.com/2012/09/27/hidden-overhead-how-small-things-really-add-up/</link>
		<comments>http://www.learnsomethings.com/2012/09/27/hidden-overhead-how-small-things-really-add-up/#comments</comments>
		<pubDate>Fri, 28 Sep 2012 02:48:44 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[Not taught in business school]]></category>
		<category><![CDATA[Random Stories]]></category>
		<category><![CDATA[business]]></category>
		<category><![CDATA[insight]]></category>
		<category><![CDATA[management]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2582</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
If you have ever spent some time in the corporate world you may have heard of the word &#8216;overhead&#8217;, and it is generally used to refer to the costs associated with the &#8216;headquarters&#8217; staff in a large organization. See, you &#8230; <a href="http://www.learnsomethings.com/2012/09/27/hidden-overhead-how-small-things-really-add-up/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>If you have ever spent some time in the corporate world you may have heard of the word &#8216;overhead&#8217;, and it is generally used to refer to the costs associated with the &#8216;headquarters&#8217; staff in a large organization. See, you may be the worker on the front lines at the clients&#8217; site, but your hourly rate goes towards your pay, the overhead, and profits for the company. Obviously, the greater the overhead expense the less flexible the company can be in setting rates and still making a decent profit. Now let&#8217;s take the concept of overhead to the network world, the two main transport protocols in use in the web are UDP and TCP/IP, one of them comes with more overhead as far as packet size is concerned. So what, why does this matter, it’s just a small bit of data right?</p>
<p><strong>Consider this: What&#8217;s a stamp worth? </strong></p>
<p>Let&#8217;s illustrate the fact that small inefficiencies can lead to a large cost to an organization given the frequency of the inefficient action.  Imagine you are in charge of the post office and you need to identify cost savings.</p>
<p>Using the facts below you devise a plan that eliminates an inefficiency that exists with stamps.</p>
<ul>
<li>1 Pound &#8211; 453.592 grams</li>
<li>Mail pieces processed in 2010 – 171,000,000,000 [1]</li>
<li>Assume every piece of mail (packet) requires one stamp</li>
<li>Stamps are printed on paper that weighs 56 g/m(sq) [2]</li>
<li>Current stamps have the following dimensions 22.10 x 24.89 mm [3]</li>
<li>Assume that we are using first class letters which cost $0.45 cent for the first ounce and $0.20 for each additional ounce. The post office works like airport parking garage, they charge for the full ounce (even if you’re over by .20 grams!).</li>
</ul>
<p>Now we all know that weight affects postage prices[4], I mean why else would we have those cool airmail envelopes and sheets of paper with the little striped edges, right.</p>
<p>First let’s translate the paper weight so that we have the grams per square millimeter, since we are dealing with the metric system we know that 1m² = 1,000,000 mm², next we divide the weight by the square millimeters to get a weight per millimeter. 453.592 / 1000000 = 0.000453592 grams / sq mm.</p>
<p>The postage stamp is 22.10 x 24.89mm so the area is 550.069 sq mm. The weight per postage stamp is 0.249506897848 grams.</p>
<p>Now we can calculate the straight cost of the stamp in weight added to the letter, we know that 0.249506897848 =  0.0088010968208481997 ounces and that it costs $0.20 cents per ounce, so it costs $0.00044005484 cent to mail the stamp on your letter. Barely noticeable, right? Now let’s multiply that by 171 billion ( 171,000,000,000 ), which is the yearly mail volume; the result, we would be paying $75,249,377.64 just to cover the weight of the stamps on the envelopes. If it was this simple we could use triangular stamps and save 37million dollars!</p>
<p>That’s great but we know that the post office rounds up to the nearest ounce and slaps a $0.20 cent charge on those that go over. Lets test the assumption on varying percentages of letters that could theoretically be put over the ounce limit by the weight of a stamp.</p>
<p>1% of letters are over = 1,710,000,000 * .20 = $342,000,000</p>
<p>This brings me to the last point: <em><strong>quantifiable things matter</strong></em>. You may disagree and many do, however, when you start presenting solutions to problems in the work world there is only one measure that really matters and it comes down to quantifiable outcomes.</p>
<p>To ensure your idea makes it you have to translate these outcomes into dollars, especially when dealing with network speeds, and security issues. Why? For far too long the IT department has sat back and used the &#8216;security&#8217; argument, which seems to work without any thought to cost (be it in time or money, and more often both) . Your challenge is to sit down and translate your IT related issues into dollars and cents, and come up with quantifiable savings. Remember you can save money by saving time, which is what automation strives to accomplish.</p>
<p><em><strong>Sources</strong></em></p>
<p>[1] <a href="http://pe.usps.com/businessmail101/rates/weight.htm">http://pe.usps.com/businessmail101/rates/weight.htm</a></p>
<p>[2] <a href="http://www.google.com/patents/US5503436?dq=us+post+office+adhesive+stamps&amp;hl=en&amp;sa=X&amp;ei=_AliUKy-GZKo9gSRrYHgCA&amp;ved=0CDoQ6AEwAw">http://www.google.com/patents/US5503436?dq=us+post+office+adhesive+stamps&amp;hl=en&amp;sa=X&amp;ei=_AliUKy-GZKo9gSRrYHgCA&amp;ved=0CDoQ6AEwAw</a></p>
<p>[3] <a href="http://about.usps.com/postal-bulletin/2012/pb22330/html/info_006.htm">http://about.usps.com/postal-bulletin/2012/pb22330/html/info_006.htm</a></p>
<p>[4] <a href="http://pe.usps.com/businessmail101/rates/weight.htm">http://pe.usps.com/businessmail101/rates/weight.htm</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/09/27/hidden-overhead-how-small-things-really-add-up/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Defaulting the extjs 4.1 combobox to the first item in the list</title>
		<link>http://www.learnsomethings.com/2012/09/25/defaulting-the-extjs-4-1-combobox-to-the-first-item-in-the-list/</link>
		<comments>http://www.learnsomethings.com/2012/09/25/defaulting-the-extjs-4-1-combobox-to-the-first-item-in-the-list/#comments</comments>
		<pubDate>Wed, 26 Sep 2012 01:12:46 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[ExtJs Stuff]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[extjs4]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2575</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
There have been some very small changes in extjs 4.1 that affect the inner working of the combobox, and actually make it a bit easier to select the first record in the store as the default item in the list &#8230; <a href="http://www.learnsomethings.com/2012/09/25/defaulting-the-extjs-4-1-combobox-to-the-first-item-in-the-list/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>There have been some very small changes in extjs 4.1 that affect the inner working of the combobox, and actually make it a bit easier to select the first record in the store as the default item in the list instead of just a blank space in the dropdown. (run-on sentences are ok as long as you don&#8217;t confuse affect and effect, right?)</p>
<p>To accomplish this task in extjs 4.1 just add the following listener to your combobox:</p>
<pre class="brush: jscript; title: ; notranslate">
listeners: {
  boxready: function(){
     this.setValue(this.getStore().getAt(0).get(this.valueField),true);
  // fire the select event ( Event in extjs )
  this.fireEvent('select',this);
  }
},
</pre>
<p>The &#8216;boxready&#8217; event (<a href="http://docs.sencha.com/ext-js/4-1/#!/api/Ext.AbstractComponent-event-boxready" target="_blank">http://docs.sencha.com/ext-js/4-1/#!/api/Ext.AbstractComponent-event-boxready</a>) gets fired once after the component has been laid out for the first time at its initial size. The reason you would use this opposed to beforeshow or render is due to the fact that the combobox will not have a hook into the store until the boxready event is fired if it is initially hidden (say on a second tab, or in a popup window …), and you will get a undefined error running the third line of the code. You will also run into issues if you don&#8217;t auto load the store.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/09/25/defaulting-the-extjs-4-1-combobox-to-the-first-item-in-the-list/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>A discussion on network cables, throughput and security</title>
		<link>http://www.learnsomethings.com/2012/09/16/a-discussion-on-network-cables-throughput-and-security/</link>
		<comments>http://www.learnsomethings.com/2012/09/16/a-discussion-on-network-cables-throughput-and-security/#comments</comments>
		<pubDate>Sun, 16 Sep 2012 22:24:27 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[Random Stories]]></category>
		<category><![CDATA[lan design]]></category>
		<category><![CDATA[networking]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2562</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
If that title doesn&#8217;t get you motivated to read this article nothing will! I&#8217;ve been teaching a course in LAN design and it is really theoretical so the things that you need to know always figure that the best case scenario is &#8230; <a href="http://www.learnsomethings.com/2012/09/16/a-discussion-on-network-cables-throughput-and-security/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>If that title doesn&#8217;t get you motivated to read this article nothing will! I&#8217;ve been teaching a course in LAN design and it is really theoretical so the things that you need to know always figure that the best case scenario is what you&#8217;ll get. So here&#8217;s what you absolutely need to know about network cables.</p>
<p><strong>Types and speeds</strong> :</p>
<div class="wp-caption alignnone" style="width: 610px"><img title="Twisted Pair" src="http://www.networkcablinglosangeles.com/wp-content/themes/networkcablinglosangeles/images/unshielded_cable.jpg" alt="" width="600" height="364" /><p class="wp-caption-text">Twisted Pair Cable</p></div>
<p>First, there&#8217;s <em><strong>twisted pair copper wire, </strong></em>chances are this is the stuff that connects your computer to the web (unless your&#8217;e browsing this from work on a high speed network). Twisted pair takes it&#8217;s name from the pattern that the wires have with two wires being twisted around each other to reduce electrical interference from nearby wires. The speeds that can be achieved range from 10Mbps to 10Gbps. This is what you probably refer to as &#8216;network cable&#8217;.</p>
<div class="wp-caption alignleft" style="width: 240px"><img title="Concentric Cable" src="http://www.otds.co.uk/electrical-equipment/cables/concentric-cable.jpg" alt="" width="230" height="455" /><p class="wp-caption-text">Concentric Cable (Coaxial)</p></div>
<p>Next, there is <strong><em>coaxial cable</em></strong>, which is also made of copper wire , however, the wires run concentric ( see the image to the left ). This cable is usually used to bring you television via your cable provider, and if you get internet from them then guess what, this is your cable. One thing that always surprises people is that when you use the cable company as your internet provider you &#8216;share&#8217; the bandwidth with your neighbors. This means that speeds may vary depending on the number of people that are online. Your cable modem that cost you a good deal more than say a regular router actually has to change tour digital signal from the computer into an analog signal to be sent over the shared connection. Speeds with this type of cable are in the tens of Mbps.</p>
<p>Finally we get to <em><strong>fiber optic cables</strong></em>, this is the new kid on the block, as copper wire dates back to the telegraph. These cables are small glass tubes where pulses of light are sent so as you can imagine speeds are very very fast. The speed of light is 3.00 x 10^8 m/s. Let&#8217;s put that into perspective, you could travel from New York to Los Angeles (2462 miles) about 75 times in one second (186,000 miles an hour). Of course your data won&#8217;t seem like it travels quite as fast but that is due to the various delays a packet encounters on the road to NY or LA depending on where you are at.</p>
<div class="wp-caption alignnone" style="width: 450px"><img title="Fiber Optic Cable" src="http://www.abc.net.au/news/image/351328-3x2-940x627.jpg" alt="" width="440" height="293" /><p class="wp-caption-text">Fiber Optic Cable</p></div>
<p><strong>Now that we got the three main types of wire down consider this &#8230; </strong></p>
<p>So designing a network is like building a nascar car right? It&#8217;s all about speed, and being lightweight helps a lot in that area right. A lot of emphasis is placed on the speed of fibre optic cable but let’s not overlook the security benefits of fiber optic cable opposed to cat5 and wireless communication methods.</p>
<p>There are a few things that can happen between the endpoints on a network that could compromise your data. These include:</p>
<p><em><strong>Tapping</strong></em> - We have all seen those old spy films where someone climbs a telephone pole and taps into the phone wires to listen in on conversations, and we have seen the films where the someone is listening in on radios to intercept messages.</p>
<p>Well, since fibre optic cable is comprised of a bundle of glass tubes, now imagine how hard it is to tap into those tubes without breaking the connection or causing loss that is noticeable.</p>
<p>I dug up this article in the Washington Post that illustrates this with a few interesting stories regarding cables that have been cut during the construction around Tyson’s Corner.</p>
<p><a href="http://www.washingtonpost.com/wp-dyn/content/article/2009/05/30/AR2009053002114_2.html?sid=ST2009053100019">http://www.washingtonpost.com/wp-dyn/content/article/2009/05/30/AR2009053002114_2.html?sid=ST2009053100019</a></p>
<p><strong><em>Radiation - </em></strong><em></em>You lose data due to interference from electromagnetic radiation, and the amount of resilience you have to this issue is based on your cable choice, fibre optic being the best and twisted pair being the worst.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/09/16/a-discussion-on-network-cables-throughput-and-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone does it again &#8211; Find my iPhone sends police directly to a robbery in progress</title>
		<link>http://www.learnsomethings.com/2012/08/16/iphone-does-it-again-find-my-iphone-sends-police-directly-to-a-robbery-in-progress/</link>
		<comments>http://www.learnsomethings.com/2012/08/16/iphone-does-it-again-find-my-iphone-sends-police-directly-to-a-robbery-in-progress/#comments</comments>
		<pubDate>Thu, 16 Aug 2012 20:21:05 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[Random Stories]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[news]]></category>
		<category><![CDATA[tech news]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2555</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
It&#8217;s a well known fact to the tech community or maybe the apple community that the devices can be located, locked, or even wiped clean from anywhere by using Apple&#8217;s Find My iPhone feature. This feature extends to the iPad &#8230; <a href="http://www.learnsomethings.com/2012/08/16/iphone-does-it-again-find-my-iphone-sends-police-directly-to-a-robbery-in-progress/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>It&#8217;s a well known fact to the tech community or maybe the apple community that the devices can be located, locked, or even wiped clean from anywhere by using Apple&#8217;s Find My iPhone feature. This feature extends to the iPad and now with the mountain lion release your desktop as well if you configure it correctly. However, this seems to be a feature that some criminals are in the dark about, for the second in as many weeks police in Maryland have located a stolen iPhone using this service. The first, of course is the case of the New York Times reporter David Pogue&#8217;s stolen phone in the case made famous over the internet. In that case authorities found the phone ditched in a backyard in Prince George&#8217;s county. The second case happened in Frederick, Maryland where a phone that was stolen from a vehicle parked outside the common market led police to the MARC train commuter parking lot behind the local Target where police found a running car with the door open and the suspect ducking behind two other cars in the lot. Turns out that the iPhone was not the only thing stolen, so was the car, another purse in the car that was stolen from the commuter lot, a GPS, and perhaps the cocaine that the suspect was carrying. Read more about both cases by clicking these links to the <a href=" http://www.washingtonpost.com/local/new-york-times-technology-columnist-gets-iphone-back-with-help-of-maryland-police-department/2012/08/03/ddaa3982-dd78-11e1-8ad1-909913931f71_story.html" target="_blank">Washington Post</a> and <a href="http://www.fredericknewspost.com/sections/news/display.htm?storyID=139422#.UC1VK2HY-Sp." target="_blank">Frederick News Post</a> articles.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/08/16/iphone-does-it-again-find-my-iphone-sends-police-directly-to-a-robbery-in-progress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Extjs 4.1 UX that will allow multiple remote sorting on columns, and display multiple directional icons</title>
		<link>http://www.learnsomethings.com/2012/08/15/extjs-4-1-ux-that-will-allow-multiple-remote-sorting-on-columns-and-display-multiple-directional-icons/</link>
		<comments>http://www.learnsomethings.com/2012/08/15/extjs-4-1-ux-that-will-allow-multiple-remote-sorting-on-columns-and-display-multiple-directional-icons/#comments</comments>
		<pubDate>Wed, 15 Aug 2012 16:20:06 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[ExtJs Stuff]]></category>
		<category><![CDATA[EXT]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[extjs4]]></category>
		<category><![CDATA[extjs4 overrides and plugins]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[sencha]]></category>
		<category><![CDATA[UX]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2535</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
Why? Ok, so I have come across the need to perform multiple sorting on many occasions, and like most people got a little frustrated with the drag and drop toolbar method that is given in the Extjs examples. I wanted &#8230; <a href="http://www.learnsomethings.com/2012/08/15/extjs-4-1-ux-that-will-allow-multiple-remote-sorting-on-columns-and-display-multiple-directional-icons/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<h2>Why?</h2>
<p>Ok, so I have come across the need to perform multiple sorting on many occasions, and like most people got a little frustrated with the drag and drop toolbar method that is given in the Extjs examples. I wanted something that the user would intuitively understand since they were used to clicking rows to perform sorting anyway, and I wanted them to see what was being sorted in the same manner that the native sort works. You know that small blue triangle in your column header. It became apparent that this would be a feature that could be used over and over again as this is a really common request so I put together this UX for your Extjs 4.1 grids. I did not do any testing on versions prior to 4.1, so maybe it will work for those, maybe not, consider that fair warning.</p>
<h2>Where to get the InlineRemoteMultiSort UX</h2>
<p><a href="https://github.com/jmcdonald69124/extjs-multisort-ux" target="_blank">https://github.com/jmcdonald69124/extjs-multisort-ux</a></p>
<h2>How to use the InlineRemoteMultiSort UX</h2>
<p>In your javascript code please make sure you place the files in the following folder, where extjs could be the root of your extjs distribution:</p>
<p>extjs/src/ux/ folder, and place the CSS file in the extjs/src/ux/css folder.</p>
<p>In your grid add the plugin, and pass it the initial &#8216;default&#8217; sort values.</p>
<pre class="brush: jscript; title: ; notranslate">
plugins : [
Ext.create('Ext.ux.InlineRemoteMultiSort', {
 defaultSorters: [
 {property:'col1',   direction:'ASC'},
 {property:'col2',   direction:'ASC'},
 {property:'col3',   direction:'ASC'}
    // ....
 ]
})
]
</pre>
<p>Of course this assumes that you set your path to the ux folder correctly in your MVC app.js file.</p>
<p>On the server watch out for the following values that are passed in a parameter called &#8216;sort&#8217;:</p>
<pre class="brush: jscript; title: ; notranslate">
sort:[
{'item':'col1','direction':'ASC'},
{'item':'col2','direction':'ASC'},
{'item':'col3','direction':'ASC'}
]
</pre>
<p>If you are using Cold Fusion for your back end code you can parse the incoming form value with this code:</p>
<pre class="brush: xml; title: ; notranslate">
&lt;cfset sorters = deserializeJSON(#form.sort#) /&gt;
</pre>
<h2>Watch out for the following</h2>
<p>This code will pass a set of brackets [ ] if there are no sorters, please handle this on the server side. </p>
<p><strong>Paging</strong> poses a set of issues that will require that the query return the rows that are needed by the page the user is viewing. If you intend to use paging please see this post and pay particular attention to how it uses the start and page number<br />
<a href="http://www.learnsomethings.com/2011/11/06/php-code-for-paging-and-remote-filtering-extjs4-grids/">http://www.learnsomethings.com/2011/11/06/php-code-for-paging-and-remote-filtering-extjs4-grids/</a> . </p>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/08/15/extjs-4-1-ux-that-will-allow-multiple-remote-sorting-on-columns-and-display-multiple-directional-icons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding store events to your controller in Extjs 4.1</title>
		<link>http://www.learnsomethings.com/2012/07/26/adding-store-events-to-your-controller-in-extjs-4-1/</link>
		<comments>http://www.learnsomethings.com/2012/07/26/adding-store-events-to-your-controller-in-extjs-4-1/#comments</comments>
		<pubDate>Fri, 27 Jul 2012 01:40:02 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[ExtJs Stuff]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[extjs4]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[mvc architecture]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2526</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
Ok so you set out to code your new extjs app using MVC and now you want to do something like add a &#8216;datachanged&#8217; or &#8216;load&#8217; event to your store. This is common stuff right, you know exception handlers, so &#8230; <a href="http://www.learnsomethings.com/2012/07/26/adding-store-events-to-your-controller-in-extjs-4-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>Ok so you set out to code your new extjs app using MVC and now you want to do something like add a &#8216;datachanged&#8217; or &#8216;load&#8217; event to your store. This is common stuff right, you know exception handlers, so you open up Google or stack overflow and start searching, but what you get is a whole lot of differing opinion on how to accomplish this trivial task. There are a few things that you already know; they are your ground rules so to say. Come hell or high water you will not add listeners to your store, you want all of the methods (or actions) to go in the controller.  So what are you to do?</p>
<p>First let&#8217;s look at our sample store:</p>
<pre class="brush: jscript; title: ; notranslate">
Ext.define('sample.store.MainStore', {
    extend      : 'Ext.data.Store',
    model       : 'sample.model.MainStore',
    pageSize    : 100,
    remoteSort  : true,
    proxy: {
        type: 'ajax',
        extraParams: {
            start        : 0,
            limit        : 100
        },
        url: 'someurl.php',
        method: 'POST',
        reader: {
            type: 'json',
            root: 'data',
            totalProperty:'results'
        }
    },
    autoLoad: true
});
</pre>
<p>… and every store has a model, right …</p>
<pre class="brush: jscript; title: ; notranslate">
Ext.define('sample.model.MainStore', {
    extend: 'Ext.data.Model',
    fields: [
        'some_primary_key',
        'some_data_element',
    ]
});
</pre>
<p>Now for the Pièce de résistance – our controller:</p>
<pre class="brush: jscript; title: ; notranslate">
Ext.define('sample.controller.Main', {
    extend     :  'Ext.app.Controller',
    models    :  ['MainStore'],
    stores      :  [' MainStore '],
    views       :  ['Main'],
    requires  :  ['Ext.MessageBox'],
    init: function() {

        Ext.getStore('MainStore').addListener('load',
this.onMainStoreLoad,
 this);
        Ext.getStore('MainStore').addListener('datachanged',
this. onMainStoreDataChange,
 this);

        this.control({
               //  A sample combo box select function
            'combo[action=sampleSelect]':{
                select:this.onComboSelect
            },
	//  A sample button click function
            'button[action=sampleAction]':{
                click:this.onButtonClick
            }
        });
    },

// This is where all the functions go

    onComboSelect: function(combo) {
        	console.log('ComboBox Selected, the value is:' + combo.getValue()) ;
    },

    onButtonClick: function(me){
console.log('Button Clicked');
    },

    onMainStoreLoad: function(me,records,success){
if(!success){
     Ext.MessageBox.show({
        title   : 'Data Load Error',
        msg   : 'The data encountered a load error, please try again in a few minutes.'
                });
            }
    },

    onMainStoreDataChange: function(me){
console.log('Hey the store data just changed!');
    }

});
</pre>
<p>In closing there are a few things that I learned in this exercise that I would like to point out so you don&#8217;t repeat my mistakes.</p>
<ol>
<li>When you look at the API for the store, and you take one of the events (load for example is here <a href="http://docs.sencha.com/ext-js/4-1/">http://docs.sencha.com/ext-js/4-1/#!/api/Ext.data.Store-event-load</a> ) you can pass the parameters in the function in the controller.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/07/26/adding-store-events-to-your-controller-in-extjs-4-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lies, damn lies, and JavaScript statistics!</title>
		<link>http://www.learnsomethings.com/2012/07/23/lies-damn-lies-and-javascript-statistics/</link>
		<comments>http://www.learnsomethings.com/2012/07/23/lies-damn-lies-and-javascript-statistics/#comments</comments>
		<pubDate>Tue, 24 Jul 2012 02:48:02 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[ExtJs Stuff]]></category>
		<category><![CDATA[EXT]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[extjs4]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[sencha]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2519</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
Ok I have been doing some statistical analysis of values in arrays lately (because it&#8217;s fun!) and wanted to pass on some of the more popular equations, along with what they mean, or what they mean to tell you. Mean &#8230; <a href="http://www.learnsomethings.com/2012/07/23/lies-damn-lies-and-javascript-statistics/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>Ok I have been doing some statistical analysis of values in arrays lately (<strong><em>because it&#8217;s fun!)</em></strong> and wanted to pass on some of the more popular equations, along with what they mean, or what they mean to tell you.</p>
<p><strong>Mean</strong> – Many of you no doubt know the mean as the average of a set of numbers, you calculate this by summing the values in the data set and dividing the sum by the number of values. This seems straight forward, and the concepts below rely on the mean so it is crucial that this be calculated. Ext.Array (<a href="http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Array-method-mean" target="_blank">http://docs.sencha.com/ext-js/4-1/#!/api/Ext.Array-method-mean</a>) has a handy way of calculating the mean value of a dataset stored in what else – an array.</p>
<p>In the world of probability the mean is also known as the expected value, and provides a good idea of where the next value will fall.</p>
<p><strong>Variance</strong> – Now that you have the mean value of the array, you can start to look for the variance in your dataset. The variance is the measure of how far the numbers in your dataset are spread out. The baseline for this is the mean, which is also known as the expected value! Variance is calculated by taking the mean and subtracting that number from the value, then squaring the difference (between the mean and the value) for each of the numbers in your dataset. Wait! You are only half way there! Once you complete that task you should have a new dataset comprise of squared differences, now to get the variance just calculate the mean of the dataset of squared differences.</p>
<p><strong>Standard Deviation</strong> – OK, now that we have worked out the mean, and the variance, what is standard deviation, and what do we plan to do with it. Before I explain, let&#8217;s take a look at the chart below:</p>
<p><a href="http://www.learnsomethings.com/wp-content/uploads/2012/07/Screen-Shot-2012-07-23-at-10.31.27-PM.png"><img class="aligncenter size-full wp-image-2520" title="Screen Shot 2012-07-23 at 10.31.27 PM" src="http://www.learnsomethings.com/wp-content/uploads/2012/07/Screen-Shot-2012-07-23-at-10.31.27-PM.png" alt="" width="605" height="280" /></a></p>
<p>In this chart you see the greek symbols for mean (μ)  and standard deviation (σ) . The type of curve represented by the chart above is named the bell curve. So you may be asking yourself what standard deviation is right &#8212; well, it is the square root of the variance and shows how spread out a set of numbers is. In the bell curve you can see that 34.1% of the dataset falls within -1 standard deviation and 34.1% falls within +1 standard deviation of the mean. This dataset can be categorized as normalized.</p>
<p><strong>Frequency</strong> – Now let&#8217;s talk about frequency, which is commonly expressed as a histogram, or a chart that contains &#8216;bins&#8217; and the number of items per &#8216;bin&#8217;.</p>
<p>Now, how do you go about calculating the values above given a set of values in a JavaScript array?</p>
<p>Luckily, I stumbled across some handy JavaScript snippets from Larry Battle (<a href="http://bateru.com/news/2011/03/javascript-standard-deviation-variance-average-functions/" target="_blank">http://bateru.com/news/2011/03/javascript-standard-deviation-variance-average-functions/</a> ), and of course when you couple that with some extjs Array singleton functions you get an easy to use list of stats functions.</p>
<p><strong>Average (mean)</strong></p>
<pre class="brush: jscript; title: ; notranslate">
var avg = Ext.mean(yourArray);
</pre>
<p><strong>Variance</strong></p>
<pre class="brush: jscript; title: ; notranslate">
// Function returns variance for an array of numbers
function  variance(arr){
	// Make sure that your input is of type array
if (!Ext.isArray(arr)) {
return false;
}
	var avg = Ext.mean(arr);
	i = arr.length,
	v = 0;

	while (i--){
		v+= Math.pow((arr[i] – avg), 2 );
	}
	V /= arr.length;
	return (v);
}
</pre>
<p><strong>Standard Deviation</strong></p>
<pre class="brush: jscript; title: ; notranslate">
function stdev(arr){
	// Make sure that your input is of type array
if (!Ext.isArray(arr)) {
return false;
}
	var sd = Math.sqrt(variance(arr));
return sd;

}
</pre>
<p><strong>Frequency</strong></p>
<pre class="brush: jscript; title: ; notranslate">
function histogram(arrayOfNumbers){
var bins = 10,
histogramDataValues = arrayOfNumbers, // Source Values
i = 0,
over = 0,
under = 0,
binContent = [],       // Becomes the data array
delta;

var lowestNumber = Ext.Array.min(histogramDataValues),
highestNumber = Ext.Array.max(histogramDataValues),
delta = Math.abs((lowestNumber - highestNumber) / bins);

// Set the initial value of all bins to zero
// and populate the categories data based on the deltas

for (; i &lt;= bins; i++) {
binContent[i] = 0;
histogramDataValues[i] = lowestNumber + Math.round(100 * (i - 1) * delta) / 100;
}

// Populate the bins with the
for (i = 0; i &lt; histogramDataValues.length; i++) {

if (histogramDataValues[i] &lt; lowestNumber) {
under++;
}
else if (histogramDataValues[i] &gt;= highestNumber) {
over++;
}
else {
var ndata = histogramDataValues[i] - lowestNumber,
thisBin = Math.floor(ndata / delta);

thisBin = Math.abs(thisBin);
binContent[thisBin]++;
}
}
return binContent;
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/07/23/lies-damn-lies-and-javascript-statistics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Random thoughts on code errors after teaching two different languages in one semester</title>
		<link>http://www.learnsomethings.com/2012/07/13/random-thoughts-on-code-errors-after-teaching-two-different-languages-in-one-semester/</link>
		<comments>http://www.learnsomethings.com/2012/07/13/random-thoughts-on-code-errors-after-teaching-two-different-languages-in-one-semester/#comments</comments>
		<pubDate>Fri, 13 Jul 2012 23:54:02 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[Random acts of learning]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[developement methodologies]]></category>
		<category><![CDATA[insight]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[just the code]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2491</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
When I was a bit younger we used to play a game called Pitfall where you would guide your player across various obstacles, including chomping alligators, deadly quicksand, and rushing rivers. In programming there are also pitfalls, and they may &#8230; <a href="http://www.learnsomethings.com/2012/07/13/random-thoughts-on-code-errors-after-teaching-two-different-languages-in-one-semester/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>When I was a bit younger we used to play a game called Pitfall where you would guide your player across various obstacles, including chomping alligators, deadly quicksand, and rushing rivers. In programming there are also pitfalls, and they may not be as bad as an alligator pit, but they will consume your time and leave you drained at the end of the day. </p>
<p>Software errors will always happen, it comes down to how quickly you can identify them and correct them that make all the difference. Those that argue that code should be written error free the first time have obviously not written much code. We can all agree that production code should be error free, but to achieve error free code means you will have to identify and eliminate errors.</p>
<p>I wanted to share a few thoughts on how to cut down on errors in your code.</p>
<p><strong>Use proper indentation, and formatting. </strong>This is almost never taught in class, and most of the books that I have seen even contain code that runs and is compact but is not really easy to read.  It&#8217;s important to write all your code as if you are going to spend the rest of your career maintaining it.</p>
<p>This sounds great but how can I implement it? Let&#8217;s take a look at some code.</p>
<p>I like to use a tab for each block of code. Look at the difference between block a and block b.</p>
<p><strong>A</strong></p>
<pre class="brush: jscript; title: ; notranslate">
Ext.override(Ext.form.Radio, {
        setValue : function(v) {
            if (typeof v == 'boolean') {
                Ext.form.Radio.superclass.setValue.call(this, v);
            } else if (this.rendered) {
                var els = this.getCheckEl().select('input[name=' + this.el.dom.name + ']');
                els.each(function(el){
                    if (el.dom.value == v) {
                        Ext.getCmp(el.dom.id).setValue(true);
                    } else {
                        Ext.getCmp(el.dom.id).setValue(false);
                    }
                }, this);
            }
            return this;
        }
    });
</pre>
<p><strong>B</strong></p>
<pre class="brush: jscript; title: ; notranslate">
Ext.override(Ext.form.Radio, { setValue : function(v) {
if (typeof v == 'boolean') {
Ext.form.Radio.superclass.setValue.call(this, v);
} else if (this.rendered) {
var els = this.getCheckEl().select('input[name=' + this.el.dom.name + ']');
els.each(function(el){
if (el.dom.value == v) {Ext.getCmp(el.dom.id).setValue(true);
 } else {Ext.getCmp(el.dom.id).setValue(false);
}}, this);}
return this;
} });
</pre>
<p>Hard to believe that&#8217;s the same code right? Now imagine this throughout a file containing a thousand, ten thousand, hundreds of thousands of lines of code.</p>
<p><strong>Use curly braces even when you don&#8217;t have to.</strong> Wait won&#8217;t that bloat my code? I&#8217;ve been taught that I should keep things as compact as possible what&#8217;s up with this. Let me explain in code:</p>
<p><strong>A</strong></p>
<pre class="brush: java; title: ; notranslate">
if (condition1)
{
    if (condition2)
    {
        statement1;
    } else {
        statement2;
    }
}
</pre>
<p><strong>B</strong></p>
<pre class="brush: java; title: ; notranslate">
if (condition1)
if (condition2)
statement1;
else statement2;
</pre>
<p>To the compiler, both pieces of code above will achieve the same result; however, the top block is far easier to read for us humans. Which code would you like to maintain.</p>
<p><strong>Don&#8217;t use variable names that have no meaning – remember comments in the code should not be used to explain what your variables are, let their names tell all.</strong> This rule needs no code explanation, just stay away from one letter variables like a, b, or c and try to spell them out like</p>
<p><strong>A</strong></p>
<pre class="brush: java; title: ; notranslate">
        double    a;
        double    b;
a = (b - 32) * 0.555555556
</pre>
<p>&nbsp;</p>
<p><strong>B</strong></p>
<p>&nbsp;</p>
<pre class="brush: java; title: ; notranslate">
        double    celsius;
        double    fahrenheit;
celsius = (fahrenheit - 32) * 0.555555556
</pre>
<p>Bet you didn&#8217;t know that example A did until you got a look at B, right.</p>
<p><strong>Test often and test early.</strong> How many lines do you write before you stop and see if what you have compiles. Do you write test cases for all your functions when you code them and actually test them before connecting them to the user interface? This helps you tackle bugs close to the source without wading through hundreds of lines of code.</p>
<p><strong>If your IDE does not have a nice auto save feature like Jet Brain&#8217;s WebStorm, then please remember to save early and save often. </strong>There is nothing more frustrating than losing hours of good code.</p>
<p><strong>Nobody ever wanted an app that ran slower, keep that in mind and optimize, optimize, optimize.</strong> You can use tools like Page Speed, or Chrome&#8217;s Developer Tools to get your JavaScript on track. In addition Google and Yahoo have written detailed articles that are essentially a lessons learned document</p>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/07/13/random-thoughts-on-code-errors-after-teaching-two-different-languages-in-one-semester/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Showing your SplitButton menu on the top level button press extjs4</title>
		<link>http://www.learnsomethings.com/2012/06/09/showing-your-splitbutton-menu-on-the-top-level-button-press-extjs4/</link>
		<comments>http://www.learnsomethings.com/2012/06/09/showing-your-splitbutton-menu-on-the-top-level-button-press-extjs4/#comments</comments>
		<pubDate>Sat, 09 Jun 2012 19:00:48 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[ExtJs Stuff]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[extjs4]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2484</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
I just finished updating an application that contained a lot of split buttons in the toolbar, which of course contained several menus where the user could select tasks. The problem is, when the original application was released I went with &#8230; <a href="http://www.learnsomethings.com/2012/06/09/showing-your-splitbutton-menu-on-the-top-level-button-press-extjs4/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>I just finished updating an application that contained a lot of split buttons in the toolbar, which of course contained several menus where the user could select tasks. The problem is, when the original application was released I went with the standard extjs splitbutton functionality, and my users were used to the standard menus that they find in other applications.</p>
<p>There&#8217;s a difference, and if you want to know what it is just hover over the menu buttons on the browser that you are using to read this.  Chances are all you have to do is click anywhere on the buttons to show the menu, right? We&#8217;ll now take a look at the extjs splitButton, what you get is a small arrow that user has to press which toggles the menu between visible / invisible.</p>
<p>Why not change your split buttons to give the same functionality that users are already used to, and stop testing their nerves by making the target so small the slightest shake will mean they cannot see the menu.  Fortunately you can include the following listener to add a show / hide action to the main button click.</p>
<pre class="brush: jscript; title: ; notranslate">

listeners:{

'click': function(me){

me.showMenu();

}

},

</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/06/09/showing-your-splitbutton-menu-on-the-top-level-button-press-extjs4/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>What happened getForm().getValues()  returns a dom error in extjs</title>
		<link>http://www.learnsomethings.com/2012/05/24/what-happened-getform-getvalues-returns-a-dom-error-in-extjs/</link>
		<comments>http://www.learnsomethings.com/2012/05/24/what-happened-getform-getvalues-returns-a-dom-error-in-extjs/#comments</comments>
		<pubDate>Thu, 24 May 2012 21:44:47 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[ExtJs Stuff]]></category>
		<category><![CDATA[ajax]]></category>
		<category><![CDATA[EXT]]></category>
		<category><![CDATA[extjs4]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[sencha]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2474</guid>
		<description><![CDATA[getForm().getValues()  returns a dom error in extjs <a href="http://www.learnsomethings.com/2012/05/24/what-happened-getform-getvalues-returns-a-dom-error-in-extjs/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p><strong>Background</strong>:</p>
<p>Ok let&#8217;s assume for a minute that you have a tab panel with four tabs each containing a form. You have placed this panel inside of a window, and the goal is to have one &#8216;save&#8217; button on the bottom of the window that will save all of the forms simultaneously so the user does not have to remember to save after changing data on a tab before moving to the next. This is a common and straight forward task, and I am sure that it comes up in the real world often; I&#8217;ve used this layout multiple times myself.</p>
<p><strong>The Problem</strong>:</p>
<p>You want to read the form values and consolidate them into one call to your backend database, however, then form elements in the tab panels behind the default panel have not been rendered to the dom, therefore, you cannot access them via getValues().<br />
You want to set the values in each form; however, you cannot set values for items that do not exist.</p>
<p><strong>The Solution</strong>:</p>
<p>The code below will construct a button that can be placed at the &#8216;Window&#8217; level and will try to get the values of all child forms contained in a tab panel inside the window.</p>
<pre class="brush: jscript; title: ; notranslate">
buttons:[
    {
    text    : 'Save',
    listeners : {
        click : function() {
            // The first form is always rendered!
            var first_form_values  = first_form.getForm().getValues(false),
                // This checks the form first to see if they have been rendered
                second_form_values = !second_form.rendered ? '' : second_form.getForm().getValues(false),
                third_form_values  = !third_form.rendered  ? '' : third_form.getForm().getValues(false),
                fourth_form_values = !fourth_form.rendered ? '' : fourth_form.getForm().getValues(false);

            Ext.Ajax.request({
                url:'your_url.php?' +
                    // You need urlEncode as getValues passes
                    // back an object!
                    '&amp;' + Ext.urlEncode(first_form_values)  +
                    '&amp;' + Ext.urlEncode(second_form_values) +
                    '&amp;' + Ext.urlEncode(third_form_values)  +
                    '&amp;' + Ext.urlEncode(fourth_form_values),
                method:'POST',
                success:function () {
                    msg('','Your changes have been saved successfully!');
                },
                failure:function () {
                    msg('uh-oh','Your changes have not been saved!');
                }
            });
        }}
    }
]
</pre>
<p>That&#8217;s all there is to sending your data values from multiple forms to the server in one ajax post, but what about getting values from the server and updating your forms that reside in the tab panel?</p>
<p>Luckily, when an element is in the tab panel you can add an &#8216;<a href="http://docs.sencha.com/ext-js/3-4/#!/api/Ext.Panel-event-activate" target="_blank">activate</a>&#8216; listener that is waiting for the tab and form to become visible, and the best part is it is fired every time you click on the tab, which would be useful as <a href="http://docs.sencha.com/ext-js/3-4/#!/api/Ext.Component-event-afterrender" target="_blank">afterrender</a> is called once, and that&#8217;s when the component is first rendered (as the name suggests ).<br />
The code below will load values to your form and must be placed at the formPanel element level.</p>
<pre class="brush: jscript; title: ; notranslate">
listeners   :{
                    'activate': function(e){
                        working_status_form.getForm().load({
                            url: '/getData.php',
                            failure: function(form, action) {
                                Ext.Msg.alert('uh-oh','Your data has not been loaded.');
                            }
                        });
                    }
                },
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/05/24/what-happened-getform-getvalues-returns-a-dom-error-in-extjs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handling user input at the source, an example using DUNS numbers and mod 10 check digits with extjs</title>
		<link>http://www.learnsomethings.com/2012/05/11/handling-user-input-at-the-source-an-example-using-duns-numbers-and-mod-10-check-digits-with-extjs/</link>
		<comments>http://www.learnsomethings.com/2012/05/11/handling-user-input-at-the-source-an-example-using-duns-numbers-and-mod-10-check-digits-with-extjs/#comments</comments>
		<pubDate>Fri, 11 May 2012 22:29:06 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[ExtJs Stuff]]></category>
		<category><![CDATA[business]]></category>
		<category><![CDATA[EXT]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[extjs4]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[sencha]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2467</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
Right now you must be thinking &#8220;what and the hell is a duns number?&#8221; or &#8220;I can&#8217;t believe my luck, I was looking for an easy way to verify duns numbers on the client side in my app!&#8221;. If you &#8230; <a href="http://www.learnsomethings.com/2012/05/11/handling-user-input-at-the-source-an-example-using-duns-numbers-and-mod-10-check-digits-with-extjs/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p> Right now you must be thinking &#8220;what and the hell is a duns number?&#8221; or &#8220;I can&#8217;t believe my luck, I was looking for an easy way to verify duns numbers on the client side in my app!&#8221;. If you are in the first camp, then let me elaborate.  The D-U-N-S number is a unique identifier used for keeping track of businesses, and a business is actually required to have one if they are to do work for the US Government, Australian Government, the United Nations, or the European Commission, so yes, you could say that it widely used. What&#8217;s really cool for UI developers about the D-U-N-S number is the fact that it is set up with a check digit and you can perform some calculations on the data entered in your apps D-U-N-S field to make sure that the entry is valid. I am sure I don&#8217;t have to tell you that eliminating bad data entry is critical to ensuring data integrity, and as with most things in life, it is often easier to take care of issues at the source of the problem before they grow, rather than spend time later trying to clean up the mess.</p>
<p>To set this check up in Extjs we will need to create a custom vType (<a href="http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.VTypes" target="_blank">http://docs.sencha.com/ext-js/4-1/#!/api/Ext.form.field.VTypes</a> ).  </p>
<p>The code is below.</p>
<pre class="brush: jscript; title: ; notranslate">

var dunsNbr     = /\d{2}-?\d{3}-?\d{4}/i;
   
// vtype for Duns Number including MOD 10 Check
    Ext.apply(Ext.form.field.VTypes, {
        //  vtype validation function
        duns: function(val, field) {
            if(dunsNbr.test(val) == true){
                return mod10CheckDigit(val);
            } else {
                return false;
            }
        },
        // vtype Text property: The error text 
        // to display when the validation 
        // function returns false
        
        dunsText: 'The D-U-N-S® number is always' +
            ' presented in a distinct format:' +
            ' two digits, hyphen, three digits,' +
            'hyphen, four digits. ' +
            'For example: 04-997-7473.',
        // vtype Mask property: The keystroke filter mask
        dunsMask: /[\d\-]/i
    }); 
</pre>
<p>In the code above note that duns is the vtype, and the dunsText will be displayed in a qTip when the user enters the wrong input. The dunsMask is used to filter out keystrokes that do not match the pattern provided. It is important to realize that the mask is not a regex value that matches the specific string that you would like to see in your duns field, but is actually regex that lists the allowed characters in the field. This is a key point!</p>
<p>Now, take a look at the line of code:
<pre class="brush: jscript; title: ; notranslate">if(dunsNbr.test(val) == true){ …}</pre>
<p>. This is the code that performs the regex check on the value that has been entered. dunsNbr is declared at the top of our vType. You can find more information about Ext&#8217;s regex features here (<a href="http://docs.sencha.com/ext-js/4-1/#!/api/RegExp" target="_blank">http://docs.sencha.com/ext-js/4-1/#!/api/RegExp</a>), but the points to remember are 1) you have to add a / before the regex statement and a /i at the end of the statement and 2) never try to plug your regex into the &#8216;Mask&#8217; property.</p>
<p>I find that it&#8217;s easier to test my regex code on a website like: <a href="http://www.zytrax.com/tech/web/regex.htm#experiment" target="_blank">http://www.zytrax.com/tech/web/regex.htm#experiment</a> before I put it in my javascript.</p>
<p>Now suppose you get through the check above, you will notice that the very next line reads:</p>
<pre class="brush: jscript; title: ; notranslate">
                return mod10CheckDigit(val);
</pre>
<p>In order to check the D-U-N-S number you would take the first 8 digits in the number. Next loop through the numbers and multiply the even numbers by 2. Now the numbers greater than 10 are separated and you write out the ones and tens place and add all of the numbers together. </p>
<p>D-U-N-S with check digit in the 9th place = 0 4 9 9 7 7 4 73</p>
<p>0 4 9 9 7 7 4 7<br />
x1 x2 x1 x2 x1 x2 x1 x2<br />
0+8+9+1+8+7+1+4+4+1+4 = 47</p>
<p>In this example above , the total is 47. Subtract this total, 47 from the next highest multiple of 10, (that is 50 in this case).</p>
<p>50 – 47 = 3</p>
<p>3 = check digit</p>
<p>The code below uses Modulus 10 + 5, meaning if the original check digit calculation is greater than a 4, then add  5 and then subtract 10 to determine the check digit.</p>
<p>That&#8217;s it! So with this quick tutorial you have seen how to apply a function and some serious calculations to an Extjs vType, how you can use regex, and what Mask is all about, and how you can ensure that data gets checked at the client side before hitting your database.</p>
<p>The function you need is below:</p>
<pre class="brush: jscript; title: ; notranslate">
 function mod10CheckDigit(value) {
        //Strip all characters except numbers
        var v   = value.replace(/[^0-9]+/g,''),
            cd  = v.substr(8,1),
            v   = v.substr(0, 8),
            total = 0,
            temp,
            tens,
            ones,
            modDigit;

        //Get Odd Numbers
        for (i=0; i &lt;= v.length-1; i=i+2) {
            total = total + parseInt(v.substr(i,1));
        }

        //Get Even Numbers
        for (i=1; i&lt;=v.length; i=i+2) {
            temp = parseInt(v.substr(i,1)) * 2;
            if (temp &gt; 9) {
                tens = Math.floor(temp/10);
                ones = temp - (tens*10);
                temp = tens + ones;
            }
            total = total + temp;
        }

        //Determine the checksum
        modDigit = (10 - total % 10) % 10;

        // Now if the original check digit calculation is greater than a 4, then add
        // 5 and then subtract 10 to determine the check digit

        if (modDigit &gt; 4){
            modDigit = ((parseInt(modDigit) + 5) - 10);
        } 

        // Duns Number Expansion OR original MOD 10 check
        if ( modDigit == cd){
            return true;
        } else {
          //  alert(modDigit + ' - ' + cd);
            Ext.Msg.alert('Invalid D-U-N-S® Number', 'The D-U-N-S® number you entered was in the correct format, however, did not pass the D-U-N-S® validation test. Please correct your input. ')
            return false;
        }
    }
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/05/11/handling-user-input-at-the-source-an-example-using-duns-numbers-and-mod-10-check-digits-with-extjs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stop the backspace key from going to the previous page in your extjs app</title>
		<link>http://www.learnsomethings.com/2012/05/04/stop-the-backspace-key-from-going-to-the-previous-page-in-your-extjs-app/</link>
		<comments>http://www.learnsomethings.com/2012/05/04/stop-the-backspace-key-from-going-to-the-previous-page-in-your-extjs-app/#comments</comments>
		<pubDate>Sat, 05 May 2012 01:07:48 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[ExtJs Stuff]]></category>
		<category><![CDATA[ex]]></category>
		<category><![CDATA[EXT]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[extjs4]]></category>
		<category><![CDATA[extjs4 overrides and plugins]]></category>
		<category><![CDATA[html 5]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[sencha]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2463</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
If you have an app with just one view and there is even a small possibility that the user will open the app in a browser that they have been using to cruise around the web and the user will &#8230; <a href="http://www.learnsomethings.com/2012/05/04/stop-the-backspace-key-from-going-to-the-previous-page-in-your-extjs-app/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>If you have an app with just one view and there is even a small possibility that the user will open the app in a browser that they have been using to cruise around the web and the user will likely use the backspace key in your app then you should think about turning off the backspace == url -1 feature in most browsers. </p>
<p>If you actually want to use the backspace button for its intended purpose and you would like to map ext events to the browser history then a good choice might be using Ext.History, which you can learn about in depth by reading Ed Spencer&#8217; blog post its use. (<a href="http://edspencer.net/2009/01/why-you-should-be-using-history-in-your.html" target="_blank">http://edspencer.net/2009/01/why-you-should-be-using-history-in-your.html</a> )</p>
<p>Turning off the backspace key is pretty straight forward.  You would just use Ext&#8217;s EventManager and create a listener to check for any keypress events that take place on the page. If the user is not in an input field then you would ignore the default action of the backspace button. Placing the code below right under your Ext.onReady …  method will do the trick.</p>
<pre class="brush: jscript; title: ; notranslate">
Ext.EventManager.addListener(Ext.getBody(), 'keydown', function(e){
        if(e.getTarget().type != 'text' &amp;&amp; e.getKey() == '8' ){
            e.preventDefault();
        }
    }); 
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/05/04/stop-the-backspace-key-from-going-to-the-previous-page-in-your-extjs-app/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Dealing with toolbars that go on forever</title>
		<link>http://www.learnsomethings.com/2012/05/01/dealing-with-toolbars-that-go-on-forever/</link>
		<comments>http://www.learnsomethings.com/2012/05/01/dealing-with-toolbars-that-go-on-forever/#comments</comments>
		<pubDate>Wed, 02 May 2012 00:39:53 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[ExtJs Stuff]]></category>
		<category><![CDATA[EXT]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[extjs4]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[sencha]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2458</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
This should not be a shocker to anyone, but the amount of toolbar that is visible on a users machine varies greatly with screen resolution. Best case scenario, the users that you have in mind all use a computer just &#8230; <a href="http://www.learnsomethings.com/2012/05/01/dealing-with-toolbars-that-go-on-forever/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>This should not be a shocker to anyone, but the amount of toolbar that is visible on a users machine varies greatly with screen resolution. Best case scenario, the users that you have in mind all use a computer just like your development machine, and all have the great sense to set their resolution just like yours, then of course you would be guaranteed that they would see every single toolbar item just as you meticulously laid them out. Worst case scenario, well, you could get lucky and they call the help desk asking where that button disappeared to, or maybe they just walk to the competing product, you will never know.  Fortunately one simple setting will put your invisible toolbar items in a dropdown menu to the right of the visible toolbar items. The extjs example can be found here (<a href="http://docs.sencha.com/ext-js/4-1/#!/example/toolbar/overflow.html" target="_blank">http://docs.sencha.com/ext-js/4-1/#!/example/toolbar/overflow.html</a>).</p>
<p><a href="http://www.learnsomethings.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-01-at-8.38.48-PM.png"><img src="http://www.learnsomethings.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-01-at-8.38.48-PM.png" alt="" title="Screen Shot 2012-05-01 at 8.38.48 PM" width="585" height="249" class="aligncenter size-full wp-image-2459" /></a></p>
<p>The code that makes this possible is:</p>
<pre class="brush: jscript; title: ; notranslate">
layout: {
      overflowHandler: 'Menu'
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/05/01/dealing-with-toolbars-that-go-on-forever/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Help I can&#8217;t set values in my Multiselect Combobox in extjs4</title>
		<link>http://www.learnsomethings.com/2012/05/01/help-i-cant-set-values-in-my-multiselect-combobox-in-extjs4/</link>
		<comments>http://www.learnsomethings.com/2012/05/01/help-i-cant-set-values-in-my-multiselect-combobox-in-extjs4/#comments</comments>
		<pubDate>Wed, 02 May 2012 00:35:18 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[ExtJs Stuff]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[extjs4]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[sencha]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2450</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
Ok, there is a little documented trick to setting multiple values in the extjs4.1 combobox when you have multiselect set to true and you are returning your values as a comma delimted string from the store. I know what you &#8230; <a href="http://www.learnsomethings.com/2012/05/01/help-i-cant-set-values-in-my-multiselect-combobox-in-extjs4/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>Ok, there is a little documented trick to setting multiple values in the extjs4.1 combobox when you have multiselect  set to true and you are returning your values as a comma delimted string from the store. I know what you are thinking, and no I don&#8217;t mean you are storing your multiple values in the database as a comma delimited string, but let&#8217;s say you used STUFF or something like that to get the values back as a nice delimited string.</p>
<p>Your data would look like this if you alerted the value in the record.</p>
<p><a href="http://www.learnsomethings.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-01-at-8.32.36-PM.png"><img src="http://www.learnsomethings.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-01-at-8.32.36-PM.png" alt="" title="Screen Shot 2012-05-01 at 8.32.36 PM" width="191" height="175" class="aligncenter size-full wp-image-2451" /></a></p>
<p>Your combobox would look like this after the record was loaded:</p>
<p><a href="http://www.learnsomethings.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-01-at-8.33.27-PM.png"><img src="http://www.learnsomethings.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-01-at-8.33.27-PM.png" alt="" title="Screen Shot 2012-05-01 at 8.33.27 PM" width="245" height="49" class="aligncenter size-full wp-image-2452" /></a></p>
<p>But you want the combobox to look like this:</p>
<p><a href="http://www.learnsomethings.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-01-at-8.34.06-PM.png"><img src="http://www.learnsomethings.com/wp-content/uploads/2012/05/Screen-Shot-2012-05-01-at-8.34.06-PM.png" alt="" title="Screen Shot 2012-05-01 at 8.34.06 PM" width="238" height="49" class="aligncenter size-full wp-image-2453" /></a></p>
<p>What you will need to do is transform your comma delimited string into an array and then set the value like this:</p>
<pre class="brush: jscript; title: ; notranslate">
// this goes right before your form.loadRecord(record) code

var values = rec.get('delimited_string_field').split(',');
Ext.getCmp('your_multiselect_box').setValue(values);   

</pre>
<p>It&#8217;s that easy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/05/01/help-i-cant-set-values-in-my-multiselect-combobox-in-extjs4/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Extjs4 Color Picker in a drop down control for use on forms and in editable grids</title>
		<link>http://www.learnsomethings.com/2012/03/20/extjs4-color-picker-in-a-drop-down-control-for-use-on-forms-and-in-editable-grids/</link>
		<comments>http://www.learnsomethings.com/2012/03/20/extjs4-color-picker-in-a-drop-down-control-for-use-on-forms-and-in-editable-grids/#comments</comments>
		<pubDate>Wed, 21 Mar 2012 00:35:42 +0000</pubDate>
		<dc:creator>Joshua</dc:creator>
				<category><![CDATA[ExtJs Stuff]]></category>
		<category><![CDATA[extjs]]></category>
		<category><![CDATA[extjs4]]></category>
		<category><![CDATA[extjs4 overrides and plugins]]></category>
		<category><![CDATA[sencha]]></category>

		<guid isPermaLink="false">http://www.learnsomethings.com/?p=2430</guid>
		<description><![CDATA[<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
Ok so I needed a color picker that I could stick in an editable grid or just use as a form field, but I did not want to render the complete box with the little color squares in the form, &#8230; <a href="http://www.learnsomethings.com/2012/03/20/extjs4-color-picker-in-a-drop-down-control-for-use-on-forms-and-in-editable-grids/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
	<style type="text/css">
#leftcontainerBox {
float:left;
position: fixed;
top: 60%;
left: 70px;
}

#leftcontainerBox .buttons {
float:left;
clear:both;
margin:4px 4px 4px 4px;

padding-bottom:2px;
}


#bottomcontainerBox {
height: 60px;
width:50%;
padding-top:1px;
}

#bottomcontainerBox .buttons {
float:left;
height: 60px;
margin:4px 4px 4px 4px;
}

</style>
			<content:encoded><![CDATA[<p>Ok so I needed a color picker that I could stick in an editable grid or just use as a form field, but I did not want to render the complete box with the little color squares in the form, and well, a grid is pretty tight on space. </p>
<p>I went ahead and designed a color picker combo box that puts the hex value in the input field and underlines it in the selected color. One of the notable features is the monitorMouseLeave method that is found in Ext.Element, this performs an action after the users mouse leaves an element after a preset amount of time. In the code below it is used to hide the drop down color fields after the user leaves the picker for half a second. This way we don&#8217;t force them to make a selection, but do not penalize them for coloring outside of the lines with their mouse.</p>
<pre class="brush: jscript; title: ; notranslate">
Ext.define('Ext.ux.ColorPickerCombo', {
	extend: 'Ext.form.field.Trigger',
	alias: 'widget.colorcbo',
	triggerTip: 'Please select a color.',
 	onTriggerClick: function() {
	  var me = this; 
	  picker = Ext.create('Ext.picker.Color', {     
		pickerField: this,     
		ownerCt: this,    
		renderTo: document.body,     
		floating: true,    
		hidden: true,    
		focusOnShow: true,
		style: {
            	backgroundColor: &quot;#fff&quot;
        	} ,
		listeners: {
            	scope:this,
            	select: function(field, value, opts){
		me.setValue('#' + value);
		me.inputEl.setStyle({backgroundColor:value});
		picker.hide();
	},
	show: function(field,opts){
		field.getEl().monitorMouseLeave(500, field.hide, field);
		}
        	}
});
       picker.alignTo(me.inputEl, 'tl-bl?');
       picker.show(me.inputEl);
	}	
});
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.learnsomethings.com/2012/03/20/extjs4-color-picker-in-a-drop-down-control-for-use-on-forms-and-in-editable-grids/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
