
<?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>Examancer &#187; Programming</title>
	<atom:link href="http://examancer.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://examancer.com</link>
	<description>take in moderation</description>
	<lastBuildDate>Fri, 16 Dec 2011 00:15:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Rubyists Have More Fun: Drug Themed Ruby Gems</title>
		<link>http://examancer.com/2011/12/rubyists-have-more-fun-drug-themed-ruby-gems/</link>
		<comments>http://examancer.com/2011/12/rubyists-have-more-fun-drug-themed-ruby-gems/#comments</comments>
		<pubDate>Fri, 16 Dec 2011 00:12:29 +0000</pubDate>
		<dc:creator>Carl Zulauf</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://examancer.com/?p=211</guid>
		<description><![CDATA[I recently noticed we are using at least two &#8220;drug themed&#8221; gems in our current Ruby project. In my previous adventures in PHP, Java, and other languages I never ran into any drug themed libraries, so I found this curious, and a bit fun. I thought I&#8217;d take a few minutes and see how many [...]]]></description>
			<content:encoded><![CDATA[<p>I recently noticed we are using at least two &#8220;drug themed&#8221; gems in our current Ruby project. In my previous adventures in PHP, Java, and other languages I never ran into any drug themed libraries, so I found this curious, and a bit fun. I thought I&#8217;d take a few minutes and see how many Ruby gem authors have had some fun with their gem names by searching through gems for other drug themed gems. Here is the list I came up with:</p>
<ul>
<li><a href="https://github.com/ernie/valium">valium</a> &#8211; A gem that lets you get around the ActiveRecord instantiation penalty while retaining the awesome power of using ActiveRecord.</li>
<li><a href="https://github.com/jnunemaker/crack">crack</a> &#8211; A simple XML/JSON parsing library.</li>
<li><a href="https://github.com/jnunemaker/joint">joint</a> &#8211; Provides GridFS functionality to MongoMapper&#8230; seems kind of like a simple <a href="https://github.com/thoughtbot/paperclip">paperclip</a>+<a href="https://github.com/fog/fog">fog</a> implementation for MongoMapper.</li>
<li><a href="https://github.com/objectreload/cannabis">cannabis</a> &#8211; Simple permissions gem.</li>
<li><a href="https://github.com/miaout17/psychedelic">psychedelic</a> &#8211; A very &#8220;psychedelic&#8221;, maybe even just &#8220;psycho&#8221;, syntax colorizer.</li>
<li><a href="https://github.com/thoughtbot/cocaine">cocaine</a> &#8211; A gem which provides a bunch of functionality for executing system commands.</li>
</ul>
<p>Can you guess which two we&#8217;re using?</p>
<p>I don&#8217;t know if these gems are a positive or negative for the Ruby community. Personally, I like that the ruby community has such a great sense of humor. There are other humorously named gems out there that have nothing to do with drugs, like <a href="https://github.com/ernie/polyamorous">polyamorous</a> and <a href="https://github.com/thoughtbot/bourbon">bourbon</a>. I think it&#8217;s fantastic the Ruby community seems to remain constantly aware of the fact that programming should be fun, artistic, and expressive. My initial reaction is that these &#8220;funny&#8221; gems are just a symptom of that awareness; behavior that is generally embraced by the community.</p>
<p>What do you think? Are these gems good or bad for the community? Any other drug themed or humorously named gems I missed? What about libraries from other languages?</p>
]]></content:encoded>
			<wfw:commentRss>http://examancer.com/2011/12/rubyists-have-more-fun-drug-themed-ruby-gems/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Advanced &#8216;grep&#8217;: Search for Multiple Strings Simultaneously</title>
		<link>http://examancer.com/2010/12/advanced-grep-search-for-multiple-strings-simultaneously/</link>
		<comments>http://examancer.com/2010/12/advanced-grep-search-for-multiple-strings-simultaneously/#comments</comments>
		<pubDate>Tue, 14 Dec 2010 22:28:16 +0000</pubDate>
		<dc:creator>Carl Zulauf</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://examancer.com/?p=178</guid>
		<description><![CDATA[It took me a while to figure out how to do this so I thought I&#8217;d post a quick guide for other people who might need to have this trick up their sleeve. The unix/linux grep command can use POSIX extended regular expressions. I learned from this guide that unlike most other regular expression implementations [...]]]></description>
			<content:encoded><![CDATA[<p>It took me a while to figure out how to do this so I thought I&#8217;d post a quick guide for other people who might need to have this trick up their sleeve.</p>
<p>The unix/linux <a href="http://en.wikipedia.org/wiki/Grep">grep</a> command can use <a href="http://en.wikipedia.org/wiki/Regular_expression#POSIX_Extended_Regular_Expressions">POSIX extended regular expressions</a>. I learned from <a href="http://www.regular-expressions.info/posix.html#bre">this guide</a> that unlike most other regular expression implementations the meta-characters must be escaped to be treated as meta-characters. If they are not escaped grep will treat them as literal characters. This is exactly opposite of most regular expression engines where you escape meta-characters when you <strong>don&#8217;t</strong> want them treated by the regex engine as special characters.</p>
<p>I&#8217;m not particularly great at regex and I didn&#8217;t find a lot of guides on using extended POSIX regular expressions with grep. This really surprised me.</p>
<p>In my scenario I had a really large file I needed to search through. I had several unique strings I thought might be in this file and due to its size I didn&#8217;t want to execute a separate grep command for each string. This would be woefully inefficient as the entire file would be searched independently for each string. This approach would also take much much longer to complete and would be a lot more work for me.</p>
<p>Instead, I knew there had to be a way to craft a single command that would search the file once looking for any lines containing any of the strings I supplied. Well, using my mediocre knowledge of regular expressions and my new-found understanding of the behavior of grep&#8217;s regex engine I came up with the following command:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-nE</span> \<span style="color: #7a0874; font-weight: bold;">&#40;</span>string1\<span style="color: #000000; font-weight: bold;">|</span>string2\<span style="color: #000000; font-weight: bold;">|</span>string3\<span style="color: #000000; font-weight: bold;">|</span>string4\<span style="color: #7a0874; font-weight: bold;">&#41;</span> theFile.txt</div></div>
<p>Breaking down the command further:</p>
<ul>
<li><strong>grep</strong> &#8211; Indicates we are using the unix/linux grep utility.</li>
<li><strong>-nE</strong> &#8211; These are the grep &#8220;options.&#8221; &#8216;n&#8217; tells grep to tell us which line number any matches came from when it spits out its results. &#8216;E&#8217; tells grep to use its extended regular expression engine (required for this kind of search).</li>
<li><strong>\(</strong> and <strong>\)</strong> &#8211; These are the &#8220;range&#8221; boundaries for the regular expression. Technically not required here, but I find it good practice to use ranges in case you ever need to back reference. Grep would treat these like any other string if they weren&#8217;t escaped with the backslash. We want grep to treat these as special regex characters (range boundaries in this case) so we must escape them.</li>
<li><strong>\|</strong> &#8211; The regex &#8220;OR&#8221; operator. This tells grep that it can match either the value to the left or the value to the right of this operator. If you read out the statement above as &#8220;or&#8221; the command makes perfect sense. We are telling grep: find string1 OR string2 OR string3 OR string4 in theFile.txt. Since we want this to be treated by grep as an OR operator and not just another character it also needs to be escaped with a backslash.</li>
<li><strong>string1</strong>, <strong>string2</strong>, <strong>string3</strong>, and <strong>string4</strong> &#8211; The strings grep should be looking for in the file. The line &#8220;I like the taste of string1&#8242;s bread&#8221; would match string1 and would be in the results outputted by grep. The line &#8220;I think String2 has a really mean demeanor&#8221; would not match since this search is case sensitive by default.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://examancer.com/2010/12/advanced-grep-search-for-multiple-strings-simultaneously/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PDF Ruby Books for Free</title>
		<link>http://examancer.com/2010/04/pdf-ruby-books-for-free/</link>
		<comments>http://examancer.com/2010/04/pdf-ruby-books-for-free/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 18:02:45 +0000</pubDate>
		<dc:creator>Carl Zulauf</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[ipad]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[ipod]]></category>
		<category><![CDATA[palm pre]]></category>
		<category><![CDATA[pdf]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://examancer.com/?p=171</guid>
		<description><![CDATA[Many of us carry a device or two around with us capable of reading PDF files and there are often times when a reliable connection to the internet is not available. Whether it be a laptop you&#8217;re working on or a companion device like a smart phone (Palm Pre, iPhone, Android, etc.) or something like [...]]]></description>
			<content:encoded><![CDATA[<p>Many of us carry a device or two around with us capable of reading PDF files and there are often times when a reliable connection to the internet is not available. Whether it be a laptop you&#8217;re working on or a companion device like a smart phone (Palm Pre, iPhone, Android, etc.) or something like the iPad or Kindle there are cases where you might want a programming resource for one of these devices which doesn&#8217;t depend on an internet connection. Also important to many of us is price. There are several great books related to <a href="http://ruby-lang.org/">Ruby programming</a>, but few of them are free and even fewer available as a free PDF download. Below are direct links to some free PDF Ruby books.</p>
<ul>
<li><a href="http://www.humblelittlerubybook.com/book/hlrb.pdf">humble little ruby book [PDF]</a> (from <a href="http://www.humblelittlerubybook.com/">humblelittlerubybook.com</a>)</li>
<li><a href="http://en.wikibooks.org/wiki/Ruby_Programming">WikiBooks: Ruby Programming</a> &#8211; WikiBooks is a WikiMedia project and is similar to WikiPedia; however, content is organized under specific topics and meant to be treated somewhat like a book. I created a collection of all the Ruby Programming pages I could file and added in the <a href="http://en.wikibooks.org/wiki/Ruby_on_Rails/Print_version">print version</a> of the <a href="http://en.wikibooks.org/wiki/Ruby_on_Rails">Ruby on Rails</a> topic as well. I then used the book creator to export the collection as a PDF. <a href="http://examancer.com/wp-content/uploads/2010/04/ruby-wikibook.pdf">I am hosting a snapshot of this collection from 4/9/2010 here [PDF]</a>.</li>
<li><a href="http://www.sapphiresteel.com/IMG/pdf/LittleBookOfRuby.pdf">The Little Book of Ruby [PDF]</a> (from <a href="http://www.sapphiresteel.com/The-Little-Book-Of-Ruby">SapphireSteel Software</a>)</li>
</ul>
<p>I am looking at solutions for cleanly converting the RDoc documentation for ruby core, Rails, and a variety of gems. I will update this post or make a new post if I figure that out.</p>
]]></content:encoded>
			<wfw:commentRss>http://examancer.com/2010/04/pdf-ruby-books-for-free/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Printing a Specific Line From a Large File in Linux</title>
		<link>http://examancer.com/2009/12/printing-a-specific-line-from-a-large-file-in-linux/</link>
		<comments>http://examancer.com/2009/12/printing-a-specific-line-from-a-large-file-in-linux/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 17:24:35 +0000</pubDate>
		<dc:creator>Carl Zulauf</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://examancer.com/?p=164</guid>
		<description><![CDATA[I recently had to find a specific line in a large (28GB) file equipped with nothing more than the line number. I thought it would take me just a few seconds to find a cool *nix utility to accomplish this task. Instead, it took me a bit of scouring to find something that works, and [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to find a specific line in a large (28GB) file equipped with nothing more than the line number. I thought it would take me just a few seconds to find a cool *nix utility to accomplish this task. Instead, it took me a bit of scouring to find something that works, and works well on large files. That&#8217;s OK though since I had to wait for the 28GB file to uncompress from a tarball&#8230; which, obviously, takes a while.</p>
<p>What I learned about while I waited was the *nix command &#8216;sed&#8217;. This is a tool built for command line processing of data files. Apparently it was birthed as an evolution of our trusty friend &#8216;grep&#8217;. The forum post I found which hinted that &#8216;sed&#8217; was my solution didn&#8217;t provide much real information and the <a href="http://en.wikipedia.org/wiki/Sed">Wikipedia article</a> was mostly background and provided examples that won&#8217;t help me.</p>
<p>Where I found the most useful info was the <a href="http://sed.sourceforge.net/">sed page on sourceforge</a>&#8230; go figure. The docs page pointed me to &#8216;<a href="http://sed.sourceforge.net/sed1line.txt">The sed one-liners</a>&#8216; by Eric Pement. Here I found, through example, the power of &#8216;sed&#8217; and an example that is more efficient on large files than the ones I found elsewhere.</p>
<p>So here is how you do it:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'34005050q;d'</span> filename</div></div>
<p>&#8217;34005050&#8242; is the line number. &#8216;q&#8217; tells sed you are looking for that line number, and &#8216;;d&#8217; tells it to stop after that line. &#8216;filename&#8217; is of course the file you are trying to coax a specific line out of. To do an inclusive range of lines all at once (lines 8 through 12, for example), do this:</p>
<div class="codecolorer-container bash twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #ff0000;">'8,12!d'</span> filename</div></div>
<p>I&#8217;m still learning about &#8216;sed&#8217; but its already saving my ass. Have fun.</p>
]]></content:encoded>
			<wfw:commentRss>http://examancer.com/2009/12/printing-a-specific-line-from-a-large-file-in-linux/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ExaNotes &#8211; An Overdue Introduction</title>
		<link>http://examancer.com/2009/06/exanotes-an-overdue-introduction/</link>
		<comments>http://examancer.com/2009/06/exanotes-an-overdue-introduction/#comments</comments>
		<pubDate>Wed, 17 Jun 2009 05:12:13 +0000</pubDate>
		<dc:creator>Carl Zulauf</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[exanotes]]></category>
		<category><![CDATA[notes]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[webapp]]></category>

		<guid isPermaLink="false">http://examancer.com/2009/06/exanotes-an-overdue-introduction/</guid>
		<description><![CDATA[Several months ago I started working on ExaNotes as a lightweight personal tool to write, access, and search notes from one of the many computers I may use throughout the day. I told a good friend of mine about the simple web app I was building and she said it sounded like a great tool [...]]]></description>
			<content:encoded><![CDATA[<p>Several months ago I started working on <a title="ExaNotes - Secure Note Taking" href="https://exanotes.com/">ExaNotes</a> as a lightweight personal tool to write, access, and search notes from one of the many computers I may use throughout the day. I told a good friend of mine about the simple web app I was building and she said it sounded like a great tool for keeping a journal. I asked her if she could help test the app by keeping a journal and she hesitated. As good of friends as we were the idea of me having access to her journal was not a comfortable one. The convenience of being able to access her journal from any computer was appealing but she didn&#8217;t want to trade control of her privacy for convenience. Her desire for privacy gave me the idea of developing a system that was so secure that even the developer or administrator of the tool could not access the content users of the application have stored within it.</p>
<p>I decided to use this as a chance to learn much more about building secure web applications and I spent a few hours diagramming the concept. Then, I spoke with my friend again. I explained the design to her and she agreed the design would keep her journal secure enough that she would feel comfortable testing it and using it.<span id="more-136"></span></p>
<p>The basic design of <a href="https://exanotes.com/">ExaNotes</a> is that the a user&#8217;s password is used to encrypt each user&#8217;s notes using the very strong <a href="http://en.wikipedia.org/wiki/Advanced_Encryption_Standard">AES</a>-256 cipher. This password is only available to ExaNotes during the duration of the user&#8217;s browsing session. Once a logout or timeout has occurred the session data is destroyed and there is no longer any information left on the server which could be used to decrypt a user&#8217;s notes. The only thing stored on the server are the <a href="http://en.wikipedia.org/wiki/Salt_%28cryptography%29">salted</a> <a href="http://en.wikipedia.org/wiki/SHA_hash_functions">SHA-256</a> <a href="http://en.wikipedia.org/wiki/Cryptographic_hash">cryptographic hashes</a> of the user&#8217;s username and password. Even the username is anonymized!</p>
<p>In reality there is no way to completely secure any web application from someone who has all the keys and the knowledge. A sufficiently skilled developer or administrator could modify ExaNotes in such a way that user credentials were captured at the time of login and stored somewhere, allowing them the ability to decrypt the notes of users whose logins they have captured. As it currently stands ExaNotes only retains the login credentials for the duration of the user&#8217;s session and the session data is not easily accessible. More than just my good nature allows me to promise ExaNotes will remain this way as long as I am administrating it. My own self interest is to thank as well. If I had access to the content of ExaNotes&#8217; users I would assume a level of liability I do not want. Building a way to gain access to user content could force me to reveal content to a 3rd party. If the 3rd party was a good intentioned police officer wanting access to content to solve or prevent a murder there is very little ethical dilemma from my perspective. However, if an agent of an oppressive political organization attempted to coerce or force me into providing access to a user&#8217;s notes in an attempt to track and suppress political dessent it would be nice if I could avoid the ethical quandary by being able to truthfully respond that I simply have no way to provide access. I feel preventing myself from assuming that liability and building a truly secure and anonymous system is even more important than providing any mechanism for 3rd party investigation.</p>
<p>For some my promise is understandably not enough. To allow for independent validation of ExaNote&#8217;s design and security and to allow people to run ExaNotes on their own server I am offering the source code to anyone who requests it. For now anyone interested can send me an email and I will send you the source. Eventually I plan to start an open source project and release the source code under an open source license. I simply have not found the time and have not yet had requests from other developers to do so. For those interested ExaNotes is built using PHP,MySQL,HTML,CSS, and JavaScript. ExaNotes makes use of the prototype javascript library and tinyMCE rich text editor for its web interface. ExaNotes also contains a small API which could be used for desktop or &#8220;native&#8221; clients. If there is interest the API will be published with documentation.</p>
<p>The user interface of ExaNotes is clean, simple, and easy to learn. I generally follow the KISS principle in my interface design, which stands for &#8220;Keep It Simple, Stupid!&#8221; I&#8217;m sure you will agree that I have done that with ExaNotes. While the interface <strong>is</strong> simple I do not believe it is boring. ExaNotes provides a slick, even elegant interface for writing and managing your notes. This interface is lightweight yet modern, making use of modern web development tools like Ajax and Rich Text Editing while running fast on even the slowest computers and the smallest screens. ExaNotes even runs well on some mobile devices and is particularly optimized for use with the <a href="http://www.palm.com/us/products/phones/pre/index.html">Palm Pre</a>.</p>
<p>ExaNotes has been functional for a few months now and has been my primary note taking tool for roughly as long. I have been developing ExaNotes to fit my needs and those of a few of my friends and colleagues. I now feel this application is mature enough that it is ready for a larger audience and hopefully there is a large audience out there who will find it as useful as I do.</p>
<p>The public beta begins today. Simply visit <a href="https://exanotes.com/">ExaNotes</a> to participate.</p>
<p>Please send me questions, criticism, suggestions, bugs, or any other feedback you have regarding ExaNotes. Leave a comment here, <a href="mailto:carl@examancer.com">send me an email</a>, message me on <a href="http://twitter.com/examancer/">twitter</a>, even find me on AIM or Facebook.</p>
]]></content:encoded>
			<wfw:commentRss>http://examancer.com/2009/06/exanotes-an-overdue-introduction/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Greasemonkey Script: ArsTechnica Cleaner</title>
		<link>http://examancer.com/2008/12/greasemonkey-script-arstechnica-cleaner/</link>
		<comments>http://examancer.com/2008/12/greasemonkey-script-arstechnica-cleaner/#comments</comments>
		<pubDate>Thu, 04 Dec 2008 22:06:40 +0000</pubDate>
		<dc:creator>Carl Zulauf</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[arstechnica]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[userscript]]></category>

		<guid isPermaLink="false">http://examancer.com/?p=96</guid>
		<description><![CDATA[This is another fairly simple Greasemonkey script I&#8217;ve made to make viewing ArsTechnica much easier. This script hides, removes, and reorganizes superfluous content, widens the main content pain a little, and removes all flash. This is extremely helpful when you are reading many articles at a time and don&#8217;t want the flash animations on every [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://examancer.com/userscripts/arstechnica_cleaner.user.js">This</a> is another fairly simple <a href="http://www.greasespot.net/">Greasemonkey</a> script I&#8217;ve made to make viewing <a href="http://arstechnica.com/">ArsTechnica</a> much easier. This script hides, removes, and reorganizes superfluous content, widens the main content pain a little, and removes all flash. This is extremely helpful when you are reading many articles at a time and don&#8217;t want the flash animations on every article slowing down your computer. Scrolling smoothness, tab switching, and general responsiveness of your browser will be improved, especially on older/slower computers. Also, I find the slightly wider content pain to be easier to read.</p>
<p>Like last time, this script is also available through <a href="http://userscripts.org/scripts/show/38102">userscripts.org</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://examancer.com/2008/12/greasemonkey-script-arstechnica-cleaner/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Twitter Refresher Script for Greasemonkey/Others</title>
		<link>http://examancer.com/2008/09/twitter-refresher-script-for-greasemonkeyothers/</link>
		<comments>http://examancer.com/2008/09/twitter-refresher-script-for-greasemonkeyothers/#comments</comments>
		<pubDate>Thu, 11 Sep 2008 05:54:42 +0000</pubDate>
		<dc:creator>Carl Zulauf</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[firefox]]></category>
		<category><![CDATA[greasekit]]></category>
		<category><![CDATA[greasemetal]]></category>
		<category><![CDATA[greasemonkey]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[twitter]]></category>
		<category><![CDATA[userscript]]></category>

		<guid isPermaLink="false">http://examancer.com/?p=68</guid>
		<description><![CDATA[I wrote my first Greasemonkey script today, and it happens to be an automatic Twitter Refresher. The script will refresh Twitter every n seconds (10 seconds by default), unless you have placed any input in the input field, in which case it will not refresh. I haven&#8217;t tested this in Greasemetal (Google Chrome) or Greasekit [...]]]></description>
			<content:encoded><![CDATA[<p>I wrote my first <a href="http://www.greasespot.net/">Greasemonkey</a> script today, and it happens to be an automatic <a href="http://examancer.com/userscripts/Twitter_Refresher.user.js">Twitter Refresher</a>. The script will refresh Twitter every <em>n </em>seconds (10 seconds by default), unless you have placed any input in the input field, in which case it will not refresh.</p>
<p>I haven&#8217;t tested this in <a href="http://greasemetal.31tools.com/">Greasemetal</a> (Google Chrome) or <a href="http://8-p.info/greasekit/">Greasekit</a> (Safari) yet, but it uses very simple and standard javascript DOM to work, so I&#8217;m pretty sure it will work fine in other userscript environments.</p>
<p>Pretty simple, but its something I really wanted so I figured I would share in case anyone else needs a tool like this. Also available through <a href="http://userscripts.org/scripts/show/33497">userscripts.org</a>.</p>
<p>Let me know if you can think of any other sites this would be useful for.</p>
]]></content:encoded>
			<wfw:commentRss>http://examancer.com/2008/09/twitter-refresher-script-for-greasemonkeyothers/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>PHP: Is Output Buffering Significantly Slower Than Strings?</title>
		<link>http://examancer.com/2008/08/php-is-output-buffering-significantly-slower-than-strings/</link>
		<comments>http://examancer.com/2008/08/php-is-output-buffering-significantly-slower-than-strings/#comments</comments>
		<pubDate>Sat, 09 Aug 2008 02:26:49 +0000</pubDate>
		<dc:creator>Carl Zulauf</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Benchmarking]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://examancer.com/?p=19</guid>
		<description><![CDATA[I love PHP. I use it constantly for rapid prototyping and small scripts that help &#8220;glue&#8221; things together for me. However, one annoyance I have with PHP is related to building large strings. This isn&#8217;t particularly difficult in PHP&#8230; in fact its easier in PHP than most languages. The problem is that sometimes my entire [...]]]></description>
			<content:encoded><![CDATA[<p>I love PHP. I use it constantly for rapid prototyping and small scripts that help &#8220;glue&#8221; things together for me. However, one annoyance I have with PHP is related to building large strings. This isn&#8217;t particularly difficult in PHP&#8230; in fact its easier in PHP than most languages. The problem is that sometimes my entire page output will need to be contained in a string for various reasons (headers still need to be sent, the output needs to be passed to a filter or other function, etc&#8230;). Creating multi-line strings in PHP using single or double quotes looks awful, and the heredoc syntax prevents proper indentation. All of these methods also require tons of concatenation if any logic is necessary. Sometimes I have forgone these methods and instead used <a href="http://www.php.net/manual/en/book.outcontrol.php">Output Buffering</a> to prevent output from being sent, then I simply grab the content of the output buffer and store it in a string. This has several advantages, including ease of coding and the freedom of using the same code whether I need the output stored in a string or sent to the client immediately. However, its main disadvantage is that it is much slower&#8230; right? Well, I decided to find out exactly <em>how much</em> slower Output Buffering really is. Read on for my results.<br />
<span id="more-19"></span><br />
First, lets start witch what output buffering looks like vs. using single quotes and double quotes.</p>
<p>Output Buffering example:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; ob_start();<br />
&nbsp; ?&gt;<br />
&nbsp; &lt;div class=&quot;resultset&quot;&gt;<br />
&nbsp; &nbsp; &lt;div class=&quot;xResult&quot;&gt;$x is set to <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$x</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;<br />
&nbsp; &nbsp; &lt;div class=&quot;yResult&quot;&gt;$y is set to <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$y</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;<br />
&nbsp; &nbsp; &lt;div class=&quot;zResult&quot;&gt;$z is set to <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$z</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;<br />
&nbsp; &lt;/div&gt;<br />
&nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp; <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/ob_end_clean"><span style="color: #990000;">ob_end_clean</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Single Quotes example:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'<br />
&nbsp; &lt;div class=&quot;resultset&quot;&gt;<br />
&nbsp; &nbsp; &lt;div class=&quot;xResult&quot;&gt;$x is set to '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/div&gt;<br />
&nbsp; &nbsp; &lt;div class=&quot;yResult&quot;&gt;$y is set to '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$y</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/div&gt;<br />
&nbsp; &nbsp; &lt;div class=&quot;zResult&quot;&gt;$z is set to '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$z</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/div&gt;<br />
&nbsp; <br />
&nbsp; '</span><span style="color: #339933;">;</span></div></div>
<p>Double Quotes example:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<br />
&nbsp; &lt;div class=<span style="color: #000099; font-weight: bold;">\&quot;</span>resultset<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<br />
&nbsp; &nbsp; &lt;div class=<span style="color: #000099; font-weight: bold;">\&quot;</span>xResult<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\$</span>x is set to <span style="color: #006699; font-weight: bold;">$x</span>&lt;/div&gt;<br />
&nbsp; &nbsp; &lt;div class=<span style="color: #000099; font-weight: bold;">\&quot;</span>yResult<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\$</span>y is set to <span style="color: #006699; font-weight: bold;">$y</span>&lt;/div&gt;<br />
&nbsp; &nbsp; &lt;div class=<span style="color: #000099; font-weight: bold;">\&quot;</span>zResult<span style="color: #000099; font-weight: bold;">\&quot;</span>&gt;<span style="color: #000099; font-weight: bold;">\$</span>z is set to <span style="color: #006699; font-weight: bold;">$z</span>&lt;/div&gt;<br />
&nbsp; &lt;/div&gt;<br />
&nbsp; &quot;</span><span style="color: #339933;">;</span></div></div>
<p>All of these methods should build a variable $string with content similar to the following:</p>
<div class="codecolorer-container html4strict twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="html4strict codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;resultset&quot;</span>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;xResult&quot;</span>&gt;</span>$x is set to 401<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;yResult&quot;</span>&gt;</span>$y is set to 73953<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&lt;<a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a> <span style="color: #000066;">class</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;zResult&quot;</span>&gt;</span>$z is set to 3<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span><br />
&nbsp; <span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><a href="http://december.com/html/4/element/div.html"><span style="color: #000000; font-weight: bold;">div</span></a>&gt;</span></div></div>
<p>To determine how much slower output buffering is than the other two methods I wrote a <a href="http://examancer.com/tests/obBenchmark.php">benchmark</a> (<a href="http://examancer.com/tests/obBenchmark.phps">source code</a>) which repeats each method a large number of times. The benchmark linked to here is hosted on a shared hosting server so the results are unlikely to be consistent. I used an Athlon XP 3200+ system with 1GB of RAM running Apache 2.2.8 and PHP 5.2.6 on Ubuntu 8.04. I made sure that the system was not doing anything but serving up this benchmark. The results were repeatable and consistent, and the following is an average of five separate benchmark runs.</p>
<table border=1>
<tr>
<td colspan=2>String Building Method</td>
<td colspan=2>Execution Overhead %</td>
</tr>
<tr>
<td>Slower</td>
<td>Faster</td>
<td>Consecutive Test</td>
<td>Random Test</td>
</tr>
<tr>
<td>Output Buffering</td>
<td>Single Quotes</td>
<td>13.4743%</td>
<td>8.0886%</td>
</tr>
<tr>
<td>Output Buffering</td>
<td>Double Quotes</td>
<td>16.0896%</td>
<td>8.7876%</td>
</tr>
<tr>
<td>Single Quotes</td>
<td>Double Quotes</td>
<td>2.3048%</td>
<td>0.6467%</td>
</tr>
</table>
<p>As you can see, output buffering is clearly the slowest method. What is surprising, however, is that the difference is fairly small. The greatest delta exists between Output Buffering and Double Quotes, which just tops 16% when the tests are ran in consecutive mode. Even 16%, though, is not a huge performance difference. Its still small enough that using output buffering exclusively on a larger project for building large strings may not be considered a significant performance impact, and the advantages of using output buffering may make it the obvious choice.</p>
<p>Next, I decided to see if using logic while building strings would have any affect on the performance overhead output buffering incurs. In case what I am saying is not clear, here are a couple examples of using logic while building a string using both Output Buffering and Single Quotes:</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; // Output Buffering with Logic example:<br />
&nbsp; ob_start();<br />
&nbsp; ?&gt;<br />
&nbsp; &lt;div class=&quot;resultset&quot;&gt;<br />
&nbsp; &nbsp; &lt;div class=&quot;xResult&quot;&gt;$x is set to <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$x</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;<br />
&nbsp; &nbsp; &lt;div class=&quot;yResult&quot;&gt;$y is set to <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$y</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;<br />
&nbsp; &nbsp; &lt;div class=&quot;zResult&quot;&gt;$z is set to <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$z</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;<br />
&nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$z</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &nbsp; &lt;div class=&quot;LogicResult&quot;&gt;$z is greater than $x by <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$z</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$x</span> <span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/div&gt;<br />
&nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span> <span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp; &lt;/div&gt;<br />
&nbsp; <span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
&nbsp; <span style="color: #000088;">$string</span> <a href="http://www.php.net/ob_get_clean"><span style="color: #990000;">ob_get_clean</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; <span style="color: #666666; font-style: italic;">// Single Quotes with Logic example:</span><br />
&nbsp; <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'<br />
&nbsp; &lt;div class=&quot;resultset&quot;&gt;<br />
&nbsp; &nbsp; &lt;div class=&quot;xResult&quot;&gt;$x is set to '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/div&gt;<br />
&nbsp; &nbsp; &lt;div class=&quot;yResult&quot;&gt;$y is set to '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$y</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/div&gt;<br />
&nbsp; &nbsp; &lt;div class=&quot;zResult&quot;&gt;$z is set to '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$z</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'&lt;/div&gt;'</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$x</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$z</span> <span style="color: #009900;">&#41;</span> <span style="color: #000088;">$string</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'<br />
&nbsp; &nbsp; &lt;div class=&quot;LogicResult&quot;&gt;$z is greater than $x by '</span> <span style="color: #339933;">.</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$z</span> <span style="color: #339933;">-</span> <span style="color: #000088;">$x</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #000088;">$string</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'<br />
&nbsp; <br />
&nbsp; '</span><span style="color: #339933;">;</span></div></div>
<p>These examples further highlight the advantages of using Output Buffering. The code is clearly cleaner and easier to work with. With traditional string building (using single quotes, double quotes, or even heredoc) the string must be terminated, the conditional evaluated, possibly concatenating the string, then the string must be concatenated a final time to add additional closing string data. This is convoluted and ugly, and the performance difference would need to be immense for me to consider building strings like this using single quotes or double quotes. However, due to the additional string concatenation my hypothesis was that adding logic would actually lessen the performance overhead when using Output Buffering, making Output Buffering even more attractive. Lets have a look at what the actual results show when we add logic:</p>
<table border=1>
<tr>
<td colspan=2>String Building Method</td>
<td colspan=2>Execution Overhead %</td>
</tr>
<tr>
<td>Slower</td>
<td>Faster</td>
<td>Consecutive Test</td>
<td>Random Test</td>
</tr>
<tr>
<td>Output Buffering</td>
<td>Single Quotes</td>
<td>4.4925%</td>
<td>2.2353%</td>
</tr>
<tr>
<td>Output Buffering</td>
<td>Double Quotes</td>
<td>6.8601%</td>
<td>3.5564%</td>
</tr>
<tr>
<td>Single Quotes</td>
<td>Double Quotes</td>
<td>2.2659%</td>
<td>1.2923%</td>
</tr>
</table>
<p>While I expected a reduction in the performance cost of output buffering, I was not anticipating a reduction of this magnitude which such a small amount of logic. Against single quotes, Output Buffering has reduced its performance disadvantage by approximately <strong>2/3</strong>, and compared to double quotes the disadvantage has been reduced by well over <strong>1/2!</strong> These results are very encouraging for those wishing to use Output Buffering. The results from adding a small amount of logic lead me to believe that the performance disadvantage of Output Buffering will continue to shrink as the size of the string and amount of logic increases. In fact, a large enough string or frequent enough use of logic may eliminate the performance disadvantage completely and could even give output buffering a performance <strong>advantage</strong> in certain situations.</p>
<p>In the end the most important part of this investigation for <strong>me</strong> is that <strong>I</strong> will be much more likely to use output buffering in the future.</p>
]]></content:encoded>
			<wfw:commentRss>http://examancer.com/2008/08/php-is-output-buffering-significantly-slower-than-strings/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

