<?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>The Original Jelani Harris &#187; Code Gems</title>
	<atom:link href="http://jelaniharris.com/category/code-gems/feed/" rel="self" type="application/rss+xml" />
	<link>http://jelaniharris.com</link>
	<description>The original website of Jelani Harris the original of course</description>
	<lastBuildDate>Tue, 28 Feb 2012 21:11:36 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>How to read remote files using PHP</title>
		<link>http://jelaniharris.com/2010/how-to-read-remote-files-using-php/</link>
		<comments>http://jelaniharris.com/2010/how-to-read-remote-files-using-php/#comments</comments>
		<pubDate>Wed, 08 Dec 2010 20:49:56 +0000</pubDate>
		<dc:creator>Jelani Harris</dc:creator>
				<category><![CDATA[Code Gems]]></category>

		<guid isPermaLink="false">http://jelaniharris.com/?p=128</guid>
		<description><![CDATA[When I was implementing pingback functionality in my custom blogging software, I needed to read files from a remote server. As long as allow_url_fopen is enabled in your php.ini configuration you can use HTTP and FTP urls with a majority of the functions that use a filename as a parameter. I found that there are [...]]]></description>
			<content:encoded><![CDATA[<p>When I was implementing pingback functionality in my custom blogging software, I needed to read files from a remote server.</p>
<p>As long as allow_url_fopen is enabled in your php.ini configuration you can use HTTP and FTP urls with a majority of the functions that use a filename as a parameter.</p>
<p>I found that there are 3 ways to read remote files using PHP.</p>
<p><strong>Fopen</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$filepointer</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://banditrevolvers.com&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;r&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$site_content</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #666666; font-style: italic;">//While we still have content to read, append it</span>
     <span style="color: #666666; font-style: italic;">//1k at a time</span>
     <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$line</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filepointer</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$site_content</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$line</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">//Error occured while trying to read the url</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filepointer</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Another example using <a href="http://php.net/manual/en/function.fgets.php">fgets </a>instead of <a href="http://php.net/manual/en/function.fread.php">fread</a></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$filehandle</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://banditrevolvers.com&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
     <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">feof</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filehandle</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #000088;">$readline</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fgets</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filehandle</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">1024</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">eregi</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&amp;lt;title&amp;gt;(.*)&amp;lt;/title&amp;gt;&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$readline</span><span style="color: #339933;">,</span> <span style="color: #000088;">$output</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #000088;">$title</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$output</span><span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
               <span style="color: #b1b100;">break</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">//Error occured while trying to read the url</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Title of the page is: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$title</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$filehandle</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><em>Wait what's the difference between fgets and fread?</em></p>
<p>Glad you noticed that. The truth is that fread is the more preferable function to use when reading (or in this case streaming) data from a remote file. The reason is because the fgets function reads a line at a time. For example, if you had a 2000 line file that was only 35k in size, it would loop <em>2000 times</em> with fgets. However it would only loop <em>35 times</em> with fread (assuming a 1k buffer).</p>
<p>Then again, if you need to read a file one line at a time fgets is the function you'll need.</p>
<p><strong>File_get_contents</strong></p>
<p>This function will return the contents of a file in a string. To use it just specify a URL as a parameter. Be sure to check the return value to see if it was successful or not.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #990000;">file_get_contents</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://banditrevolvers.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$content</span> <span style="color: #339933;">!==</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">//Do something with the content</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">//An error occurred</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><strong>CURL</strong></p>
<p>Not all web hosts have the CURL library in their installation. Thus we have to check to see if the function exists before we attempt to use it.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'curl_init'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #666666; font-style: italic;">//Initialize a new resource for curl</span>
     <span style="color: #000088;">$ch</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_init</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #666666; font-style: italic;">//Set the url the retrieve</span>
     <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_URL<span style="color: #339933;">,</span> <span style="color: #0000ff;">'http://banditrevolvers.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #666666; font-style: italic;">//Return the value instead of outputting to the browser</span>
     <span style="color: #990000;">curl_setopt</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #339933;">,</span> CURLOPT_RETURNTRANSFER<span style="color: #339933;">,</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000088;">$contents</span> <span style="color: #339933;">=</span> <span style="color: #990000;">curl_exec</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #990000;">curl_close</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$ch</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$contents</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #666666; font-style: italic;">//Do stuff with the contents</span>
     <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
          <span style="color: #666666; font-style: italic;">//Show error message</span>
     <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://jelaniharris.com/2010/how-to-read-remote-files-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Changing the pointer into the hand cursor in AS3</title>
		<link>http://jelaniharris.com/2010/changing-the-pointer-into-the-hand-cursor-in-as3/</link>
		<comments>http://jelaniharris.com/2010/changing-the-pointer-into-the-hand-cursor-in-as3/#comments</comments>
		<pubDate>Wed, 01 Dec 2010 10:29:51 +0000</pubDate>
		<dc:creator>Jelani Harris</dc:creator>
				<category><![CDATA[Code Gems]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://jelaniharris.com/?p=133</guid>
		<description><![CDATA[One of the problems that I ran into while migrating from Actionscript 2 (AS2) to ActionScript 3 (AS3) was the fact that not only was setting a mouse event of a MovieClip different, so does how the mouse cursor acts. In AS2, setting the onPress event for a MovieClip would automatically cause the cursor to [...]]]></description>
			<content:encoded><![CDATA[<p>One of the problems that I ran into while migrating from Actionscript 2 (AS2) to ActionScript 3 (AS3) was the fact that not only was setting a mouse event of a MovieClip different, so does how the mouse cursor acts.</p>
<p>In AS2, setting the onPress event for a MovieClip would automatically cause the cursor to switch the hand whenever you hovered over the element. However in AS3 I discovered that in order to get the same functionality it has to be done manually to get the same effect:</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">//These are properties of the MovieClip class</span>
targetMc.<span style="color: #006633;">buttonMode</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
targetMc.<span style="color: #006633;">useHandCursor</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span></pre></div></div>

<p>Upon discovering this bit of code, I noticed that I had already created more than a dozen of clickable instances that could use this code and not all of them had classes for them. I had searched for some kind of global variable that I could set to see if I could get this working with all of them the easy way. Alas, I came up with nothing. So instead I decided to create a base class to implement this functionality for me.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">flash.display.MovieClip</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">com.jelaniharris</span> <span style="color: #009900;">&#123;</span>
     <span style="color: #000000; font-weight: bold;">class</span> ButtonMovieClip <span style="color: #000000; font-weight: bold;">extends</span> MovieClip <span style="color: #009900;">&#123;</span>
          <span style="color: #666666; font-style: italic;">//Override the default constructor and make this movieclip indicate it's a button to the user</span>
          <span style="color: #000000; font-weight: bold;">public</span> function ButtonMovieClip <span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">void</span> <span style="color: #009900;">&#123;</span>
               <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">buttonMode</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
               <span style="color: #000000; font-weight: bold;">this</span>.<span style="color: #006633;">useHandCursor</span> <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">true</span><span style="color: #339933;">;</span>
          <span style="color: #009900;">&#125;</span>
     <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then all I needed to do was to go to my library and set the Base Class of all of my button-like elements to the ButtonMovieClip class.</p>
<p>I hoped this helped someone out there.</p>
]]></content:encoded>
			<wfw:commentRss>http://jelaniharris.com/2010/changing-the-pointer-into-the-hand-cursor-in-as3/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Jquery to disable the enter key</title>
		<link>http://jelaniharris.com/2010/using-jquery-to-disable-the-enter-key/</link>
		<comments>http://jelaniharris.com/2010/using-jquery-to-disable-the-enter-key/#comments</comments>
		<pubDate>Fri, 16 Jul 2010 18:45:06 +0000</pubDate>
		<dc:creator>Jelani Harris</dc:creator>
				<category><![CDATA[Code Gems]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[validation]]></category>

		<guid isPermaLink="false">http://jelaniharris.com/?p=38</guid>
		<description><![CDATA[There are times that you do not want a form to automatically submit when a user hits the enter key. Or if you want to do some validation via javascript before you allow the submit to go through. //Bind this keypress function to all of the input tags $&#40;&#34;input&#34;&#41;.keypress&#40;function &#40;evt&#41; &#123; //Deterime where our character [...]]]></description>
			<content:encoded><![CDATA[<p>There are times that you do not want a form to automatically submit when a user hits the enter key. Or if you want to do some validation via javascript before you allow the submit to go through.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #006600; font-style: italic;">//Bind this keypress function to all of the input tags</span>
$<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;input&quot;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">keypress</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">function</span> <span style="color: #009900;">&#40;</span>evt<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #006600; font-style: italic;">//Deterime where our character code is coming from within the event</span>
<span style="color: #003366; font-weight: bold;">var</span> charCode <span style="color: #339933;">=</span> evt.<span style="color: #660066;">charCode</span> <span style="color: #339933;">||</span> evt.<span style="color: #660066;">keyCode</span><span style="color: #339933;">;</span>
<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>charCode  <span style="color: #339933;">==</span> <span style="color: #CC0000;">13</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> <span style="color: #006600; font-style: italic;">//Enter key's keycode</span>
<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>By returning false in the keypress function it tells the browser not to allow the enter key event.</p>
]]></content:encoded>
			<wfw:commentRss>http://jelaniharris.com/2010/using-jquery-to-disable-the-enter-key/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Removing empty elements from an array</title>
		<link>http://jelaniharris.com/2010/removing-empty-elements-from-an-array/</link>
		<comments>http://jelaniharris.com/2010/removing-empty-elements-from-an-array/#comments</comments>
		<pubDate>Tue, 04 May 2010 22:10:08 +0000</pubDate>
		<dc:creator>Jelani Harris</dc:creator>
				<category><![CDATA[Code Gems]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Php]]></category>

		<guid isPermaLink="false">http://jelaniharris.com/?p=90</guid>
		<description><![CDATA[When dealing with tag inputs from users, I find myself having to make sure they they don't enter in any blank or empty tags. Then I realized that I needed to find out how to remove undesirable elements not only from the Php side, but also from the Javascript side as well. Thus, here are [...]]]></description>
			<content:encoded><![CDATA[<p>When dealing with tag inputs from users, I find myself having to make sure they they don't enter in any blank or empty tags. Then I realized that I needed to find out how to remove undesirable elements not only from the Php side, but also from the Javascript side as well. Thus, here are some functions that may help some other people out if they're searching for similar functionality.</p>
<p><strong>In PHP</strong></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">    <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$my_array</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$key</span> <span style="color: #339933;">=&amp;</span>gt<span style="color: #339933;">;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #666666; font-style: italic;">//We check to make sure that the value is either null or just an empty string</span>
      <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">is_null</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #000088;">$value</span><span style="color: #339933;">==</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$my_array</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$key</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span></pre></div></div>

<p>An easier way to clean arrays is to use php's <a href="http://us.php.net/manual/en/function.array-filter.php">array_filter</a> function without a callback parameter. By default that function is set to remove elements that contain a false (or a 0), null or a "". I mean <em>seriously</em>, look at how much cleaner it is:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">   <span style="color: #666666; font-style: italic;">//This prunes out 'false', '0', 'null' or ''</span>
   <span style="color: #000088;">$my_array</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array_filter</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$my_array</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><strong>In JavaScript</strong></p>
<p>We can mimic the functionality of Php's array_filter in Javascript by using the Array.filter function.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;">   <span style="color: #003366; font-weight: bold;">var</span> my_array <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #CC0000;">2</span><span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'4'</span><span style="color: #339933;">,</span><span style="color: #3366CC;">''</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">'false'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #003366; font-weight: bold;">function</span> emptyElement<span style="color: #009900;">&#40;</span>element<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #006600; font-style: italic;">//Removes nulls, zeros (also falses), text version of false, and blank element</span>
	<span style="color: #000066; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>element <span style="color: #339933;">==</span> <span style="color: #003366; font-weight: bold;">null</span> <span style="color: #339933;">||</span> element <span style="color: #339933;">==</span> <span style="color: #CC0000;">0</span> <span style="color: #339933;">||</span> element.<span style="color: #660066;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #660066;">toLowerCase</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> <span style="color: #3366CC;">'false'</span> <span style="color: #339933;">||</span> element <span style="color: #339933;">==</span> <span style="color: #3366CC;">''</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #339933;">;</span>
		<span style="color: #000066; font-weight: bold;">else</span> <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #003366; font-weight: bold;">var</span> my_array <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #CC0000;">0</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'false'</span><span style="color: #339933;">,</span><span style="color: #CC0000;">1</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">null</span><span style="color: #339933;">,</span> <span style="color: #CC0000;">2</span><span style="color: #339933;">,</span><span style="color: #3366CC;">''</span><span style="color: #339933;">,</span><span style="color: #CC0000;">3</span><span style="color: #339933;">,</span><span style="color: #3366CC;">'4'</span><span style="color: #339933;">,</span><span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
	my_array <span style="color: #339933;">=</span> my_array.<span style="color: #660066;">filter</span><span style="color: #009900;">&#40;</span>emptyElement<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span></pre></div></div>

<p>Then my_array will include 1,2,3,4.</p>
<p>I hope this was somewhat useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://jelaniharris.com/2010/removing-empty-elements-from-an-array/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Increasing performance of Adobe CS3 Flash in Vista</title>
		<link>http://jelaniharris.com/2009/increasing-performance-of-adobe-cs3-flash-in-vista/</link>
		<comments>http://jelaniharris.com/2009/increasing-performance-of-adobe-cs3-flash-in-vista/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 22:47:30 +0000</pubDate>
		<dc:creator>Jelani Harris</dc:creator>
				<category><![CDATA[Code Gems]]></category>
		<category><![CDATA[adobe]]></category>
		<category><![CDATA[cs3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[vista]]></category>

		<guid isPermaLink="false">http://jelaniharris.com/?p=42</guid>
		<description><![CDATA[When I first started to use Flash CS3 in Vista I noticed that all of my flash movies were performing very very slowly. Honestly .. I'm not sure why. But, here's how you can make it perform better. Navigate to your Program Files -&#62; Adobe folder(s) -&#62; Adobe Flash CS3 and find the Flash.exe. Right [...]]]></description>
			<content:encoded><![CDATA[<p>When I first started to use Flash CS3 in Vista I noticed that all of my flash movies were performing very very slowly.</p>
<p>Honestly .. I'm not sure why. But, here's how you can make it perform better.</p>
<div id="attachment_77" class="wp-caption aligncenter" style="width: 550px"><img class="size-full wp-image-77" title="speeding-up-flash-for-vista" src="http://jelaniharris.com/blog/wp-content/uploads/2009/09/speeding-up-flash-for-vista.jpg" alt="Here's how to speed up flash CS3 for vista" width="540" height="399" /><p class="wp-caption-text">Here&#39;s how to speed up flash CS3 for vista</p></div>
<ol>
<li>Navigate to your Program Files -&gt; Adobe  folder(s) -&gt; Adobe Flash CS3 and find the Flash.exe.</li>
<li>Right click on that file and goto the Compatibility tab.</li>
<li>Check "run this program in compatibility mode", and voila, suddenly it's running as fast as it did on XP. Happy coding!</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://jelaniharris.com/2009/increasing-performance-of-adobe-cs3-flash-in-vista/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Case-insensitive replaceAll in Java</title>
		<link>http://jelaniharris.com/2009/case-insensitive-replaceall-in-java/</link>
		<comments>http://jelaniharris.com/2009/case-insensitive-replaceall-in-java/#comments</comments>
		<pubDate>Thu, 10 Sep 2009 17:54:11 +0000</pubDate>
		<dc:creator>Jelani Harris</dc:creator>
				<category><![CDATA[Code Gems]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://jelaniharris.com/?p=67</guid>
		<description><![CDATA[The replaceAll function in the java.lang.String class replaces each substring found in that matches the regular expression to replace. String sentence = &#34;The sly brown fox jumped over the lazy fox.&#34;; String result = sentence.replaceAll&#40;&#34;fox&#34;, &#34;doggie&#34;&#41;; System.out.println&#40;&#34;Input: &#34; + sentence&#41;; System.out.println&#40;&#34;Output: &#34; + result&#41;; Would output: Input: The sly brown fox jumped over the lazy [...]]]></description>
			<content:encoded><![CDATA[<p>The replaceAll function in the java.lang.String class replaces each substring found in that matches the regular expression to replace.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">String</span> sentence <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;The sly brown fox jumped over the lazy fox.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> result <span style="color: #339933;">=</span> sentence.<span style="color: #006633;">replaceAll</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;fox&quot;</span>, <span style="color: #0000ff;">&quot;doggie&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Input: &quot;</span> <span style="color: #339933;">+</span> sentence<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Output: &quot;</span> <span style="color: #339933;">+</span> result<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Would output:</p>
<p><code>Input: The sly brown fox jumped over the lazy fox.<br />
Output: The sly brown doggie jumped over the lazy doggie.</code></p>
<p>However there are cases where we want to replaceall substrings and ignore the case, or make it case insensitive.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">String</span> sentence <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;The sly brown Fox jumped over the lazy foX.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> result <span style="color: #339933;">=</span> sentence.<span style="color: #006633;">replaceAll</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;fox&quot;</span>, <span style="color: #0000ff;">&quot;dog&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Input: &quot;</span> <span style="color: #339933;">+</span> sentence<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Output: &quot;</span> <span style="color: #339933;">+</span> result<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><code>Input: The sly brown Fox jumped over the lazy foX.<br />
Output: The sly brown Fox jumped over the lazy foX.</code></p>
<p>To create the case sensitive version of replaceAll we do not need to create a new wrapper function or create a utility class somewhere. All we need to do is prepend the Case-insensitve pattern modifier (?i) before our regex to indicate that we don't care about the case sensitivity of the regex.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #003399;">String</span> sentence <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;The sly brown Fox jumped over the lazy foX.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">String</span> result <span style="color: #339933;">=</span> sentence.<span style="color: #006633;">replaceAll</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;(?i)fox&quot;</span>, <span style="color: #0000ff;">&quot;dog&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Input: &quot;</span> <span style="color: #339933;">+</span> sentence<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #003399;">System</span>.<span style="color: #006633;">out</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Output: &quot;</span> <span style="color: #339933;">+</span> result<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p><code>Input: The sly brown Fox jumped over the lazy foX.<br />
Output: The sly brown dog jumped over the lazy dog.</code></p>
]]></content:encoded>
			<wfw:commentRss>http://jelaniharris.com/2009/case-insensitive-replaceall-in-java/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

