<?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>DreamSite Labs</title>
	<atom:link href="http://labs.dreamsiteweb.com/feed/rss2/" rel="self" type="application/rss+xml" />
	<link>http://labs.dreamsiteweb.com</link>
	<description>Andres Pi personal blog about web development and other interesting things.</description>
	<lastBuildDate>Fri, 02 Mar 2012 05:48:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>dreamyTip 2.0!</title>
		<link>http://labs.dreamsiteweb.com/labs/dreamytip-2-0/</link>
		<comments>http://labs.dreamsiteweb.com/labs/dreamytip-2-0/#comments</comments>
		<pubDate>Fri, 02 Mar 2012 05:38:21 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[labs]]></category>
		<category><![CDATA[dreamyTip]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Plugin]]></category>

		<guid isPermaLink="false">http://labs.dreamsiteweb.com/?p=218</guid>
		<description><![CDATA[After a while, I released a new version of this simple and lovely tooltip. With the new version of this jQuery plugin you will have a great tooltip with a couple of options like position(top,bottom, left, right), events(click and hover), speed, effect and callbacks very easy. You can check out the demo of the dreamyTip [...]]]></description>
			<content:encoded><![CDATA[<p>After a while, I released a new version of this simple and lovely tooltip. With the new version of this jQuery plugin you will have a great tooltip with a couple of options like position(top,bottom, left, right), events(click and hover), speed, effect and callbacks very easy.<br />
You can check out the demo of the <a href="http://labs.dreamsiteweb.com/jquery/plugins/dreamytip/" target="_blank">dreamyTip here</a> and download the <a href="http://labs.dreamsiteweb.com/jquery/plugins/dreamytip/dreamyTip.zip" target="_blank">demo</a> here or take a look at <a href="https://github.com/andres314/dreamyTip" target="_blank">GitHub</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.dreamsiteweb.com/labs/dreamytip-2-0/feed/rss2/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>CSS3 Generator</title>
		<link>http://labs.dreamsiteweb.com/labs/css3-generator/</link>
		<comments>http://labs.dreamsiteweb.com/labs/css3-generator/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 06:53:30 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[labs]]></category>
		<category><![CDATA[border-radius]]></category>
		<category><![CDATA[css3]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://labs.dreamsiteweb.com/?p=214</guid>
		<description><![CDATA[Last week I started working in personal project just to help me to learn some of the new CSS3 features. The idea is to create a Web App for testing and learning this new features.  And there is a lot of great new features, but undoubtedly one of my favorite is the &#8220;border radius&#8220;. After so [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I started working in personal project just to help me to learn some of the new <strong>CSS3</strong> features<strong></strong>. The idea is to create a Web App for testing and learning this new features.  And there is a lot of great new features, but undoubtedly one of my favorite is the &#8220;<a href="http://www.w3.org/TR/css3-background/#the-border-radius" target="_blank"><strong>border radius</strong></a>&#8220;. After so many years of using different techniques and tricks, we finally have the solution for the rounded corners!!! That is way I choose this feature to start working in this first step of the Web App, but the idea is upgrade it from time to time with the others new  features. In this link you will find the <a href="http://labs.dreamsiteweb.com/css3/" target="_blank">CSS3 generator Web App</a>, I hope you can find it helpful.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.dreamsiteweb.com/labs/css3-generator/feed/rss2/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>5 nice JavaSctipt resources</title>
		<link>http://labs.dreamsiteweb.com/resources/5-nice-javasctipt-resources/</link>
		<comments>http://labs.dreamsiteweb.com/resources/5-nice-javasctipt-resources/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 13:04:41 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[Resources]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[Framework]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[ide]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[online]]></category>

		<guid isPermaLink="false">http://labs.dreamsiteweb.com/?p=199</guid>
		<description><![CDATA[This time I&#8217;m sharing some resources that I found helpful while I developed in this great language. As we can read in the website of Mozilla: &#8220;JavaScript (sometimes shortened to JS) is a lightweight, object-oriented language, most known as the scripting language for web pages, but used in many non-browser environments as well&#8221;. Here are [...]]]></description>
			<content:encoded><![CDATA[<p>This time I&#8217;m sharing some resources that I found helpful while I developed in this great language. As we can read in the website of Mozilla: &#8220;JavaScript (sometimes shortened to JS) is a lightweight, object-oriented language, most known as the scripting language for web pages, but used in many non-browser environments as well&#8221;.<br />
Here are some guidelines, tips and online editors.<br />
<span id="more-199"></span></p>
<h3>Google JavaScript Style Guide:</h3>
<p>Style guidelines for JavaScript developers written by Google team</p>
<p><a href="http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml" target="_blank">Link to Google JavaScript Style Guide.</a></p>
<h3>jsFiddle:</h3>
<p>This is an Online Editor for the Web. With this editor you can write JavaScript, use some popular frameworks(<strong>MooTools</strong>, <strong>jQuery</strong>, <strong>Prototype</strong>, <strong>YUI</strong>, <strong>Glow</strong> and <strong>Dojo</strong>) and also you can edit HTML and CSS.</p>
<p><a href="http://www.jsfiddle.net" target="_blank">Link to jsfiddle.</a></p>
<h3>jsPerf, JavaScript performance playground:</h3>
<p><strong>jsPerf</strong> aims to provide an easy way to create and share test cases, comparing the performance of different JavaScript snippets by running benchmarks. </p>
<p><a href="http://jsperf.com/" target="_blank">Link to jsperf.</a></p>
<h3>Mozilla: </h3>
<p>Dedicated section to the JavaScript language itself, the parts that are not specific to Web pages or other host environments.</p>
<p><a href="https://developer.mozilla.org/en/JavaScript" target="_blank">Link to Mozilla JavaScript guideline.</a></p>
<h3>Haskell and JavaScript:</h3>
<p>Great article about <strong>Haskell Functions for JavaScript</strong> and a library, by Ariel Flesler.</p>
<p><a href="http://flesler.blogspot.com/2008/11/haskell-functions-for-javascript.html" target="_blank">Link to Haskell JavaScript Functions for JavaScript.</a></p>
<h3>Bonus:</h3>
<h2>w3schools:</h2>
<p>In the w3schools we can find a JavaScript and HTML DOM Reference. It also has an Online Editor, so you can try what you are reading.</p>
<p><a href="http://www.w3schools.com/jsref/default.asp" target="_blank">Link to w3schools reference.</a></p>
<h2>JavaScript&#8217;s appendChild and the Mythical prependChild:</h2>
<p>A nice article about the JavaScript&#8217;s appendChild() and the Mythical prependChild().</p>
<p><a href="http://developer.practicalecommerce.com/articles/2082-JavaScript-s-appendChild-and-the-Mythical-prependChild-" target="_blank">Link to the article <strong>JavaScript&#8217;s appendChild and the Mythical prependChild</strong>.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://labs.dreamsiteweb.com/resources/5-nice-javasctipt-resources/feed/rss2/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a custom WordPress admin</title>
		<link>http://labs.dreamsiteweb.com/labs/creating-a-custom-wordpress-admin/</link>
		<comments>http://labs.dreamsiteweb.com/labs/creating-a-custom-wordpress-admin/#comments</comments>
		<pubDate>Thu, 26 May 2011 19:09:53 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[labs]]></category>
		<category><![CDATA[CMS]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Wordpress]]></category>

		<guid isPermaLink="false">http://labs.dreamsiteweb.com/?p=175</guid>
		<description><![CDATA[Have you ever try to customize the wordpress dashboard? I&#8217;m sure that you think about it at least once if you made any development with wordpress. Luckily, WordPress&#8217; flexible nature allows for almost every part of it to be easily changed, Dashboard inclusive. The easy way is to create a plugin for it, so let&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever try to customize <strong>the wordpress dashboard</strong>? I&#8217;m sure that you think about it at least once if you made any development with wordpress. Luckily, WordPress&#8217; flexible nature allows for almost every part of it to be easily changed, Dashboard inclusive. The easy way is to create a <strong>plugin</strong> for it, so let&#8217;s take look on how we can creat a plugin first.<br />
<span id="more-175"></span></p>
<h4>Creating a plugin:</h4>
<p>The first step is to create a folder at &#8220;/wp-content/plugins/&#8221;, for example, called &#8220;custom-admin&#8221;. Save this file inside of the folder and call it custom-admin.php. This file must contain the next code at the begining:</p>
<pre class="brush:applescript">
<?php
/*
Plugin Name: Custom admin
Plugin URI: http://example.com/custom-admin
Description: Custom admin for WordPress.
Author: Your name
Version: 1.0
Author URI: http://example.com
 */ ?>
</pre>
<p>This is the &#8220;header&#8221; and provides information about the plugin to be viewed on the <a title="Administration Panels" href="http://codex.wordpress.org/Administration_Panels#Plugins_-_Add_Functionality_to_your_Blog" target="_blank">Plugin Panel</a>. It provides the name, URI of the plugin, the description, author, and version. Now we have the plugin and we have to activate it from the admin panel like any other plugin. And we ready to start developing our plugin.</p>
<h4>Custom footer</h4>
<p>Now that we are ready to start customazing <strong>the dashboard</strong> let&#8217;s start with something easy, for example, think about adding your own footer. If you want to modify the text you should add a function like this:</p>
<pre class="brush:applescript">
function custom_admin_footer() {
   echo 'This theme was made by <a href="http://example.com">Mr. WordPress</a>.';
}

add_filter('admin_footer', 'custom_admin_footer');</pre>
<p>This will replace the default <em>Thank you for creating with WordPress. | Documentation | Feedback</em> wordpress admin footer.</p>
<h4>Menu Items</h4>
<p>Now, we are going to remove some items from the admin menu with the <a href="http://codex.wordpress.org/Function_Reference/remove_menu_page" target="_blank"><strong>remove_menu_page()</strong></a> function:</p>
<pre class="brush:applescript"><!--?php 	function custom_admin_remove_menu_pages() { 		remove_menu_page('link-manager.php'); 		remove_menu_page('tools.php');	 	}         add_action( 'admin_init', 'custom_admin_remove_menu_pages' ); ?--></pre>
<p>This snippet remove the Links Manager and Tools menu items, and if you want to remove another item, you should change the parameter with the slug of the menu (typically the name of the PHP script for the built in menu items; example: edit-comments.php).</p>
<h4>Dashboard widgtes</h4>
<p>Another thing that we can do is removing the default dashboard widgtes <a href="http://codex.wordpress.org/Dashboard_Widgets_API#Advanced:_Removing_Dashboard_Widgets" target="_blank"><strong>remove_meta_box()</strong></a>:</p>
<pre class="brush:applescript">function custom_admin_remove_dashboard_widgets() {
	remove_meta_box( 'dashboard_quick_press', 'dashboard', 'side' );
	remove_meta_box( 'dashboard_incoming_links', 'dashboard', 'side' );
} 

add_action('wp_dashboard_setup', 'custom_admin_remove_dashboard_widgets' );</pre>
<p>This snippet will remove the <strong>quick press and the incoming links widget</strong> in the home page of the dashboard. Also, we can add a <strong>custom widget</strong> if you want:</p>
<pre class="brush:applescript">function custom_admin_dashboard_widget_function() {
	// Display whatever it is you want to show
	echo "Hello World, I'm a great Dashboard Widget";
} 

// Create the function use in the action hook
function custom_admin_add_dashboard_widgets() {
	wp_add_dashboard_widget('custom_admin_dashboard_widget', 'Example Dashboard Widget', 'custom_admin_dashboard_widget_function');
} 

// Hook into the 'wp_dashboard_setup' action to register our other functions
add_action('wp_dashboard_setup', 'custom_admin_add_dashboard_widgets' );</pre>
<p>You can find more info in the <a target="_blank" href="http://codex.wordpress.org/Dashboard_Widgets_API"><strong>Dashboard Widgets API</strong></a> page.</p>
<h4>Custom CSS for the dashboard</h4>
<p>Another useful tip is adding a custom <strong>CSS</strong> file for the admin panel. This will let you override <strong>the default styles</strong> of the wordpress dashboard. Here is an example of how you can do it:</p>
<pre class="brush:applescript">function custom_admin_css() {
  echo site_url() . "/wp-content/plugins/custom-admin/custom-admin.css";
}

add_action('admin_head','my_wp_admin_css');</pre>
<p>This will add a CSS file at the end of the head tag in the HTML, make sure that path is ok for you. </p>
<h4>Custom admin based on roles</h4>
<p>To finish this post I will show you how you can do different actions depending on the <strong>user role</strong>. As you know, WordPress uses a concept of <a href="http://codex.wordpress.org/Roles_and_Capabilities#Roles"><strong>Roles</strong></a>, designed to give the blog owner the ability to control and assign what users can and cannot do in the blog. So, we can extend this feature, adding or removing menu items, widgets, css and other stuff. For this, the first step is check the user role. For this example, I will only check if the user has an &#8216;administrator&#8217; role with the function  <a href="http://codex.wordpress.org/Function_Reference/current_user_can" target="_blank"><strong>&#8220;current_user_can()&#8221;</strong></a>:</p>
<pre class="brush:applescript">

<?php
function custom_admin_check_user(){
  if(!current_user_can("administrator")):
    custom_admin_is_not_administrator();
  endif;
}
add_action('admin_init', 'custom_admin_check_user');

function custom_admin_is_not_administrator(){
function custom_admin_dashboard_widget_function() {
	// Display whatever it is you want to show
	echo "Hello World, I'm a great Dashboard Widget";
} 

// Create the function use in the action hook
function custom_admin_add_dashboard_widgets() {
	wp_add_dashboard_widget('custom_admin_dashboard_widget', 'Example Dashboard Widget', 'custom_admin_dashboard_widget_function');
} 

// Hook into the 'wp_dashboard_setup' action to register our other functions
add_action('wp_dashboard_setup', 'custom_admin_add_dashboard_widgets' );

}

?> 
</pre>
<p>In the previous code, we are added a custom widget only if the user is not an administrator. Obviusly this bring us a lot of capabilities to customize the dashboard if you want users with differents roles have some custom widget or only some items in the menu. This is what you need. As I wrote at the begining, WordPress is a very flexible CMS and we put our own limits.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.dreamsiteweb.com/labs/creating-a-custom-wordpress-admin/feed/rss2/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HTML5: old school vs. new school</title>
		<link>http://labs.dreamsiteweb.com/labs/html5-old-school-vs-new-school/</link>
		<comments>http://labs.dreamsiteweb.com/labs/html5-old-school-vs-new-school/#comments</comments>
		<pubDate>Thu, 12 May 2011 19:05:02 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[labs]]></category>
		<category><![CDATA[attributes]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[input text]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://labs.dreamsiteweb.com/?p=158</guid>
		<description><![CDATA[A time ago post a JavaScript snipet. It was simple snipet that provides a hint that describes the expected value of an input field. So, when text input get focus, the default value disappears and allows the user to write, but if the user doesn’t type anything, the default value returns to the input text [...]]]></description>
			<content:encoded><![CDATA[<p>A time ago post a <a title="Text input default value recover jQuery snippet" href="http://labs.dreamsiteweb.com/labs/text-input-default-value-recover-javascript-snippet/" target="_blank">JavaScript snipet</a>. It was simple snipet that provides a hint that describes the expected value of an input field. So, when text input get focus, the default value disappears and allows the user to write, but if the user doesn’t type anything, the default value returns to the input text when the input lose the focus. But the last week I was reading the book <a href="http://www.amazon.com/gp/product/0240813286/ref=cm_li_v_p_self?tag=linkedin-20" target="_blank">HTML5: Designing Rich Internet Applications</a>, and I found some great new attributes.</p>
<p><span id="more-158"></span></p>
<p>One of them is the <strong>Placeholder</strong> attribute, which works exactly as my snipet(well, my snipet add an extra class to the input when get focus, but that is not always necessary). If your browser support <strong>HTML5</strong> you can test it here:</p>
<input style="width:250px"  placeholder="Testing the placeholder attribute" />
<p>&nbsp;</p>
<p>Apart of this one, there are other new great features in <strong>HTML5</strong> that I going to talk about in the future, as I think that <strong>HTML5 </strong> help making easy many task that ussualy were more complex and required the use of <strong>HTML</strong>, <strong>CSS </strong>and <strong>JavaSctip</strong>. Meanwhile you can start checking some of them in <a href="http://www.w3schools.com/html5/default.asp" target="_blank">w3schools</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.dreamsiteweb.com/labs/html5-old-school-vs-new-school/feed/rss2/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Global Functions</title>
		<link>http://labs.dreamsiteweb.com/labs/javascript-global-functions/</link>
		<comments>http://labs.dreamsiteweb.com/labs/javascript-global-functions/#comments</comments>
		<pubDate>Tue, 12 Apr 2011 03:37:02 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[labs]]></category>
		<category><![CDATA[Global Functions]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Object]]></category>
		<category><![CDATA[Regular Expressions]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">http://labs.dreamsiteweb.com/?p=135</guid>
		<description><![CDATA[In my last post, where I wrote about the Javascript problems with the float point numbers, I told that I would be writing about the JavaScript Global Functions. So here we are. This time I will talk about a few global functions that I think that could be useful and I hope that it will [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://labs.dreamsiteweb.com/labs/floating-point-numbers-in-javascript/" target="_blank">last post</a>, where I wrote about the Javascript problems with the float point numbers, I told that I would be writing about the JavaScript Global Functions. So here we are. This time I will talk about a few global functions that I think that could be useful and I hope that it will give you curious enough to investigate further.</p>
<p><span id="more-135"></span></p>
<h4>Strings and Regular Expressions:</h4>
<p><strong>Regular Expression</strong> is not something exclusive of JavaScipt. You can use it in many languages and it provides a concise and flexible means for matching strings of text, such as particular characters, words, or patterns of characters.</p>
<p>A regular expression, often called a <strong>pattern</strong>,  is an expression used to perform pattern-matching and &#8220;search-and-replace&#8221; functions on text. At first it seems to be very complex, but is very helpful, so is important learn how to use it. Luckily, JavaScript has several global functions that you can use when you have to work with strings. These are just some of then:</p>
<h5>string.search(regexp)</h5>
<p>The <strong>search()</strong> method, as its name says, searches for a match between a regular expression and a string and will returns the position of the match, or -1 if no match is found.&nbsp;
</p>
<pre class="brush:applescript">var theString = “search me”
document.write(theString.search("me"));  //output: 7</pre>
<h5>string.substr(start,length)</h5>
<p>The <strong>substr()</strong> method extracts the characters from a string, beginning at &#8220;start&#8221; and through the specified number of character, and returns the new sub string.</p>
<pre class="brush:applescript">var str="Hello world!";
document.write(str.substr(3)+"
"); //output: lo world!
document.write(str.substr(3,4)); //output lo w</pre>
<p>These functions are fine to make simple task, but it can get complicated without the use of regular expressions. Just to give an example, here a I leave a function to validate an e-mail just with global functions:</p>
<pre class="brush:applescript">function validate(email){
 if(email.search("@") == -1){
 return false;
 }else if(email.substring(0, email.search("@")).length&gt;1){
 email = email.substr(email.search("@"));
 email = email.split(".");
 if(email.length&gt;1){
 for(i=0;i&lt;email.length;i++){
 if(email[i] == " "){
 return false;
 }
 }
 return true;
 }else{
 return false;
 }
 }else{
 return false;
 }
}</pre>
<p>And here is an alternative function, much simpler, with a regular expression:</p>
<pre class="brush:applescript">function validate2(email) {
if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(email)){
    return true;
}else{
    return false;
}
}</pre>
<h4>Math Object</h4>
<p>The <strong>Math</strong> object allows you to perform mathematical tasks. You can use this to avoid a lot of looping and conditions. For example, if you need to get the the largest number in an array of numbers, you can do something like this with a loop:</p>
<pre class="brush:applescript">var myNumbers = [5,635,98,17,500,950];
var max = 0;
for(var i=0;i max){
  max = myNumbers[i];
}
}
alert(max);</pre>
<p>But it is easier and better perform this:</p>
<pre class="brush:applescript">Math.max(5,635,98,17,500,950); // returns 950</pre>
<p><strong>Math.max</strong> returns the number with the highest value. If no arguments are given, the result is &#8220;-Infinity&#8221;. On the other hand, if you want to get the lowest value you can perform <strong>Math.min</strong> method.</p>
<p>Also, maybe you have negative numbers and you want to get the absolute value of a number, to compare o do something else with it, what you need is the <strong>abs()</strong> method.</p>
<pre class="brush:applescript">Math.abs(-7) // returns 7</pre>
<p></P>
<p></P></p>
<h4>Links of reference:</h4>
<ul>
<li><a href="http://www.jslab.dk/tools.regex.php" target="_blank">JavaScript Regex Generator</a></li>
<li><a href="http://en.wikipedia.org/wiki/Regular_expression" target="_blank">Wikipedia article about regular expression</a></li>
<li><a href="http://www.w3schools.com/js/js_obj_regexp.asp" target="_blank">JavaScript RegExp Object</a></li>
<li><a href="http://www.w3schools.com/jsref/jsref_obj_string.asp" target="_blank">JavaScript String Object</a></li>
<li><a href="http://www.w3schools.com/jsref/jsref_obj_math.asp" target="_blank">JavaScript Math Object</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://labs.dreamsiteweb.com/labs/javascript-global-functions/feed/rss2/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Floating point numbers in JavaScript</title>
		<link>http://labs.dreamsiteweb.com/labs/floating-point-numbers-in-javascript/</link>
		<comments>http://labs.dreamsiteweb.com/labs/floating-point-numbers-in-javascript/#comments</comments>
		<pubDate>Tue, 25 Jan 2011 13:38:00 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[labs]]></category>
		<category><![CDATA[floating point numbers]]></category>
		<category><![CDATA[Global Functions]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://labs.dreamsiteweb.com/?p=110</guid>
		<description><![CDATA[A few weeks ago, I was doing a freelance for my friends of Gruponat when I got with this JavaScript problem. I was doing the following arithmetical function: &#8220;0.9 + 0.1&#8243;. To my surprise, the result wasn&#8217;t &#8220;1&#8243; as I spected. Numbers are represented in binary as IEEE-754 Doubles, which provides an accuracy to about 14 or [...]]]></description>
			<content:encoded><![CDATA[<p>A few weeks ago, I was doing a freelance for my friends of <a href="http://www.gruponat.com/index_eng.htm" target="_blank">Gruponat</a> when I got with this <strong>JavaScript</strong> problem. I was doing the following arithmetical function: &#8220;0.9 + 0.1&#8243;. To my surprise, the result wasn&#8217;t &#8220;1&#8243; as I spected.</p>
<p>Numbers are represented in binary as <a href="http://en.wikipedia.org/wiki/IEEE-754" target="_blank">IEEE-754</a> Doubles, which provides an accuracy to about 14 or 15 significant digits. Integers up to just over <code>9e15</code> are precise, but few decimal fractions are.  Because they are floating point numbers, they do not always exactly represent real numbers, including fractions. Given this, arithmetic is as exact as possible, but no more. Operations on integers are exact if the true result and all intermediates are integers within that range.</p>
<p><span id="more-110"></span></p>
<p>The problem is that although you can input and they are show as  common floating points numbers, internally they aren&#8217;t. This mean that a JavaScript program can not represent exactly some numbers like 0.3 or 0.1 (0.1; 0.001; etc) but it can represent others like 0.20 or 0.5. What you could do is something like this:</p>
<pre class="brush:applescript">

var floatnumber1 = 0.9;
var floatnumber2 = 0.1;
var result = Math.round(((floatnumber1*100) + (floatnumber2*100))/100));
</pre>
<p>And what about if we make more complex? In my case in need to represent the number in the HTML with a comma instead of a dot, like this &#8217;0,9&#8242;. So when I take the number from the HTML with JavaSript I have to convert from <strong>string to a floating point numbers</strong>. What I have to do first is convert the string with the JavaScript Global Functions <strong><a href="http://www.w3schools.com/jsref/jsref_replace.asp" target="_blank">&#8216;replace&#8217;</a></strong>:</p>
<pre class="brush:applescript">

var floatnumber1 = '0,9';
floatnumber1 = floatnumber1.replace(",",".");
</pre>
<p>And them I have to transform the string to a floating point numbers with the <strong><a herf="http://www.w3schools.com/jsref/jsref_parseFloat.asp" target="_blank">&#8216;parseFloat&#8217;</a></strong> JavaScript Global Functions.</p>
<pre class="brush:applescript">

floatnumber1 = parseFloat(floatnumber1)
</pre>
<p>And now, I have my number ready to do the arithmetical function.</p>
<pre class="brush:applescript">

var result = Math.round(((floatnumber1*100) + (floatnumber2*100))/100));
</pre>
<p>Its seems complicated, but its easier with the help of the <strong>JavaScript Global Functions</strong>. To finish, here is the final snippet, optimized just in one line. I add some code to the transform the floating point number to string again, adding the &#8220;&#8221; at the end, and them I replace the dot with the comma, to show it as the client want.</p>
<pre class="brush:applescript">

var floatnumber1 = '0,9';
var floatnumber2 = '0,1';
document.write(((Math.round((parseFloat(floatnumber1.replace(",","."))*100) + (floatnumber2.replace(",","."))/100) + "").replace(".",","));
</pre>
<p>In my next post I will be talking a little bit more about the JavaScript Global Functions, because I think be use to ignore them, using frameworks or just because we just don&#8217;t take the time to investigate if already exist a way to do some things, and they are a very powerful tool.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.dreamsiteweb.com/labs/floating-point-numbers-in-javascript/feed/rss2/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>BarCampAr in Buenos Aires</title>
		<link>http://labs.dreamsiteweb.com/general-topic/barcampar-in-buenos-aires/</link>
		<comments>http://labs.dreamsiteweb.com/general-topic/barcampar-in-buenos-aires/#comments</comments>
		<pubDate>Thu, 02 Dec 2010 18:12:36 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[General topic]]></category>
		<category><![CDATA[BarCampAr]]></category>
		<category><![CDATA[mobile]]></category>
		<category><![CDATA[software licenses]]></category>

		<guid isPermaLink="false">http://labs.dreamsiteweb.com/?p=96</guid>
		<description><![CDATA[A few days ago I went to the BarCampAr in Buenos Aires.  Is the fifth time that the event took place in Buenos Aires, but it&#8217;s the first time I went to it. There was a good variety of talks and was really interesting, but it was also a great opportunity to share  a good time with some colleagues [...]]]></description>
			<content:encoded><![CDATA[<div id="_mcePaste">A few days ago I went to the BarCampAr in Buenos Aires.  Is the fifth time that the event took place in Buenos Aires, but it&#8217;s the first time I went to it.</div>
<div id="_mcePaste">There was a good variety of talks and was really interesting, but it was also a great opportunity to share  a good time with some colleagues and friends(with some beer included). Here I&#8217;ll make a little review of  the two talks that I founded more interesting of all<span><span style="line-height: normal;">.<span id="more-96"></span><br />
</span></span></div>
<div>The first one was: <strong>Mobile, are you still think on it?</strong> The speaker was Max Firtman(<a href="http://twitter.com/#!/firt" target="_blank">@firt</a>). He talk about the diferences between the standard development and the mobile development and why we should start working on mobile. These are some of the most important points in the talk:</div>
<div id="_mcePaste">
<ul>
<li>Mobile is not minimizing the application or the site.</li>
<li>A mobile is very personal device and the user enjoy customizing with his tools.</li>
<li>As with any product, you have to take care about your target.</li>
<li>A Tablet is a mobile device, is an error thinking on it as a desktop device.</li>
<li>The mobile development is is a niche, there are a lots things to do.</li>
<li>All the companies will need a mobile site in the near future.</li>
<li>The web-app could be installed on the phone so you don&#8217;t always have to develop a native version.</li>
</ul>
</div>
<div id="_mcePaste">Those were the good things, but in the other hand you have the bad things, like there a lots of platforms(iPhone, android, etc) and it&#8217;s a very fast market. Not all the users are accustomed to using the mobile applications. And for last, for the developers, requires a lots of decisions and vision to understand the market, the target and generate strategies for testing and porting. But don&#8217;t be scare about these last point, it could be a great opportunity if you know how to take advantage of it.</div>
<div id="_mcePaste">The other talk was one about <strong>software licenses</strong> and the speakers were Sebastian Alvarez (<a href="http://twitter.com/#!/aseba" target="_blank">@aseba</a>) and Ezequiel Prieto(<a href="http://twitter.com/#!/ezequielprieto" target="_blank">@ezequielprieto</a>). They talked to us about how to license software and how important is that all the creations have license, it doesn&#8217;t matter if it is a private source or an open source.</div>
<div style="text-align: center;"><img class="aligncenter size-full wp-image-105" title="@asebas &amp; @ezequielprieto" src="http://labs.dreamsiteweb.com/wp-content/uploads/2010/12/201120103391.jpg" alt="@asebas &amp; @ezequielprieto" width="540" height="405" /></div>
<div>These are some tips that they gave to us:</div>
<div id="_mcePaste">
<ul>
<li>check the different licenses and which one fit better to the project</li>
<li>how we can work with something with a license, and how others can work with our projects.</li>
<li>There is difference between the license for using the software and the license for modify software.</li>
<li>Private software has license for use and you can not edit the software as you can do with open software.</li>
<li>We should put the license that we choose in some part of the source, in English.</li>
<li>Open source is not free of charge</li>
</ul>
</div>
<div id="_mcePaste">For more information about this, you can check  <a href=" http://creativecommons.org/" target="_blank">Creative Commons</a>, <a href="http://www.opensource.org/licenses/index.html" target="_blank">opensource.org</a> or <a href="http://en.wikipedia.org/wiki/Software_license" target="_blank">Wikipedia</a>.</div>
<div>Well that were a few words about my experience on the #BarCampAr. I Hope you enjoyed it.</div>
]]></content:encoded>
			<wfw:commentRss>http://labs.dreamsiteweb.com/general-topic/barcampar-in-buenos-aires/feed/rss2/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Text input default value recover jQuery snippet</title>
		<link>http://labs.dreamsiteweb.com/labs/text-input-default-value-recover-javascript-snippet/</link>
		<comments>http://labs.dreamsiteweb.com/labs/text-input-default-value-recover-javascript-snippet/#comments</comments>
		<pubDate>Wed, 06 Oct 2010 19:07:11 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[labs]]></category>
		<category><![CDATA[input text]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[snippet]]></category>

		<guid isPermaLink="false">http://labs.dreamsiteweb.com/?p=66</guid>
		<description><![CDATA[I just opened an account at http://snipplr.com and add my first snippet. I think it&#8217;s a good way to manage your own snippets for future use, and you can also take advantage by receiving community feedback and share it. The snippet that I posted could be useful when you have a text input with a [...]]]></description>
			<content:encoded><![CDATA[<div>I just opened an account at http://snipplr.com and add my first snippet. I think it&#8217;s a good way to manage your own snippets for future use, and you can also take advantage by receiving community feedback and share it.</div>
<div>The snippet that I posted could be useful when you have a text input with a default value. Thus, when user clicks on the input to write, the default value disappears and allows the user to write, but if the user doesn&#8217;t type anything, the default value will appears again. It also adds a class to the input when the user is typing on it and is removed when the input loses focus.</div>
<p><span id="more-66"></span></p>
<div>This snippet must be inside the ready event. For the HTML markup, the only thing to take care is that you must use the same class in all the inputs that you want to give this functionality. In the example I use &#8216;input-text-js&#8217;,  but you can use whatever you want.</div>
<div>This snippet could be used when a text input has a default value. Thus, when user clicks on the input to write, the default value disappears and allows the user to write, but if the user doesn&#8217;t type anything, the default value will appears again. It also adds a class to the input when the user is typing on it and is removed when the input loses focus.This snippet must be inside the ready event.For the HTML markup, the only thing to take care is that you must use the same class in all the inputs that you want to give this functionality. In the example I use &#8216;input-text-js&#8217;,  but you can use whatever you want.</div>
<div>
<pre class="brush:applescript">var textBoxs = $('.input-text-js');
textBoxs.each(function() {
  var theValue = $(this).attr('value');
  $(this).focus(function (){
    if($(this).attr('value') == theValue){
      $(this).attr('value','').addClass('writingIt');
    }
  }).blur(function () {
    if($(this).attr('value') == ''){
      $(this).attr('value',theValue).removeClass('writingIt');
    }
  });
});</pre>
</div>
<div>You can check the code at Snipplr.com <a href="http://snipplr.com/view/41714/text-input-default-value-recover/" target="_blank">here</a> and see it in action on <a href="http://www.retto.com" target="_blank">Retto.com</a>.</div>
]]></content:encoded>
			<wfw:commentRss>http://labs.dreamsiteweb.com/labs/text-input-default-value-recover-javascript-snippet/feed/rss2/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Firefox Add-ons Workshop Argentina</title>
		<link>http://labs.dreamsiteweb.com/general-topic/firefox-add-ons-workshop-argentina/</link>
		<comments>http://labs.dreamsiteweb.com/general-topic/firefox-add-ons-workshop-argentina/#comments</comments>
		<pubDate>Fri, 10 Sep 2010 20:30:16 +0000</pubDate>
		<dc:creator>Andy</dc:creator>
				<category><![CDATA[General topic]]></category>
		<category><![CDATA[add-ons]]></category>
		<category><![CDATA[Firefox]]></category>

		<guid isPermaLink="false">http://labs.dreamsiteweb.com/?p=51</guid>
		<description><![CDATA[Tomorrow I will go to the Firefox Add-ons Workshop Argentina, hoping I could learn all about firefox add-ons. I don&#8217;t have an idea yet about what add-on I could do in the future, but I think is useful having the &#8216;know-how&#8217; about that, because in the future you can create add-ons for your web proyects as complement [...]]]></description>
			<content:encoded><![CDATA[<p>Tomorrow I will go to the <a href="http://www.mozilla-ar.org/2010/09/taller-de-extensiones-de-firefox/" target="_blank">Firefox Add-ons Workshop Argentina</a>, hoping I could learn all about firefox add-ons. I don&#8217;t have an idea yet about what add-on I could do in the future, but I think is useful having the &#8216;know-how&#8217; about that, because in the future you can create add-ons for your web proyects as complement of it. Imagine for a web site of bids, like <strong>ebay, </strong>you can do an add-on were the user can follow his bid, an kwon when the his is loosing the bid. Or for a managing tasks web site, like <strong><a href="https://www.rememberthemilk.com">Remember the milk</a></strong>, you can do an add-on where the user could manage his task, adding new ones or editing others.</p>
<p>In sum, the add-ons could be a good addition to any web site to be conected with the user even when his is not on the web site. So I think that it is a good time to learn how to do this and start offering it to customers.</p>
]]></content:encoded>
			<wfw:commentRss>http://labs.dreamsiteweb.com/general-topic/firefox-add-ons-workshop-argentina/feed/rss2/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

