<?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>Hello, I am Sean Murphy &#187; Code Snippets</title>
	<atom:link href="http://iamseanmurphy.com/category/code-snippets/feed/" rel="self" type="application/rss+xml" />
	<link>http://iamseanmurphy.com</link>
	<description>Thoughts, news, code by Sean Murphy</description>
	<lastBuildDate>Wed, 19 Aug 2009 17:40:26 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Binary Search for Javascript Arrays</title>
		<link>http://iamseanmurphy.com/2009/04/29/binary-search-for-javascript-arrays/</link>
		<comments>http://iamseanmurphy.com/2009/04/29/binary-search-for-javascript-arrays/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 21:41:12 +0000</pubDate>
		<dc:creator>Sean Murphy</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[binary search]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://iamseanmurphy.com/2009/04/29/binary-search-for-javascript-arrays/</guid>
		<description><![CDATA[If you need to search through a large array, or you search arrays frequently in your Javascript code, or if you do both, chances are a binary search will give you better performance than a linear search (read: for loop). One caveat, however, is that binary search algorithms only work on sorted arrays. Here is [...]


Related posts:<ol><li><a href='http://iamseanmurphy.com/2007/11/15/javascript-for-in-loops/' rel='bookmark' title='Permanent Link: Javascript For-in Loops'>Javascript For-in Loops</a></li><li><a href='http://iamseanmurphy.com/2008/10/10/longurl-integration-for-your-website/' rel='bookmark' title='Permanent Link: LongURL Integration For Your Website'>LongURL Integration For Your Website</a></li></ol>]]></description>
			<content:encoded><![CDATA[<p>If you need to search through a large array, or you search arrays frequently in your Javascript code, or if you do both, chances are a binary search will give you better performance than a linear search (read: for loop). One caveat, however, is that binary search algorithms only work on sorted arrays. Here is a binary search function I sometimes use in my code:</p>
<p><span id="more-34"></span></p>
<pre name="code" class="js">Array.prototype.binSearch = function(needle, case_insensitive) {
    if (!this.length) return -1;

	var high = this.length - 1;
	var low = 0;
	case_insensitive = (typeof(case_insensitive) !== 'undefined' &amp;&amp; case_insensitive) ? true:false;
	needle = (case_insensitive) ? needle.toLowerCase():needle;

	while (low &lt;= high) {
		mid = parseInt((low + high) / 2)
		element = (case_insensitive) ? this[mid].toLowerCase():this[mid];
		if (element &gt; needle) {
			high = mid - 1;
		} else if (element &lt; needle) {
			low = mid + 1;
		} else {
			return mid;
		}
	}

	return -1;
};</pre>


<p>Related posts:<ol><li><a href='http://iamseanmurphy.com/2007/11/15/javascript-for-in-loops/' rel='bookmark' title='Permanent Link: Javascript For-in Loops'>Javascript For-in Loops</a></li><li><a href='http://iamseanmurphy.com/2008/10/10/longurl-integration-for-your-website/' rel='bookmark' title='Permanent Link: LongURL Integration For Your Website'>LongURL Integration For Your Website</a></li></ol></p>]]></content:encoded>
			<wfw:commentRss>http://iamseanmurphy.com/2009/04/29/binary-search-for-javascript-arrays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Recursive Find and Replace With grep and Perl</title>
		<link>http://iamseanmurphy.com/2009/04/11/recursive-find-and-replace-with-grep-and-perl/</link>
		<comments>http://iamseanmurphy.com/2009/04/11/recursive-find-and-replace-with-grep-and-perl/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 20:51:56 +0000</pubDate>
		<dc:creator>Sean Murphy</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[find/replace]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://iamseanmurphy.com/2009/04/11/recursive-find-and-replace-with-grep-and-perl/</guid>
		<description><![CDATA[I thought it might be a nice idea to start posting useful little commands and bits of code every now and then&#8211;ones I&#8217;ve found to be particularly useful. So here&#8217;s the first one, recursive find and replace. A masterfully crafted regular expression paired with this command can save you hours of tedious work.

This will search [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>I thought it might be a nice idea to start posting useful little commands and bits of code every now and then&#8211;ones I&#8217;ve found to be particularly useful. So here&#8217;s the first one, recursive find and replace. A masterfully crafted regular expression paired with this command can save you hours of tedious work.</p>
<p><span id="more-32"></span><br />
This will search all files recursively for SEARCH_STRING and replace all occurrences of SEARCH_STRING with REPLACE_STRING throughout each unique file found. It also creates a backup of each modified file so that FILE is backed-up as FILE~ (with a tilde).</p>
<pre name="code" class="python">grep -R --files-with-matches 'SEARCH_STRING' . | sort | uniq | xargs perl -pi~ -e 's/SEARCH_STRING/REPLACE_STRING/'</pre>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://iamseanmurphy.com/2009/04/11/recursive-find-and-replace-with-grep-and-perl/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
