<?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>Pearl Wisdom &#187; Code</title>
	<atom:link href="http://blog.pearlcrescent.com/categories/code/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.pearlcrescent.com</link>
	<description></description>
	<lastBuildDate>Tue, 13 Apr 2010 15:49:51 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>5 Minute Signal</title>
		<link>http://blog.pearlcrescent.com/archives/78</link>
		<comments>http://blog.pearlcrescent.com/archives/78#comments</comments>
		<pubDate>Thu, 22 Jan 2009 04:11:17 +0000</pubDate>
		<dc:creator>Mark Smith</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[DIYTech]]></category>
		<category><![CDATA[Diversions]]></category>

		<guid isPermaLink="false">http://blog.pearlcrescent.com/?p=78</guid>
		<description><![CDATA[

For the past year and a half I (Mark) have been part of an Ann Arbor, Michigan based group named GO-Tech.  The common thread among the group members is that each of us is interested in making things using technology (combining hardware, software, metal, wood, etc.).  I refer to it as &#8220;Do It [...]]]></description>
			<content:encoded><![CDATA[<div style="float:right; margin-left: 5px;">
<a href="http://pearlcrescent.com/diytech/5-minute-signal/signal.jpg"><img src="http://pearlcrescent.com/diytech/5-minute-signal/signal-small.jpg" alt="5 Minute Signal" title="Click to view larger image"/></a></div>
<p>For the past year and a half I (Mark) have been part of an Ann Arbor, Michigan based group named <a href="http://tech.groups.yahoo.com/group/notbago/">GO-Tech</a>.  The common thread among the group members is that each of us is interested in making things using technology (combining hardware, software, metal, wood, etc.).  I refer to it as &#8220;Do It Yourself Tech&#8221; (DIYTech).  The group meets monthly to present projects and have interesting discussions.  I attend when I am able; it is a fun, enriching after hours activity.</p>
<p>At the <a href="http://blog.makezine.com/archive/2009/01/gotech_meeting_tonight_11309.html">most recent meeting</a> that took place on January 13th, there was a contest in which everyone was invited to build a device and demonstrate it at the meeting.  As Dale (the group organizer and leader) described it:</p>
<blockquote><p>
The Five-Minute Timer Contest goal is to design a timer to time presentations at our meetings. It should semi-accurately time the presenter, and give some audible or visual indication when their time is up. Portability, coolness, and robustness will be helpful. Cool prizes supplied by O&#8217;Reilly, publishers of Make.
</p></blockquote>
<p>I created a traffic signal based timer that I named &#8220;5 Minute Signal.&#8221;  The time is actually settable to one minute and up (in one minute increments).  To build it, I hacked an inexpensive plastic traffic signal (about one foot tall) that I purchased from Oriental Trading Company.  To control the signal and provide accurate time keeping, I used my trusty <a href="http://www.moderndevice.com/">Bare Bones Board</a> (BBB) Arduino-compatible microcontroller board.  The hardware is fairly simple (the BBB, a pushbutton control switch, and 3 relays to control the red, yellow, and green lights) and the software was fun to write.  I put the whole thing together the weekend before the GO-Tech meeting.</p>
<p>Basic operation is as you would expect:  Push the button to start the timer.  When the time interval is set to 5 minutes, the green light will stay on for the first 4 minutes, followed by one minute of yellow, and then red at the end of 5 minutes (the green and yellow intervals are shorter when the interval is 2 minutes or less).  More details are available in these documents:</p>
<ul>
<li>Presentation:   <a href="http://pearlcrescent.com/diytech/5-minute-signal/presentation.pdf">presentation.pdf</a></li>
<li>Schematic Diagram:   <a href="http://pearlcrescent.com/diytech/5-minute-signal/schematic.png">schematic.png</a></li>
<li>Arduino Source Code:  <a href="http://pearlcrescent.com/diytech/5-minute-signal/source-code.txt">source-code.txt</a></li>
</ul>
<p>The other contest entries included a very clever and well-made artificial sundial timer (by Jim) and another with a large servo-driven dial (by Don) that, if the presenter went too far over the allotted time, popped a balloon to get everyone&#8217;s attention.  The meeting attendees voted and in the end I tied with the sundial for &#8220;Best Timer&#8221; and the sundial won the &#8220;Coolest Timer&#8221; award.  I walked away with a copy of the <a href="http://www.instructables.com/group/Best-of-Instructables-Book/">Best of Instructables</a> book (thanks O&#8217;Reilly).</p>
<p>There was one more 5 Minute Timer project presented at the meeting (it arrived too late for the contest).  Peter put together a traffic signal based timer similar to mine that uses a full size (reclaimed) traffic signal that he purchased on eBay.  His impressively polished project includes a wireless remote control (something I considered but did not have time to include), a custom printed circuit board, and a wooden project box.  <a href="http://peterjjensen.com/TrafficLight.pdf">Schematic</a> (PDF).</p>
<p>The meeting also included an interesting talk about <a href="http://linuxcnc.org/">EMC</a> and some other presentations.  Overall, it was a creative, fun and informative evening.  If you are in the southeast Michigan area, I highly recommend that you attend an upcoming GO-Tech meeting</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pearlcrescent.com/archives/78/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Capture Page Images Programmatically</title>
		<link>http://blog.pearlcrescent.com/archives/51</link>
		<comments>http://blog.pearlcrescent.com/archives/51#comments</comments>
		<pubDate>Fri, 18 May 2007 19:37:36 +0000</pubDate>
		<dc:creator>Mark Smith</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Cool Tools]]></category>
		<category><![CDATA[Page Saver]]></category>

		<guid isPermaLink="false">http://blog.pearlcrescent.com/archives/51</guid>
		<description><![CDATA[Ever since we released Page Saver Pro, people have been asking us how they can leverage its image capture features within their own in-house projects.  The wait is over.
Earlier this week, we launched a new product named Page Saver Toolkit that allows web and Mozilla developers to use the page capture capabilities of Page [...]]]></description>
			<content:encoded><![CDATA[<p>Ever since we released <a href="http://pearlcrescent.com/products/pagesaver/pro/">Page Saver Pro</a>, people have been asking us how they can leverage its image capture features within their own in-house projects.  The wait is over.</p>
<p>Earlier this week, we launched a new product named <a href="http://pearlcrescent.com/products/pagesaver/toolkit/">Page Saver Toolkit</a> that allows web and Mozilla developers to use the page capture capabilities of Page Saver Pro.  By placing a little bit of JavaScript code inside a web page, you can call the Page Saver Pro engine to save an image of a page to a local PNG file.  Or save it to a local JPEG file.  Or upload it to an FTP server.  Or save the area occupied by a single DOM element on the page.  In fact, the Toolkit API will let you access nearly all of the capabilities of Page Saver Pro.</p>
<p>We also provide an <a href="http://developer.mozilla.org/en/docs/XPCOM">XPCOM</a> interface which is callable from privileged code inside Firefox (typically, that means from within another extension).</p>
<p>I could go on and on but I know this kind of product is not for everyone.  But for those of you who are doing things like writing automated quality assurance tests for an interactive web product or who want to go beyond the capabilities provided by Page Saver Pro&#8217;s command line interface, the Toolkit is the product for you.  Plus, it is fun to use.  Learn more on these pages:</p>
<ul>
<li><a href="http://pearlcrescent.com/products/pagesaver/toolkit/">Page Saver Toolkit Overview</a>.</li>
<li><a href="http://pearlcrescent.com/products/pagesaver/toolkit/doc/">Documentation</a> (includes sample code).</li>
</ul>
<p>Please take a look and <a href="http://pearlcrescent.com/products/pagesaver/toolkit/feedback.html">let us know</a> what you think.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pearlcrescent.com/archives/51/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CodeMash 2007</title>
		<link>http://blog.pearlcrescent.com/archives/44</link>
		<comments>http://blog.pearlcrescent.com/archives/44#comments</comments>
		<pubDate>Fri, 19 Jan 2007 18:58:56 +0000</pubDate>
		<dc:creator>Mark Smith</dc:creator>
				<category><![CDATA[Code]]></category>

		<guid isPermaLink="false">http://blog.pearlcrescent.com/?p=44</guid>
		<description><![CDATA[As I write this, I am immersed in <a href="http://codemash.org/">CodeMash 2007</a>, a two day conference for software developers.]]></description>
			<content:encoded><![CDATA[<p>As I write this, I am immersed in <a href="http://codemash.org/">CodeMash 2007</a>, a two day conference for software developers.  From the conference web site:</p>
<blockquote><p>
<em>CodeMash is a unique event that will educate developers on current practices, methodologies and technology trends in variety of platforms and development languages such as Java, .NET, Ruby and PHP.</em>
</p></blockquote>
<div style="float: left; margin-right: 20px;"><img src="http://codemash.org/images/codemash_logo.gif" alt="CodeMash" title="CodeMash" style="width: 217px; height: 207px;"/></div>
<p>There are plenty of Python fans here as well, and newer solutions like Adobe&#8217;s <a href="http://en.wikipedia.org/wiki/Adobe_Flex">Flex</a> are also on the agenda.  There is a lot of talk about frameworks such as <a href="http://ajax.asp.net/Default.aspx">Atlas</a>, <a href="http://www.turbogears.org/">TurboGears</a>, and <a href="http://www.rubyonrails.org/">Rails</a>.  The speakers range from well known people such as <a href="http://www.mindview.net/WebLog">Bruce Eckel</a> to people I have never heard of (who are also doing interesting work).  In short, there is something for everyone who is a software developer or who aspires to be one.</p>
<p>One of the cool things about CodeMash is that the conference is entirely organized by a group of volunteers who see the value in &#8220;cross pollination&#8221; among software developers who are working in different areas.  None of the organizers will make any money from this conference either.  And while there is a full schedule of technical talks, there is also a participant-organized <a href="http://en.wikipedia.org/wiki/Open-space_meeting">Open Space</a> track taking place in the corridors and in, well, other open spaces.  Yesterday afternoon I attended a TurboGears/Flex Widget open space coding session instead of a traditional session.  It was fast-paced, fun, and informative.</p>
<p>Every conference has a prevailing culture.  At CodeMash, the culture is very relaxed and open.  The content as well as the attendees are very technical.  Don&#8217;t like the session you are in?  Use your two feet to move somewhere else.  Oops &mdash; that reminds me:  it is time to get up and go to the next session!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pearlcrescent.com/archives/44/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Programmatically adding items to the Firefox toolbar</title>
		<link>http://blog.pearlcrescent.com/archives/24</link>
		<comments>http://blog.pearlcrescent.com/archives/24#comments</comments>
		<pubDate>Mon, 23 Jan 2006 15:04:52 +0000</pubDate>
		<dc:creator>Mark Smith</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Page Saver]]></category>

		<guid isPermaLink="false">http://blog.pearlcrescent.com/?p=24</guid>
		<description><![CDATA[One of the changes we made for <a href="http://pearlcrescent.com/products/pagesaver/">Pearl Crescent Page Saver</a> 0.9.3 was to automatically add our "Save Page Image" toolbar item to the right side of the Firefox navigation toolbar.  We thought that would be easy to do, but (like many programming tasks) getting everything to work correctly was trickier than expected.]]></description>
			<content:encoded><![CDATA[<p>One of the changes we made for <a href="http://pearlcrescent.com/products/pagesaver/">Pearl Crescent Page Saver</a> 0.9.3 was to automatically add our &#8220;Save Page Image&#8221; toolbar item to the right side of the Firefox navigation toolbar.  We thought that would be easy to do, but (like many programming tasks) getting everything to work correctly was trickier than expected.</p>
<p><img src="http://pearlcrescent.com/products/pagesaver/images/toolbaritem-right.png" alt="Page Saver toobar item" /></p>
<p><strong>Problem 1:</strong> Adding the item by updating the navigation toolbar&#8217;s .currentSet property caused many of the toolbar items to stop working (for example, it no longer worked to load a new page from the URL bar).  Not good.  Solution: call BrowserToolboxCustomizeDone() to tell Firefox to reinitialize the toolbars.  This is a somewhat sneaky thing to do; Firefox should really provide a clean way for extensions to update the toolbars (in fact, there is <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=242071">an open bug</a> on this topic).</p>
<p><strong>Problem 2:</strong> (fallout from the solution to problem 1) Calling BrowserToolboxCustomizeDone() immediately after the window load event fired caused exceptions to be thrown (Firefox had not initialized everything yet).  Solution: use setTimeout() to introduce a short delay before adding the toolbar item.  I don&#8217;t much care for using setTimeout() this way, but it works.</p>
<p>We also set a Boolean preference so the toolbar item will only be installed once (if the user removes it, we don&#8217;t want it to mysteriously reappear).  Here is the code:<br />
<code><br />
const kPrefPrefix = "pagesaver.";<br />
const kPrefTBItemInstalled = kPrefPrefix + "toolbariteminstalled";<br />
&nbsp;<br />
window.addEventListener("load", SavePageInit, false);<br />
&nbsp;<br />
function SavePageInit()<br />
{<br />
&nbsp;&nbsp;var tbItemInstalled = nsPreferences.getBoolPref(kPrefTBItemInstalled, false);<br />
&nbsp;&nbsp;if (!tbItemInstalled)<br />
&nbsp;&nbsp;&nbsp;&nbsp;setTimeout("SavePageAddToolbarItem();", 0);<br />
}<br />
&nbsp;<br />
function SavePageAddToolbarItem()<br />
{<br />
&nbsp;&nbsp;const kToolBarID = "nav-bar";<br />
&nbsp;&nbsp;const kTBItemID = "tb-save-page-image";<br />
&nbsp;&nbsp;var tbElem = document.getElementById(kToolBarID);<br />
&nbsp;&nbsp;var tbItemElem = document.getElementById(kTBItemID);<br />
&nbsp;&nbsp;if (tbElem &#038;&#038; !tbItemElem)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;var newSet = tbElem.currentSet + "," + kTBItemID;<br />
&nbsp;&nbsp;&nbsp;&nbsp;tbElem.setAttribute("currentset", newSet);<br />
&nbsp;&nbsp;&nbsp;&nbsp;tbElem.currentSet = newSet;<br />
&nbsp;&nbsp;&nbsp;&nbsp;document.persist(kToolBarID, "currentset");<br />
&nbsp;&nbsp;&nbsp;&nbsp;nsPreferences.setBoolPref(kPrefTBItemInstalled, true);<br />
&nbsp;<br />
&nbsp;&nbsp;try {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BrowserToolboxCustomizeDone(true);<br />
&nbsp;&nbsp;&nbsp;&nbsp;} catch (e) {}<br />
&nbsp;&nbsp;}<br />
}<br />
</code></p>
<p>The try/catch around the BrowserToolboxCustomizeDone() call is not really necessary, but it insulates us a little bit from future Firefox changes.</p>
<p>I hope this information helps someone else.</p>
<p>References:</p>
<ul>
<li>MozillaZine forum topic &#8211; <a href="http://forums.mozillazine.org/viewtopic.php?t=189667&#038;start=0&#038;postdays=0&#038;postorder=asc&#038;highlight=&#038;sid=529eada0b681c980868a5ccd1d72b77f">Toolbar Button On Install</a></li>
<li>MozillaZine forum topic &#8211; <a href="http://forums.mozillazine.org/viewtopic.php?t=300404&#038;sid=af699425b587e70546ee682ae74a9c8d">Is there a cleaner way to automaticly add a toolbarbutton?</a></li>
<li>Bugzilla bug # 242071- <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=242071">Need someway to enable toolbar button at installation</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.pearlcrescent.com/archives/24/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
