<?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>And now it’s all this</title>
	<atom:link href="http://www.leancrew.com/all-this/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.leancrew.com/all-this</link>
	<description>I just said what I said and it was wrong. Or was taken wrong.</description>
	<lastBuildDate>Thu, 23 May 2013 04:16:30 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>Blogging and readability</title>
		<link>http://www.leancrew.com/all-this/2013/05/blogging-and-readability/</link>
		<comments>http://www.leancrew.com/all-this/2013/05/blogging-and-readability/#comments</comments>
		<pubDate>Thu, 23 May 2013 04:16:30 +0000</pubDate>
		<dc:creator>Dr. Drang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[blogging]]></category>

		<guid isPermaLink="false">http://www.leancrew.com/all-this/?p=2082</guid>
		<description><![CDATA[Oh, goody! A blog post about blogging! I&#8217;ll try to make it brief. This post by Matt Gemmell about designing your blog for its readers is good, and you should go read it if you haven&#8217;t already. I do, however, have some nits to pick: I think he&#8217;s confusing current fashion for eternal truth when&#8230;]]></description>
				<content:encoded><![CDATA[<p>Oh, goody! A blog post about blogging! I&#8217;ll try to make it brief.</p>

<p><a href="http://mattgemmell.com/2013/05/22/designing-blogs-for-readers/">This post by Matt Gemmell</a> about designing your blog for its readers is good, and you should go read it if you haven&#8217;t already. I do, however, have some nits to pick:</p>

<ol>
<li>I think he&#8217;s confusing current fashion for eternal truth when he says sidebars should be removed. Why is it better to put all your meta-info in a header or footer instead of a sidebar? I agree that info about the blog should be reduced to a minimum—and, like Matt, I&#8217;ve been pruning mine over the years—but where it goes is more a matter of taste than reader inconvenience. To me, the advantage of the sidebar is that vertical space is more precious on today&#8217;s widescreen displays. Use the vertical space for content and put the peripheral stuff on the periphery—that&#8217;s where the adjective comes from. Yes, phone displays are different, but phones know how to focus on a single column, don&#8217;t they?</li>
<li>Despite my longstanding complaint that web designers make their body font too small, I think Matt&#8217;s decision to increase his body font size is wrong, too. How about just honoring the user&#8217;s choice? Yes, most users have no idea they can change the default font size (and Safari 6 made it even harder by <a href="http://www.leancrew.com/all-this/2012/07/some-safari-6-stuff/">removing the Appearance preference pane</a>), but you shouldn&#8217;t punish those who do.</li>
<li>He&#8217;s overly dogmatic on the matter of line length and line spacing; there are many combinations that are perfectly readable. I do like that he warns against lines that are too short—a lot of sites today have such narrow content columns it&#8217;s exhausting to scroll through to the end of the article.</li>
<li>He seems to think that any framing of the content is &#8220;cruft.&#8221; Again, this is fashion, and while it&#8217;s fine to be fashionable, this has nothing to do with readability. A few years from now, Matt will be dissatisfied with the broad expanses of white he has today.</li>
<li>While I&#8217;ve had my ups and downs with comments, I still think they&#8217;re a net positive for small blogs like mine with a polite and informed readership. I understand why writers with a big audience find comments a pain; why they can&#8217;t demonstrate a reciprocal understanding is a mystery to me.</li>
</ol>

<p>One thing Matt said really hit home:</p>

<blockquote>
  <p>Consider interaction methods, too: hover doesn’t really work on touch-screens, for example.</p>
</blockquote>

<p>The popup-on-hover footnotes I use here seemed really cool when <a href="http://www.leancrew.com/all-this/2010/05/popup-footnotes/">I stole them from Lukas Mathis</a> three years ago, but they&#8217;ve worn out their welcome. I still think having footnotes pop up is better than jerking the reader down to the bottom of the post and then back up again, but hover isn&#8217;t the way to trigger popups in a world of iPads. That&#8217;ll have to change.</p>

<p>Overall, I found Matt&#8217;s advice to be sound. I was a little surprised to see his endorsement of Twitter and (especially) Facebook links. These are generally considered douchey among the cool Mac bloggers; I look forward to reading their reactions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leancrew.com/all-this/2013/05/blogging-and-readability/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Dropbox/bin</title>
		<link>http://www.leancrew.com/all-this/2013/05/dropboxbin/</link>
		<comments>http://www.leancrew.com/all-this/2013/05/dropboxbin/#comments</comments>
		<pubDate>Wed, 22 May 2013 01:55:10 +0000</pubDate>
		<dc:creator>Dr. Drang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[unix]]></category>

		<guid isPermaLink="false">http://www.leancrew.com/all-this/?p=2079</guid>
		<description><![CDATA[It&#8217;s so easy to see the inefficiencies in someone else&#8217;s workflows, but so hard to see them in your own. When you do finally root out some clumsiness in your setup—no matter how small—and replace it with a more streamlined system, it&#8217;s a cause for celebration. This is a small celebratory post. I&#8217;ve kept my&#8230;]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s so easy to see the inefficiencies in someone else&#8217;s workflows, but so hard to see them in your own. When you do finally root out some clumsiness in your setup—no matter how small—and replace it with a more streamlined system, it&#8217;s a cause for celebration. This is a small celebratory post.</p>

<p>I&#8217;ve kept my scripts in a <code>~/bin</code> directory pretty much since I started using Linux in ’97. I&#8217;m not sure if I learned to do that from someone&#8217;s explicit advice or if I just copied the idea from someone. Either way, it&#8217;s a pretty common setup in the Unix world: you create this <code>~/bin</code> directory as a personal analog of <code>/bin</code>, <code>/usr/bin/</code>, and <code>/usr/local/bin</code>; you modify your <code>$PATH</code> environment variable in <code>.profile</code>, <code>.bash_profile</code>, or <code>.bashrc</code><sup id="fnref:zsh"><a href="#fn:zsh" rel="footnote">1</a></sup> to include that directory; and then any executable script saved in that directory can be run from the command line without specifying the full path to it. The advantages of saving to <code>~/bin</code> instead of one of the system wide <code>bin</code>s are</p>

<ol>
<li>You don&#8217;t need superuser powers to save or modify files in <code>~/bin</code>.</li>
<li><code>~/bin</code> won&#8217;t get overwritten when you do a system update.</li>
</ol>

<p>When I moved to the Mac in 2005, I kept this same setup and it&#8217;s served me well. But there&#8217;s always been one catch. If you have two computers, your <code>~/bin</code> directories won&#8217;t stay in sync unless you create some clever piece of automation to keep each directory up to date with changes in the other. I never did that. I tended to move new scripts written on one computer to the other through CD-ROMs, then USB thumb drives, and then, finally, Dropbox. I often forgot to move scripts and didn&#8217;t realize it until I needed one that only on the other computer.</p>

<p>If you look up at the title of this post, you know what comes next, but for some reason it took me a couple of years of using Dropbox to figure it out. While it&#8217;s conventional in the Linux/Unix world to have your <code>~/bin</code> directory just below your home directory, there&#8217;s no requirement for it to be there. It can be in any subdirectory of <code>~</code>. In particular, it can be in <code>~/Dropbox/bin</code>, where it will automatically sync between however many machines you have attached to that account.</p>

<p>Even after I finally realized this was the way to go, I didn&#8217;t pull the trigger. I don&#8217;t know why. Maybe it was because I&#8217;d lived so many years with out-of-sync <code>~/bin</code> directories; maybe it was because the tradition of <code>~/bin</code> was so strong I was afraid to change. Whatever, today I finally copied the contents of <code>~/bin</code> at work into <code>~/Dropbox/bin</code> and then did the same at home (skipping over duplicates), so <code>~/Dropbox/bin</code> has <em>all</em> of my scripts. A quick edit of my <code>.bashrc</code> to change</p>

<pre><code>export PATH=$HOME/bin:…
</code></pre>

<p>to</p>

<pre><code>export PATH=$HOME/Dropbox/bin:…
</code></pre>

<p>on both machines and the transformation was complete. I now have directories for my scripts on both computers that are automatically synced. Hooray!</p>

<p>In case you&#8217;re wondering, I have <em>not</em> deleted either <code>~/bin</code> directory. There is absolutely no reason in the world for the new system to fail, which is all the more reason to keep a backup for when it does.</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:zsh">
<p>Or whatever the equivalent is for <code>zsh</code> if you&#8217;re one of <em>those</em> weirdos.&#160;<a href="#fnref:zsh" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.leancrew.com/all-this/2013/05/dropboxbin/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Steel in Extremis</title>
		<link>http://www.leancrew.com/all-this/2013/05/steel-in-extremis/</link>
		<comments>http://www.leancrew.com/all-this/2013/05/steel-in-extremis/#comments</comments>
		<pubDate>Mon, 20 May 2013 14:00:00 +0000</pubDate>
		<dc:creator>Dr. Drang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[engineering]]></category>
		<category><![CDATA[mechanics]]></category>

		<guid isPermaLink="false">http://www.leancrew.com/all-this/?p=2078</guid>
		<description><![CDATA[I saw Iron Man 3 with my family Saturday night. It was fun (Ben Kingsley was especially good), but there was a part that bothered me a bit. I tweeted about it later: Iron Man 3 was fun, but that water tower in Tennessee should’ve fallen long before its leg melted.&#8212; Dr. Drang (@drdrang) Sat&#8230;]]></description>
				<content:encoded><![CDATA[<p>I saw Iron Man 3 with my family Saturday night. It was fun (Ben Kingsley was especially good), but there was a part that bothered me a bit. I tweeted about it later:</p>

<div class="bbpBox" id="t335936927641526272">
<blockquote>
<span class="twContent">Iron Man 3 was fun, but that water tower in Tennessee should’ve fallen long before its leg melted.</span><span class="twMeta"><br /><span class="twDecoration">&mdash; </span><span class="twRealName">Dr. Drang</span><span class="twDecoration"> (</span><a href="http://twitter.com/drdrang"><span class="twScreenName">@drdrang</span></a><span class="twDecoration">) </span><a href="https://twitter.com/drdrang/status/335936927641526272"><span class="twTimeStamp">Sat May 18 2013 8:56 PM CDT</span></a><span class="twDecoration"></span></span>
</blockquote>
</div>

<p>The tweet got a little attention, so I figured it was worth explaining.</p>

<p>The scene I&#8217;m talking about is when Tony Stark is in Tennessee, trying to repair his suit and learn about the first Extremis explosion. After he escapes from the fight in the bar, Tony comes across Killian&#8217;s number one henchman who, in that way comic book villains have of being way too elaborate in their plans to kill the hero, melts one leg of the town&#8217;s water tower to bring it down onto Tony.</p>

<p>Here he is heating up the leg (big props, by the way, for using a laced design for the column):</p>

<p><a href="http://www.flickr.com/photos/drdrang/8752698096/"><img class="ss" src="http://farm9.staticflickr.com/8254/8752698096_04b368e067_z.jpg" alt="Iron Man 3 water tower" title="Iron Man 3 water tower" /></a></p>

<p>And here he is &#8220;pulling&#8221; it down after the leg is so hot it&#8217;s almost dripping:</p>

<p><a href="http://www.flickr.com/photos/drdrang/8752707756/"><img class="ss" src="http://farm8.staticflickr.com/7345/8752707756_2a11b81156_z.jpg" alt="Iron Man 3 water tower" title="Iron Man 3 water tower" /></a></p>

<p class="source"> Both screenshots from <a href="http://www.fxguide.com/featured/iron-man-3-more-suits-to-play-with/">fxguide.com</a>.</p>

<p>The problem is that the leg would have failed long before it got to that orangey yellow state. Even though it doesn&#8217;t melt until about 2500° F, steel just isn&#8217;t very strong above 1000° F.</p>

<p>Here are a couple of charts showing the rapid dropoff of steel&#8217;s strength and stiffness (modulus of elasticity) for temperatures above 500°—700°. They&#8217;re taken from Brockenbrough and Merritt&#8217;s <a href="http://www.amazon.com/gp/product/0071666664?ie=UTF8&amp;tag=andnowitsal05-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0071666664"><em>Structural Steel Designer&#8217;s Handbook</em></a>.</p>

<p><a href="http://www.flickr.com/photos/drdrang/8755724624/"><img class="ss" src="http://farm6.staticflickr.com/5329/8755724624_e812fe3ca1_z.jpg" alt="Steel strength and stiffness at elevated temperatures" title="Steel strength and stiffness at elevated temperatures" /></a></p>

<p>These are idealized curves for design purposes, so they&#8217;re a little on the conservative side. I have an older version of this book that had a similar chart for strength with actual data points for different structural steels.</p>

<p><a href="http://www.flickr.com/photos/drdrang/8756347728/"><img class="ss" src="http://farm6.staticflickr.com/5470/8756347728_d288d2b9c8_z.jpg" alt="Yield strength vs temperature" title="Yield strength vs temperature" /></a></p>

<p>For completeness, I&#8217;ll mention that an older water tower like the one in the movie would almost certainly be made from A36 steel.</p>

<p>As you can see, somewhere between 1200° and 1300°, the strength of steel is about a third of its room temperature strength. Given that the water tank in the movie was full (it wouldn&#8217;t have been interesting otherwise), losing two-thirds of its strength and a similar amount of its stiffness<sup id="fnref:young"><a href="#fn:young" rel="footnote">1</a></sup> in one leg certainly would&#8217;ve brought the tower down. It might have collapsed at an even lower temperature.</p>

<p>What color does steel take on a various temperatures? Here&#8217;s a handy chart from Swedish steel maker, <a href="http://www.uddeholm.com/files/Temperature_guide.pdf">Uddeholm</a>:</p>

<p><a href="http://www.flickr.com/photos/drdrang/8755505299/"><img class="ss" src="http://farm9.staticflickr.com/8405/8755505299_e8eb68b286_z.jpg" alt="Color chart" title="Color chart" /></a></p>

<p>At the temperatures needed to cause collapse, the steel would be only a dull red, not the bright orange and yellow we see in the film.</p>

<p>And in case you&#8217;re wondering, yes, pretty much all of the above went through my head as I watched that scene. &#8220;Bothered&#8221; may be too strong a word for my reaction, but I couldn&#8217;t help but notice it. We all have areas of specialized knowledge that get triggered when we see someone get it wrong. This is one of mine.</p>

<p>Why does a column collapsing at the wrong temperature tweak me more than a guy melting steel by touching it? Well, the Extremis stuff is part of the comic book universe; it&#8217;s one of the futuristic/fantastic elements that drive the story. Complaining about it would be like rejecting <em>The Lord of the Rings</em> because hobbits don&#8217;t really exist. The water tower, on the other hand, is part of our world and should act like it. It wasn&#8217;t designed by Tony Stark.</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:young">
<p>The stiffness is important because the leg is a compression member. Compression members fail by buckling, and buckling capacity is governed by both yield strength and modulus of elasticity. The more you know…&#160;<a href="#fnref:young" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.leancrew.com/all-this/2013/05/steel-in-extremis/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Now we see the violence inherent in Hooke’s Law</title>
		<link>http://www.leancrew.com/all-this/2013/05/now-we-see-the-violence-inherent-in-hookes-law/</link>
		<comments>http://www.leancrew.com/all-this/2013/05/now-we-see-the-violence-inherent-in-hookes-law/#comments</comments>
		<pubDate>Sat, 18 May 2013 15:31:43 +0000</pubDate>
		<dc:creator>Dr. Drang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[mechanics]]></category>

		<guid isPermaLink="false">http://www.leancrew.com/all-this/?p=2077</guid>
		<description><![CDATA[This is the post where I explain how I avoided shooting my older son with the head of a screw. Two heads of screws, actually, but we&#8217;ll get into the details later. The underlying topic is strain energy, its potential1 for harm, and the respect it should be paid. As I said a few days&#8230;]]></description>
				<content:encoded><![CDATA[<p>This is the post where I explain how I avoided shooting my older son with the head of a screw. Two heads of screws, actually, but we&#8217;ll get into the details later. The underlying topic is strain energy, its potential<sup id="fnref:pun"><a href="#fn:pun" rel="footnote">1</a></sup> for harm, and the respect it should be paid.</p>

<p>As <a href="http://www.leancrew.com/all-this/2013/05/a-simple-drafts-work-diary/">I said a few days ago</a>, the inspiration for this post—apart from the actual incident in which I avoided shooting my son—was <a href="http://www.70decibels.com/generational/2013/5/4/033-what-happened-when-gabe-set-himself-on-fire.html">this episode</a> of Gabe Weatherhead and Erik Hess&#8217;s <em>Generational</em> podcast, in which they talked about the dangers of their respective former professions—Gabe as a research chemist and Erik as a fighter pilot. The dangers associated with being a fighter pilot are pretty obvious; those associated with being a research chemist are probably less obvious, but you can get a good sense of them from the title of the episode: &#8220;What Happened When Gabe Set Himself on Fire.&#8221;</p>

<p>Like chemistry labs, mechanical testing labs have their own set of dangers, most of which involve the sudden, unexpected release of strain energy. You learned about strain energy in high school physics, although your teacher probably didn&#8217;t call it that. Shortly after learning about the forces in springs and Hooke&#8217;s Law, <span class="MathJax_Preview">[F = kx]</span><script type="math/tex">F = kx</script> (a topic we&#8217;ve looked at here <a href="http://www.leancrew.com/all-this/2010/07/bathroom-scales-and-robert-hooke/">once</a> or <a href="http://www.leancrew.com/all-this/2012/12/khan/">twice</a>), you learned that the potential energy<sup id="fnref:joke"><a href="#fn:joke" rel="footnote">2</a></sup> stored in a spring is expressed by this formula:</p>

<span class="MathJax_Preview">[\frac{1}{2}k\;x^2]</span><script type="math/tex; mode=display">\frac{1}{2}k\;x^2</script>

<p>The <span class="MathJax_Preview">[k]</span><script type="math/tex">k</script> in the formula is the spring constant, which is a measure of how stiff the spring is. It&#8217;s measured in units like pounds per inch or newtons per millimeter—force per length—and is always a positive value. The <span class="MathJax_Preview">[x]</span><script type="math/tex">x</script> is the amount, as measured in inches or millimeters or some other unit of length, the spring has stretched from its natural, unloaded length. The sign convention for <span class="MathJax_Preview">[x]</span><script type="math/tex">x</script> is arbitrary, but it&#8217;s usually taken that positive values of <span class="MathJax_Preview">[x]</span><script type="math/tex">x</script> represent lengthening of the spring and negative values represent shortening.</p>

<p>You see, then, that because <span class="MathJax_Preview">[x]</span><script type="math/tex">x</script> is squared, the potential energy in the spring is either zero (when the spring is at its natural length) or positive. This makes sense because potential energy is defined as the ability to do work. A  compressed spring is able to do just as much work as a stretched spring, so their potential energies should be the same and should have the same sign. And a spring that&#8217;s neither stretched nor compressed can&#8217;t do any work, so its potential energy should be zero. So far, so good.</p>

<p>The reason Hooke&#8217;s Law works on a macro scale for things like coiled springs is that a very similar sort of law works on a micro scale within the spring wire. On the micro scale, the force-displacement relationship, <span class="MathJax_Preview">[F = kx]</span><script type="math/tex">F = kx</script>, is replaced by a similar relationship between stresses (which are like forces) and strains (which are derived from deformations). In the same way that the potential energy stored in a spring is a function of its stretch, the potential energy in any deformed body is a function of its strain. Hence the term &#8220;strain energy.&#8221;</p>

<p>The details I&#8217;ve glossed over in the previous paragraph would fill, and do fill, volumes. My shoulders are sore from all the hand-waving, but I&#8217;ll push on.</p>

<p>When it comes to the ability to do harm, not all strains are created equal. It&#8217;s only the elastic strains—those which can be reversed when the load is removed—that present a danger. If you stretch a rubber band in front of your face and let go, it&#8217;ll snap back and hit you in the nose. That won&#8217;t happen if you do the same thing with a ring of Play-Doh. In a mechanical testing lab, we&#8217;re usually applying very large forces to parts and materials that have a lot of reversable elastic strain. And when things break, whether intentionally or unintentionally, the huge strain energy that&#8217;s built up as the parts have been loaded is suddenly released and turned into kinetic energy. Lab safety is all about directing that kinetic energy to where it won&#8217;t hurt anyone.</p>

<p>Which brings us, finally, to my son and the screw heads. One weekend a few months ago he was helping me finish up a few tests. The tests were intended to break things, and I had barriers set up to block any pieces that might come flying out at us. And of course we were wearing goggles. The tests went smoothly and no one came close to getting hurt.</p>

<p>We ran into a snag while taking the equipment apart. One of the pieces of the test fixture was a pipe clamped in place by four capscrews like this one:</p>

<p><a href="http://www.flickr.com/photos/drdrang/8749757199/"><img class="ss" src="http://farm3.staticflickr.com/2864/8749757199_f0cb81e035_o.jpg" alt="Capscrew" title="Capscrew" /></a></p>

<p class="source">Source: <a href="http://littlemachineshop.com/products/product_view.php?ProductID=1529">littlemachineshop.com</a></p>

<p>A side view of the clamping arrangement looked like this, with two screws on the top and two on the bottom (you see only one in each position because its mate is behind it). The screws passed through unthreaded holes in the blue piece and screwed into threaded holes in the green piece.</p>

<p><a href="http://www.flickr.com/photos/drdrang/8743296398/"><img class="ss" src="http://farm8.staticflickr.com/7289/8743296398_2d7bf6c729_z.jpg" alt="Clamp" title="Clamp" /></a></p>

<p>I had clamped and loosened this pipe many times over the previous month of testing, and internal hex surfaces of the capscrews had rounded out. Finally, after the testing was over, the Allen wrench wouldn&#8217;t grip in the screwheads and I couldn&#8217;t loosen the clamp and remove the pipe.</p>

<p>So I grabbed a hacksaw, slid its blade down the gap between the blue and green pieces, and drew it back to start cutting. That&#8217;s when I noticed my son standing to the left, directly in line with the screw heads.</p>

<p>Let me digress at this moment of high tension<sup id="fnref:slay"><a href="#fn:slay" rel="footnote">3</a></sup> and explain how bolts and screws work. Most people know that bolted joints<sup id="fnref:bolts"><a href="#fn:bolts" rel="footnote">4</a></sup> require sufficient torque to do their job. Many of you have probably used a torque wrench at one time or another. But most people don&#8217;t realize that torque, in and of itself, is meaningless. Bolted joints work because of the tension in the bolts, not the torque. The purpose of applying torque to a bolt is to use the mechanical advantage of the thread (which is essentially an inclined plane wrapped around in a helix) to stretch the bolt and induce tension in it. There are, in fact, bolting systems in which a hydraulic machine stretches a bolt directly by pulling on its tail and then spins the nut up tight to maintain that stretch—no torque of any significance is ever applied.</p>

<p>The word &#8220;stretch&#8221; in the previous paragraph should prick up you ears. Strain energy is stored in every fully tightened bolt because that bolt has been stretched. When such a bolt breaks or is cut, that strain energy gets released somehow, often by sending the bolt head flying.</p>

<p>In this case, there&#8217;s even more strain energy available. The flanges on the two clamp pieces are bent under the load of the screws. When the screws are cut, they&#8217;ll straighten back out, acting as a catapult to fling the screw heads.</p>

<p>&#8220;You need to move around to the other side,&#8221; I said.</p>

<p>&#8220;Why?&#8221;</p>

<p>&#8220;Because when I cut through, these screws are going to shoot out like bullets, and you&#8217;re standing in the way.&#8221;</p>

<p>&#8220;Really?&#8221; I should mention that my son is sixteen years old and therefore assumes that I&#8217;m full of shit. But he moved anyway.</p>

<p>I did a suprisingly good job of cutting evenly through the two top screws, and they snapped almost simultaneously. The screw heads shot across the lab and hit a piece of plywood leaning against the opposite wall with a loud <em>th-thunk</em>. I was vindicated; when I had to cut another recalcitrant screw a few minutes later, he stayed well out of the line of fire.</p>

<p>While I was happy to have proved myself not entirely full of shit, I was annoyed at my brief lapse. I&#8217;d been careful during the test but let my guard down briefly during disassembly. I should never have even picked up the hacksaw before clearing him out of the way. Strain energy is not to be messed with.</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:pun">
<p>You may not get that joke yet, but <a href="http://onlyamodel.com/">Ben Deaton</a> is laughing his ass off right now.&#160;<a href="#fnref:pun" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:joke">
<p>Yes, that was the joke.&#160;<a href="#fnref:joke" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:slay">
<p>I slay me.&#160;<a href="#fnref:slay" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:bolts">
<p>There is a technical difference between bolts and screws, but it has nothing to do with this discussion, so I&#8217;m going to use the words interchangably from now on.&#160;<a href="#fnref:bolts" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.leancrew.com/all-this/2013/05/now-we-see-the-violence-inherent-in-hookes-law/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>A simple Drafts work diary</title>
		<link>http://www.leancrew.com/all-this/2013/05/a-simple-drafts-work-diary/</link>
		<comments>http://www.leancrew.com/all-this/2013/05/a-simple-drafts-work-diary/#comments</comments>
		<pubDate>Wed, 15 May 2013 03:50:11 +0000</pubDate>
		<dc:creator>Dr. Drang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[drafts]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://www.leancrew.com/all-this/?p=2071</guid>
		<description><![CDATA[Topics for posts are piling up and I don&#8217;t have time to write them up. I&#8217;ve recently plotted out posts on The dangers of stored strain energy and how I avoided shooting my older son with the head of a screw when he helped me run some load tests a couple of months ago. This&#8230;]]></description>
				<content:encoded><![CDATA[<p>Topics for posts are piling up and I don&#8217;t have time to write them up. I&#8217;ve recently plotted out posts on</p>

<ol>
<li>The dangers of stored strain energy and how I avoided shooting my older son with the head of a screw when he helped me run some load tests a couple of months ago. This topic was inspired by <a href="http://www.70decibels.com/generational/2013/5/4/033-what-happened-when-gabe-set-himself-on-fire.html">the May 4 episode of the <em>Generational</em> podcast</a>, in which Erik Hess and Gabe Weatherhead discussed the dangers of their former workplaces and Gabe&#8217;s propensity for setting himself on fire.</li>
<li>Thermal stresses and why <a href="https://twitter.com/KatieFloyd/status/333675338833989632">Katie Floyd&#8217;s glass baking dish blew up</a> on Mother&#8217;s Day. This one would harken back to <a href="http://www.howtospotapsychopath.com/2012/02/09/is-pyrex-pyrex/">Dan Rutter&#8217;s post on Pyrex</a>, which I read through <a href="http://www.marco.org/2012/02/09/is-pyrex-pyrex">a link from Marco Arment</a>.</li>
<li>The alleged design and craftsmanship in <a href="https://www.genmfg.co/products/7/langley-churchkey">this artisanal bottle opener</a> which <a href="http://hypertext.net/2013/05/langley-churchkey/">Justin Blanton made the unforgivable mistake of ordering</a>.</li>
<li>How revisiting the comic books I loved as a teen has left me disappointed in both the writing and the artwork. The one exception is the early Conan series by <a href="http://en.wikipedia.org/wiki/Roy_Thomas">Roy Thomas</a> and <a href="http://barrywindsor-smith.com/">Barry Windsor-Smith</a>, and that&#8217;s probably because I&#8217;ve always seen myself as a latter-day Conan—black-haired, sullen-eyed, sword in hand, a thief, a reaver, a slayer, with gigantic melancholies and gigantic mirth.</li>
</ol>

<p>And that doesn&#8217;t include more topical posts that I&#8217;ve given up on writing because their time has passed.</p>

<p>So tonight I&#8217;m taking the easy way out, with a short post about <a href="https://itunes.apple.com/us/app/drafts/id502385074?mt=8&amp;partnerId=30&amp;siteID=L4JhWyGwYTM">the iOS Drafts app</a> inspired by David and Katie&#8217;s recent <a href="http://5by5.tv/mpu/136">iOS Automation episode of <em>Mac Power Users</em></a> and by <a href="http://www.70decibels.com/generational/2013/5/11/034-developing-workflow-software-with-greg-pierce.html">the <em>Generational</em> episode with Greg Pierce</a>,<sup id="fnref:kill"><a href="#fn:kill" rel="footnote">1</a></sup> the developer of Drafts.</p>

<p>Last night I asked a stupid question about Drafts on Twitter:</p>

<div class="bbpBox" id="t334114977801711616">
<blockquote>
<span class="twContent">Y’know what’d be great? If <a href="http://twitter.com/draftsapp">@draftsapp</a> could append to a Dropbox file named according to the date, creating the file if necessary.</span><span class="twMeta"><br /><span class="twDecoration">&mdash; </span><span class="twRealName">Dr. Drang</span><span class="twDecoration"> (</span><a href="http://twitter.com/drdrang"><span class="twScreenName">@drdrang</span></a><span class="twDecoration">) </span><a href="https://twitter.com/drdrang/status/334114977801711616"><span class="twTimeStamp">Mon May 13 2013 8:16 PM CDT</span></a><span class="twDecoration"></span></span>
</blockquote>
</div>

<p>It was stupid because Drafts can already do what I was asking for, as several kind people told me without snickering. Here&#8217;s the Dropbox action I came up with:</p>

<p><a href="http://www.flickr.com/photos/drdrang/8739249533/"><img class="ss" src="http://farm8.staticflickr.com/7292/8739249533_a748ef9ede_z.jpg" alt="Drafts work diary" title="Drafts work diary" /></a></p>

<p>In my defense, the reason I didn&#8217;t realize I could use a date tag (the thing inside the doubled square brackets) in the name of the file is the name of the option that must be chosen with it: Predefined. It just didn&#8217;t seem right to me that a file with a predefined name could have its name defined on the fly. Also, it seemed superfluous to have a Timestamp option for the file name if a timestamp could be provided through tags. Still, the ability to use tags in file names goes back to <a href="http://agiletortoise.com/blog/2013/02/08/drafts-v2-5-3-and-drafts-for-ipad-v1-5-3/">version 2.5.3</a>—I should have known about it.</p>

<p>Anyway,<sup id="fnref:anyways"><a href="#fn:anyways" rel="footnote">2</a></sup> this action is intended to help me keep track of what I&#8217;m doing at work, what the action described at the end of <a href="http://www.leancrew.com/all-this/2013/02/new-flexible-timestamps-in-drafts/">this post</a> should&#8217;ve been. The idea is to launch Drafts when I switch from one task to another, tap in (or dictate) what I&#8217;m about to start working on, and invoke this action. Each time, a pair of lines will be added to a diary file for that day, one with the timestamp and the other with the note I wrote for it. Like this:</p>

<pre><code>1:14 PM
Started 200° test

1:45 PM
Ended 200° test

1:54 PM
Started 300° test
</code></pre>

<p>The improvement over the old system is that now I&#8217;ll have a separate file for each day, all in the same Diary folder in Dropbox. To me, this is a more natural way to organize diary entries, rather than having them all with time <em>and</em> date stamps in a single big file. Each day&#8217;s file will have a name like <code>2013-05-14.txt</code>.</p>

<p>This is, in many ways, the same sort of thing Katie Floyd is doing with <a href="https://itunes.apple.com/us/app/day-one-journal-diary/id421706526?mt=8&amp;partnerId=30&amp;siteID=L4JhWyGwYTM">Day One</a>. I like Day One, but I prefer using plain text files in case there comes a time when I want to run some script over my diary files to extract information. I have no plans to do that, but I want leave open the possibility.</p>

<p>Of course the real trick isn&#8217;t coming up with a Drafts action, it&#8217;s developing and maintaining the discipline to make an entry every time I switch contexts. I&#8217;m working on that.</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:kill">
<p>Gabe and Erik have been killing it on <em>Generational</em>. You really should make room for it in your listening schedule.&#160;<a href="#fnref:kill" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:anyways">
<p>Have I ever mentioned how much I hate the non-word &#8220;anyways&#8221;? Once limited to the sort of people who say &#8220;irregardless,&#8221; it&#8217;s now everywhere, tormenting me.&#160;<a href="#fnref:anyways" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.leancrew.com/all-this/2013/05/a-simple-drafts-work-diary/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Cleaning out Clean My Mac</title>
		<link>http://www.leancrew.com/all-this/2013/05/cleaning-out-clean-my-mac/</link>
		<comments>http://www.leancrew.com/all-this/2013/05/cleaning-out-clean-my-mac/#comments</comments>
		<pubDate>Mon, 13 May 2013 02:40:33 +0000</pubDate>
		<dc:creator>Dr. Drang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[utilities]]></category>

		<guid isPermaLink="false">http://www.leancrew.com/all-this/?p=2070</guid>
		<description><![CDATA[I just got a notification on my computer from Clean My Mac 2, a utility I bought as part of the recent MacHeist nanoBundle. I have nothing against CMM2—it does a fine job of scanning my disk and finding files that might be good to delete—but I don&#8217;t want it nagging me to do so.&#8230;]]></description>
				<content:encoded><![CDATA[<p>I just got a notification on my computer from <a href="http://macpaw.com/cleanmymac">Clean My Mac 2</a>, a utility I bought as part of the <a href="http://www.leancrew.com/all-this/2013/04/macheist-nano/">recent MacHeist nanoBundle</a>. I have nothing against CMM2—it does a fine job of scanning my disk and finding files that might be good to delete—but I don&#8217;t want it nagging me to do so. So I went searching for how that notification was sent.</p>

<p>I didn&#8217;t have to look far. The natural place for scheduled, periodic tasks to live is in your <code>~/Library/LaunchAgents</code> folder. And that&#8217;s exactly where I found a couple of Launch Agent <code>plist</code> files from CMM2.</p>

<p><a href="http://www.flickr.com/photos/drdrang/8734118610/"><img class="ss" src="http://farm8.staticflickr.com/7288/8734118610_ca61299757_z.jpg" alt="Clean My Mac Launch Agents" title="Clean My Mac Launch Agents" /></a></p>

<p>A quick review of the <code>plist</code> file shows that the scheduled scan is set to run on the 12th and 19th of the month. I installed CMM2 late last month, so it&#8217;s not surprising that today was the first day I saw the notification.</p>

<p>I didn&#8217;t want to delete the <code>plist</code> files (they might be useful later), but I did want to stop them, so I ran</p>

<pre><code>launchctl unload -w ~/Library/LaunchAgents/com.macpaw.CleanMyMac2Helper.scheduledScan.plist
</code></pre>

<p>and</p>

<pre><code>launchctl unload -w ~/Library/LaunchAgents/com.macpaw.CleanMyMac2Helper.trashWatcher.plist
</code></pre>

<p>from the Terminal. Running the <a href="http://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/launchctl.1.html"><code>launchctl</code> command</a> to look for other MacPaw processes</p>

<pre><code>launchctl list | grep macpaw
</code></pre>

<p>showed that there was still a CMM2 Helper process running, so I opened Activity Monitor and killed it.</p>

<p><a href="http://www.flickr.com/photos/drdrang/8733032091/"><img class="ss" src="http://farm8.staticflickr.com/7286/8733032091_8f8d3dc270_z.jpg" alt="Activity Monitor with CMM2 Helper" title="Activity Monitor with CMM2 Helper" /></a></p>

<p>I suppose I could&#8217;ve edited the <code>plist</code> files to add a Disabled key, but I find running <code>launchctl</code> easier. I&#8217;m always worried that I&#8217;ll add an item at the wrong nesting level when I edit XML files.</p>

<p>I&#8217;m not going to rant against MacPaw for installing processes without telling me, because it&#8217;s entirely possible it <em>did</em> tell me and I didn&#8217;t pay attention. Either way, I shouldn&#8217;t get that unwanted notification again.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leancrew.com/all-this/2013/05/cleaning-out-clean-my-mac/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Bite me</title>
		<link>http://www.leancrew.com/all-this/2013/05/bite-me/</link>
		<comments>http://www.leancrew.com/all-this/2013/05/bite-me/#comments</comments>
		<pubDate>Sat, 11 May 2013 03:40:02 +0000</pubDate>
		<dc:creator>Dr. Drang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[flashlight]]></category>

		<guid isPermaLink="false">http://www.leancrew.com/all-this/?p=2069</guid>
		<description><![CDATA[Earlier today, Gabe Weatherhead recommended a very powerful compact flashlight. It&#8217;s a nice product, I&#8217;m sure, but it&#8217;s missing one feature that I&#8217;ve come to find very important in a flashlight: biteability. You know what I mean. You&#8217;re working in the dark and need both hands free. Where does your flashlight go? In your mouth,&#8230;]]></description>
				<content:encoded><![CDATA[<p>Earlier today, <a href="http://www.macdrifter.com/2013/05/an-860-lumen-compact-flashlight.html">Gabe Weatherhead recommended</a> a very powerful compact flashlight. It&#8217;s a nice product, I&#8217;m sure, but it&#8217;s missing one feature that I&#8217;ve come to find very important in a flashlight: biteability.</p>

<p>You know what I mean. You&#8217;re working in the dark and need both hands free. Where does your flashlight go? In your mouth, of course. And to keep it pointed in the right direction, you need to be able to grip it between your teeth, so a metal barrel is out of the question. For several years now, I&#8217;ve been using a <a href="http://www.amazon.com/gp/product/B00252W2SY?ie=UTF8&amp;tag=andnowitsal05-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B00252W2SY">Brinkmann 3-watt LED Armor Max</a> flashlight that runs on 3 AAA batteries. It has a plastic body with a rubbery grip around the barrel that makes it very tooth-friendly. It&#8217;s nowhere near as bright as Gabe&#8217;s, but it&#8217;s always been more than bright enough for my needs.</p>

<p><a href="http://www.amazon.com/gp/product/B00252W2SY?ie=UTF8&amp;tag=andnowitsal05-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=B00252W2SY"><img class="ss" src="http://ecx.images-amazon.com/images/I/41CSN8u7G2L.jpg" alt="Brinkmann 3 watt flashlight" title="Brinkmann 3 watt flashlight" /></a></p>

<p>Yes, you can buy headband-mounted flashlights, but the great thing about this Brinkman is that it works perfectly well as a regular flashlight, and under normal circumstances you won&#8217;t look like a dork using it. And while you <em>will</em> look like a dork when you put it in your mouth, you only need to do that when there&#8217;s no one around to hold the flashlight for you and, therefore, no one around to see how dorky you look. Self-correcting!</p>

<p>I didn&#8217;t set out to find a biteable flashlight. I just happened to buy a Brinkmann because it was bright, compact, and water-resistant (O-rings seal the screw-on caps at either end) and learned later how helpful it was to have a flashlight I could hold comfortably in my teeth.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leancrew.com/all-this/2013/05/bite-me/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>TextExpander date snippets via bash</title>
		<link>http://www.leancrew.com/all-this/2013/05/textexpander-date-snippets-via-bash/</link>
		<comments>http://www.leancrew.com/all-this/2013/05/textexpander-date-snippets-via-bash/#comments</comments>
		<pubDate>Thu, 09 May 2013 02:52:55 +0000</pubDate>
		<dc:creator>Dr. Drang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[calendar]]></category>
		<category><![CDATA[textexpander]]></category>

		<guid isPermaLink="false">http://www.leancrew.com/all-this/?p=2068</guid>
		<description><![CDATA[You have, presumably seen this post by David Sparks, in which he provides a bunch of TextExpander snippets for showing dates and times in different formats, some of which involve calendrical calculations. That&#8217;s a combination of topics I simply cannot resist commenting on. First, if you download his snippet collection and double-click on the file,&#8230;]]></description>
				<content:encoded><![CDATA[<p>You have, presumably seen <a href="http://macsparky.com/blog/2013/5/text-expander-snippets-date-and-time">this post by David Sparks</a>, in which he provides a bunch of <a href="https://itunes.apple.com/us/app/textexpander-for-mac/id405274824?mt=12&amp;partnerId=30&amp;siteID=L4JhWyGwYTM">TextExpander</a> snippets for showing dates and times in different formats, some of which involve calendrical calculations. That&#8217;s a combination of topics I simply cannot resist commenting on.</p>

<p>First, if you download his snippet collection and double-click on the file, it&#8217;ll be imported into its own folder in TextExpander. If you already have some date snippets—and I suspect most of you do—you don&#8217;t have to worry that David&#8217;s will overwrite or get mixed in with the ones you already have.</p>

<p><a href="http://www.flickr.com/photos/drdrang/8722265864/"><img class="ss" src="http://farm8.staticflickr.com/7454/8722265864_ae104d017a_z.jpg" alt="MacSparky date snippets" title="MacSparky date snippets" /></a></p>

<p>Second, you&#8217;ll notice that most of David&#8217;s abbreviations start with <em>x</em>. He uses that the same way <a href="http://www.leancrew.com/all-this/2010/03/textexpander-abbreviation-design/">I use the semicolon</a>: as a signal character that makes it easy to come up with meaningful abbreviations that don&#8217;t conflict with real words. By using a letter instead of a punctuation character, David can sync his snippets between his Mac and his iOS devices and not have to worry about his abbreviations requiring a trip to a secondary iOS keyboard. I&#8217;d use this except for the fact that I often use variable names that start with <em>x</em>,<sup id="fnref:x"><a href="#fn:x" rel="footnote">1</a></sup> and my fear of conflicts is greater than my desire for snippet harmony.</p>

<p>Finally, and most interestingly, David has a few snippets for inserting dates that are for some date in the future. I&#8217;ve made <a href="http://www.leancrew.com/all-this/2011/06/a-couple-of-textexpander-thingies/">similar snippets</a>, but mine have always been for a fixed number of days from today. David&#8217;s are more subtle. As you can see from the screenshot, he has snippets for things like &#8220;next Monday&#8221; and &#8220;next Friday.&#8221; TextExpander&#8217;s built-in date calculation commands can&#8217;t handle things like that, so David&#8217;s snippets use AppleScript (written by <a href="http://www.automatedworkflows.com/">Ben Waldie</a>).</p>

<p>I wrote <a href="http://www.leancrew.com/all-this/2012/09/eight-days-a-week/">a post about these kinds of calculations</a> last fall, discussing both AppleScript and Python solutions. In the comments to that post, David Cross (<a href="https://twitter.com/roguemonk">@roguemonk</a>) pointed out a clever use of the <a href="https://developer.apple.com/library/mac/#documentation/Darwin/Reference/Manpages/man1/date.1.html"><code>date</code> command</a> that blew me away. It manages to do these same calculations in way that&#8217;s both more compact and easier to understand at a glance. The technique relies on the use of <code>date</code>&#8217;s <code>-v</code> option.</p>

<p>Let&#8217;s say you want to replicate the &#8220;Next Monday&#8221; snippet shown above. The <code>date</code> invocation that&#8217;ll do it is</p>

<pre><code>bash:
date -v +1d -v +mon +"%Y-%m-%d"
</code></pre>

<p>Like the AppleScript in the screenshot, this gives you the next Monday (<code>-v +mon</code>) after (<code>-v +1d</code>) today.<sup id="fnref:v"><a href="#fn:v" rel="footnote">2</a></sup> <sup id="fnref:next"><a href="#fn:next" rel="footnote">3</a></sup> The formatting of the date is done through the familiar <a href="https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/strftime.3.html"><code>strftime</code> library</a> used by lots of Unix utilities and programming languages.</p>

<p>To make this command work in TextExpander, you need to add the shebang line for bash and you probably want to use <code>echo -n</code> to suppress the linefeed that <code>date</code> adds to the end. Your final snippet would look like this:</p>

<pre><code>bash:
#!/bin/bash
echo -n `date -v +1d -v +mon +"%Y-%m-%d"`
</code></pre>

<p>Next Friday would look like this:</p>

<pre><code>bash:
#!/bin/bash
echo -n `date -v +1d -v +fri +"%Y-%m-%d"`
</code></pre>

<p>And so on. The great advantage of this approach is that the <code>strftime</code> format is much more flexible than what you can get out of AppleScript. Just look at the contortions poor Ben had to go through to get a simple year-month-date format. If you wanted a format like &#8220;8 May 2013,&#8221; the <code>date</code> specifier would be easy to change:</p>

<pre><code>bash:
#!/bin/bash
echo -n `date -v +1d -v +mon +"%-d %b %Y"`
</code></pre>

<p>I realize that writing this post so close on the heels last week&#8217;s <a href="http://www.leancrew.com/all-this/2013/05/unsolicited-textexpander-advice/">gentle poke at Merlin Mann</a> makes it look like I&#8217;m taking on the role of TextExpander policeman. But if I could control my obsessions they wouldn&#8217;t be obsessions, would they?</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:x">
<p>Contrary to popular opinion, variable names that start with <em>x</em> aren&#8217;t necessarily a recipe for obscure code. I write scripts that do coordinate calculations, and the variables that represent the x-, y-, and z-coordinates of points often start with those letters.&#160;<a href="#fnref:x" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:v">
<p>The order of the <code>-v</code> options is important, as they&#8217;re applied sequentially. In this case, we start by moving forward a day and then look for the &#8220;next&#8221; Monday. If the order of the <code>-v</code>&#8217;s were reversed, we&#8217;d go to the next Monday and then step forward a day, landing on a Tuesday.&#160;<a href="#fnref:v" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:next">
<p>If tomorrow <em>is</em> a Monday, that&#8217;s the date that&#8217;ll be returned. The <em>+</em> sign for day-of-week searches works more like <em>≥</em> than <em>></em>.&#160;<a href="#fnref:next" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.leancrew.com/all-this/2013/05/textexpander-date-snippets-via-bash/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Sidebar affiliate links</title>
		<link>http://www.leancrew.com/all-this/2013/05/sidebar-affiliate-links/</link>
		<comments>http://www.leancrew.com/all-this/2013/05/sidebar-affiliate-links/#comments</comments>
		<pubDate>Tue, 07 May 2013 04:45:21 +0000</pubDate>
		<dc:creator>Dr. Drang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://www.leancrew.com/all-this/?p=2067</guid>
		<description><![CDATA[If you&#8217;re reading this on the site rather than through an RSS reader, you&#8217;ll see that the sidebar over on the right has changed. Gone are the Flickr photos, which I hadn&#8217;t updated since the fall, and the tag cloud, which I doubt that anyone used. In their place are affiliate links to Amazon, the&#8230;]]></description>
				<content:encoded><![CDATA[<p>If you&#8217;re reading this on the site rather than through an RSS reader, you&#8217;ll see that the sidebar over on the right has changed. Gone are the Flickr photos, which I hadn&#8217;t updated since the fall, and the tag cloud, which I doubt that anyone used. In their place are affiliate links to Amazon, the Mac App Store, and the iOS App Store.</p>

<p>As I mentioned <a href="http://www.leancrew.com/all-this/2013/01/lucre/">a few months ago</a>, I&#8217;m not entirely comfortable with conventional web ads on the site, but I have no problem with affiliate links. I&#8217;ve been using them in my posts for quite a while when I recommend an application or book or pen or whatever. Now they&#8217;ll be in the sidebar.</p>

<p>I&#8217;ll certainly be tweaking the format, but what you see now is—in broad terms, if not in detail—the way I expect it to stay: an Amazon product, a Mac application, and an iOS app. A decent-sized image of each, with a sentence or two from me explaining why I recommend it. At present, the text appears when you hover over the image via the <code>title</code> attribute. That was easy to implement, but isn&#8217;t a permanent solution because hovering isn&#8217;t a concept that applies to touch devices. A popup system that works just as well on mobile and the desktop will be one of my first changes.<sup id="fnref:fn"><a href="#fn:fn" rel="footnote">1</a></sup></p>

<p>At present, I expect to switch the recommendations every week or two, but we&#8217;ll see how that works out. I&#8217;m notoriously lazy<sup id="fnref:flickr"><a href="#fn:flickr" rel="footnote">2</a></sup> and may leave some links up for longer.</p>

<p>I have, of course, written a couple of scripts to make it easier to add the link code to my WordPress template. Here&#8217;s the script that generates the Amazon link:</p>

<pre><code>python:
 1:  #!/usr/bin/python
 2:  
 3:  from amazonproduct import API
 4:  import sys
 5:  import re
 6:  
 7:  # Get the item's ID from the URL on the command line.
 8:  itemID = re.search(r'dp/([^/?%]+)', sys.argv[1]).group(1)
 9:  # print itemID
10:  # sys.exit()
11:  
12:  # Login.
13:  api = API('myaccesskey', 'mysecretkey', 'us', 'myassociateID')
14:  
15:  # Lookup the item.
16:  node = api.item_lookup(itemID, ResponseGroup="Images,Small")
17:  itemURL = node.Items.Item.DetailPageURL
18:  imageURL = node.Items.Item.LargeImage.URL
19:  author = node.Items.Item.ItemAttributes.Author
20:  title = node.Items.Item.ItemAttributes.Title
21:  
22:  # Print the HTML to be added to the sidebar
23:  print '''&lt;p&gt;
24:    &lt;a href="{0}"&gt;&lt;img src="{1}" alt="{2} by {3}" title="" /&gt;&lt;/a&gt;
25:  &lt;/p&gt;'''.format(itemURL, imageURL, title, author)
</code></pre>

<p>This takes the URL of an Amazon product as its command-line argument and returns the HTML link code. To use it requires an <a href="https://affiliate-program.amazon.com/gp/associates/network/main.html">Amazon Associates</a> account, a <a href="https://affiliate-program.amazon.com/gp/advertising/api/detail/main.html">Product Advertising API</a> account, and the <a href="https://pypi.python.org/pypi/python-amazon-product-api/"><code>python-amazon-product-api</code> library</a>.</p>

<p>The comments in the script pretty much tell you what&#8217;s going on. You&#8217;ll want to edit Line 8 to use your own API access and secret keys and your own Associate ID. Lines 17-20 show how deeply nested the return values are; figuring out how to extract the fields I needed was the most difficult part of this script.</p>

<p>The script is called this way:</p>

<pre><code>amazon-sidebar-link 'http://www.amazon.com/Idiot-America-Stupidity-Became-Virtue/dp/0767926153/ref=la_B001IQXNKY_1_1?ie=UTF8&amp;qid=1367898622&amp;sr=1-1' | pbcopy
</code></pre>

<p>The URL is put in single quotes to keep the ampersands (and any other special characters) from being interpreted by the shell. I typically use <a href="https://github.com/drdrang/te-url-snippets">my <code>;furl</code> TextExpander snippet</a> to insert the URL of the page I&#8217;m browsing so I don&#8217;t have to jump back and forth between the Terminal and the browser. Piping the output through <a href="https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man1/pbcopy.1.html"><code>pbcopy</code></a> puts the HTML output into the clipboard, ready for pasting into the template.</p>

<p>A similar script uses the <a href="https://pypi.python.org/pypi/python-itunes/1.0"><code>python-itunes</code> library</a> to access the <a href="http://www.apple.com/itunes/affiliates/resources/documentation/itunes-store-web-service-search-api.html">iTunes Search API</a>:</p>

<pre><code>python:
 1:  #!/usr/bin/python
 2:  
 3:  import itunes
 4:  import re
 5:  import sys
 6:  
 7:  # Get the item ID from the URL on the command line.
 8:  itemID = re.search(r'/id([^/?%]+)', sys.argv[1]).group(1)
 9:  # print itemID
10:  # sys.exit()
11:  
12:  # Lookup the item.
13:  item = itunes.lookup(itemID)
14:  itemURL = item.get_url() + "&amp;uo=4&amp;partnerId=30&amp;siteID=mysiteID"
15:  imageURL = item.get_artwork()['512']
16:  name = item.get_name()
17:  publisher = item.get_artist()
18:  
19:  # Print the HTML to be added to the sidebar
20:  print '''&lt;p&gt;
21:    &lt;a href="{0}"&gt;&lt;img src="{1}" alt="{2} by {3}" title="" /&gt;&lt;/a&gt;
22:  &lt;/p&gt;'''.format(itemURL, imageURL, name, publisher)
</code></pre>

<p>Here, the only things you&#8217;ll need to edit are the <code>siteID</code> item and (possibly) the <code>uo</code> and <code>partnerID</code> items<sup id="fnref:uo"><a href="#fn:uo" rel="footnote">3</a></sup> in Line 14. You&#8217;ll need to be a member of <a href="http://www.apple.com/itunes/affiliates/">Apple&#8217;s Affiliate program</a> to get those items. This script is called exactly the same way as the Amazon script above. The argument is the URL of the <code>itunes.apple.com</code> web page for the product.</p>

<p>To help me find the right web page quickly, I use Google&#8217;s site-specific searching restriction. For example, a search on</p>

<pre><code>bbedit site:itunes.apple.com
</code></pre>

<p>brings me immediately to the page I want. Of course, I have a TextExpander snippet that expands to <code>site:itunes.apple.com</code>.</p>

<p>It&#8217;d be nice to get the product ID number directly from iTunes or the App Store application, but I don&#8217;t know how.</p>

<p>You&#8217;ll notice that in each script, I leave the <code>title</code> attribute of the <code>&lt;img&gt;</code> blank. That&#8217;s where I add my comment on the item after pasting the output into my blog template.</p>

<p>This site doesn&#8217;t get enough traffic for the earnings on affiliate links amount to much, but they should allow the site to pay for itself. Actually, only iTunes/App Store earnings come to me. Earnings from the Amazon account go to my daughter who, unlike many her age, didn&#8217;t come back to <s>sponge off</s> live with her parents after college. It&#8217;s not enough to pay for her coffee habit, but it helps.</p>

<div class="update">

<p><strong>Update 5/7/13</strong><br />
I should&#8217;ve mentioned that the images used in the links—which are served directly from Amazon and Apple—are larger than what you see in the sidebar. That&#8217;s because the CSS for the sidebar has <code>max-width</code> and <code>max-height</code> settings that tell the browser to scale the images down. This wastes a little bandwidth, but I don&#8217;t have to redesign the sidebar to match the size of the images Amazon and Apple deliver.</p>

</div>

<div class="footnotes">
<hr />
<ol>

<li id="fn:fn">
<p>And I should probably apply that solution—whatever it turns out to be—to footnotes, too.&#160;<a href="#fnref:fn" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:flickr">
<p>See Flickr comment above.&#160;<a href="#fnref:flickr" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:uo">
<p>I confess I&#8217;ve forgotten whether those items are generic or specific to your account, and I just don&#8217;t feel like looking it up (see earlier comment on laziness). If your affiliate links use different values, then they must be account-specific.&#160;<a href="#fnref:uo" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.leancrew.com/all-this/2013/05/sidebar-affiliate-links/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Unsolicited TextExpander advice</title>
		<link>http://www.leancrew.com/all-this/2013/05/unsolicited-textexpander-advice/</link>
		<comments>http://www.leancrew.com/all-this/2013/05/unsolicited-textexpander-advice/#comments</comments>
		<pubDate>Fri, 03 May 2013 05:21:53 +0000</pubDate>
		<dc:creator>Dr. Drang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[applescript]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[textexpander]]></category>

		<guid isPermaLink="false">http://www.leancrew.com/all-this/?p=2066</guid>
		<description><![CDATA[This afternoon, Merlin Mann tweeted a link to a set of his TextExpander snippets: As requested, here’s a few of the random TextExpander 4 snippets I mentioned in Back to Work #116:i-0.us/18vNRnM&#8212; Merlin Mann (@hotdogsladies) Thu May 2 2013 2:41 PM CDT I will not comment on how foolish I think it is for Merlin&#8230;]]></description>
				<content:encoded><![CDATA[<p>This afternoon, Merlin Mann tweeted a link to <a href="https://www.dropbox.com/s/mye9ot7wx9v5t09/mdm-te-snippets.md">a set of his TextExpander snippets</a>:</p>

<div class="bbpBox" id="t330044307941781505">
<blockquote>
<span class="twContent">As requested, here’s a few of the random TextExpander 4 snippets I mentioned in Back to Work #116:<br /><br /><a href="http://i-0.us/18vNRnM">i-0.us/18vNRnM</a></span><span class="twMeta"><br /><span class="twDecoration">&mdash; </span><span class="twRealName">Merlin Mann</span><span class="twDecoration"> (</span><a href="http://twitter.com/hotdogsladies"><span class="twScreenName">@hotdogsladies</span></a><span class="twDecoration">) </span><a href="https://twitter.com/hotdogsladies/status/330044307941781505"><span class="twTimeStamp">Thu May 2 2013 2:41 PM CDT</span></a><span class="twDecoration"></span></span>
</blockquote>
</div>

<p>I will <em>not</em> comment on how foolish I think it is for Merlin use abbreviations without some signaling character. I will <em>not</em> mention how really smart people like John Gruber and Jason Snell (semicolon men) and Brett Terpstra and Gabe Weatherhead (double comma men) design their abbreviations with signaling characters because doing so frees you from the necessity of devising unique, nonword abbreviations, a necessity that seems easy at first but turns into a pain in the ass when you have dozens of abbreviations to wrangle. No, I won&#8217;t say that because that would be churlish and discourteous to someone who&#8217;s always been very generous to me. Besides, <a href="http://www.leancrew.com/all-this/2010/03/textexpander-abbreviation-design/">I&#8217;ve already said it</a> (<a href="http://www.leancrew.com/all-this/2011/09/why-is-this-key-different-from-all-other-keys/">more than once</a>).</p>

<p>Instead, I&#8217;m going to suggest a possible improvement to one of Merlin&#8217;s snippets that will save countless seconds. The snippet in question is his &#8220;Better YouTube Link,&#8221; which is defined this way:</p>

<pre><code>[**%filltext:name=artist% - "%filltext:name=Title%"**](http://www.youtube.com/watch?v=%clipboard) %|
</code></pre>

<p>You see that it requires the clipboard to be prefilled with the unique ID string of the video you want to link to. Which means you have to select the ID from the address field of your browser and then copy it to the clipboard before switching back to wherever you&#8217;re typing to invoke the snippet. Wouldn&#8217;t it be nicer if TextExpander could just extract that ID from your browser on its own? That&#8217;s the improvement I have in mind.</p>

<p>What&#8217;s needed is another snippet, an AppleScript snippet that extracts the ID from the URL of the frontmost tab of your frontmost browser window. If you use Safari, that snippet would look like this:</p>

<pre><code>applescript:
tell application "Safari" to set ytURL to URL of front document
do shell script ("perl -e 'if ($ARGV[0]=~/[?&amp;]v=([^&amp;]+)/){print $1}' " &amp; ytURL)
</code></pre>

<p>And if your browser is Chrome, it would look like this:</p>

<pre><code>applescript:
tell application "Google Chrome"
  set frontIndex to active tab index of front window
  set ytURL to URL of tab frontIndex of front window
end tell
do shell script ("perl -e 'if ($ARGV[0]=~/[?&amp;]v=([^&amp;]+)/){print $1}' " &amp; ytURL)
</code></pre>

<p>If you sometimes use Safari and sometimes use Chrome, you could use this:</p>

<pre><code>applescript:
tell application "System Events"
  set numSafari to count (every process whose name is "Safari")
  set numChrome to count (every process whose name is "Google Chrome")
end tell

if numSafari &gt; 0 then
  tell application "Safari" to set ytURL to URL of front document
else
  if numChrome &gt; 0 then
    tell application "Google Chrome"
      set frontIndex to active tab index of front window
      set ytURL to URL of tab frontIndex of front window
    end tell

  end if
end if


do shell script ("perl -e 'if ($ARGV[0]=~/[?&amp;]v=([^&amp;]+)/){print $1}' " &amp; ytURL)
</code></pre>

<p>If you have both Safari and Chrome running at the same time, this one will try to get the ID from the frontmost tab of Safari. This may not be what you want, but I don&#8217;t know how to make the script read your mind.</p>

<p>Anyway, give that snippet a good abbreviation, like <code>;ytid</code>, and then define a new snippet that&#8217;s very much like Merlin&#8217;s:</p>

<pre><code>[**%filltext:name=name:default=Artist% - "%filltext:name=Title%"**](http://www.youtube.com/watch?v=%snippet:;ytid%) %|
</code></pre>

<p>Notice that this one uses the <code>;ytid</code> snippet instead of the clipboard to fill in the video ID string. TextExpander&#8217;s ability to call one snippet from within another allows you to use snippets like subroutines.</p>

<p>Obviously, I&#8217;m assuming that the most common situation in which you&#8217;d use the Better YouTube Link snippet is when you have the video in the frontmost tab and you want to create a Markdown link to it in your text editor. If that&#8217;s not the case—if, for example, you usually want to create the link in a text entry field in another browser tab—then this won&#8217;t be an improvement for you. Stick with Merlin&#8217;s original. (But change the abbreviation to start with a semicolon.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leancrew.com/all-this/2013/05/unsolicited-textexpander-advice/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Afghanistan, April 2013</title>
		<link>http://www.leancrew.com/all-this/2013/05/afghanistan-april-2013/</link>
		<comments>http://www.leancrew.com/all-this/2013/05/afghanistan-april-2013/#comments</comments>
		<pubDate>Thu, 02 May 2013 23:54:16 +0000</pubDate>
		<dc:creator>Dr. Drang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[afghanistan]]></category>
		<category><![CDATA[politics]]></category>
		<category><![CDATA[war]]></category>

		<guid isPermaLink="false">http://www.leancrew.com/all-this/?p=2065</guid>
		<description><![CDATA[Yes, I&#8217;m back with this post again. And we&#8217;re still getting our young people killed for no reason.]]></description>
				<content:encoded><![CDATA[<p>Yes, I&#8217;m back with this post again. And we&#8217;re still getting our young people killed for no reason.</p>

<p><a href="http://leancrew.com/all-this/images2012/ac-2013-04.png"><img class="ss" src="http://leancrew.com/all-this/images2012/ac-2013-04-t.png" alt="Afghanistan, April 2013" title="Afghanistan, April 2013" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.leancrew.com/all-this/2013/05/afghanistan-april-2013/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PCalc 2.8</title>
		<link>http://www.leancrew.com/all-this/2013/05/pcalc-2-8/</link>
		<comments>http://www.leancrew.com/all-this/2013/05/pcalc-2-8/#comments</comments>
		<pubDate>Wed, 01 May 2013 16:11:23 +0000</pubDate>
		<dc:creator>Dr. Drang</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[calculator]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[pcalc]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.leancrew.com/all-this/?p=2064</guid>
		<description><![CDATA[If you followed my advice back in December, you bought PCalc for the ridiculously low price of 99¢ during its 20th anniversary sale1 and have been using a first-class calculator for the past four months. With Version 2.8 just released, you&#8217;re going to see its value explode with two new features: user-defined conversions and user-defined&#8230;]]></description>
				<content:encoded><![CDATA[<p>If you followed <a href="http://www.leancrew.com/all-this/2012/12/pcalc-rides-again/">my advice back in December</a>, you bought <a href="https://itunes.apple.com/us/app/pcalc-the-best-calculator/id284666222?mt=8&amp;partnerId=30&amp;siteID=L4JhWyGwYTM">PCalc</a> for the ridiculously low price of 99¢ during its 20th anniversary sale<sup id="fnref:anniv"><a href="#fn:anniv" rel="footnote">1</a></sup> and have been using a first-class calculator for the past four months. With Version 2.8 just released, you&#8217;re going to see its value explode with two new features: user-defined conversions and user-defined functions.</p>

<p>PCalc added an <em>f(x)</em> key in Version 2.6 as a way to access functions beyond those available on the keys. Initially, the additional functions were limited to whatever the developer, James Thomson, gave us. Here&#8217;s me, back in December:</p>

<blockquote>
  <p>What I’d really like to see, though, is an expansion of these functions. Things like present value, future value, and internal rate of return are natural for the financial section. And the statistical section could use functions for the normal and inverse normal cumulative distribution.</p>
</blockquote>

<p>This was not based on any insider knowledge. High-end calculators have been programmable since the 70s, so it was only natural to expect that functionality to come to PCalc eventually. We just had to wait for James to figure out how he wanted to implement it.<sup id="fnref:rules"><a href="#fn:rules" rel="footnote">2</a></sup></p>

<p>In this post, I&#8217;m going to focus on creating user-defined functions. The creation of user-defined conversions follows almost exactly the same steps and has access to the same set of commands—once you&#8217;ve learned how to define functions, you&#8217;ll have no trouble defining conversions.</p>

<h2>Creating a new function</h2>

<p>Start by tapping the <em>f(x)</em> key to see the list of function categories and then tap the Edit key in the lower left corner. You&#8217;ll get a ⊞ key in the upper right corner, which will allow you to add new categories. As you can see below, I&#8217;ve added three categories: Financial 2, Probability, and Weather.</p>

<p><a href="http://www.flickr.com/photos/drdrang/8687969712/"><img class="ss" src="http://farm9.staticflickr.com/8394/8687969712_19abb7c9b9_z.jpg" alt="Defining PCalc function categories" title="Defining PCalc function categories" /></a></p>

<p>Tapping the ⊞ key on this screen will create a new category. Tapping that category takes you to a screen where you can rename it and then start defining new functions.</p>

<p><a href="http://www.flickr.com/photos/drdrang/8686871909/"><img class="ss" src="http://farm9.staticflickr.com/8397/8686871909_50c1a613a8_z.jpg" alt="Renaming a new function category" title="Renaming a new function category" /></a></p>

<p>Tapping the new function takes you to a screen where you can rename and define it. PCalc starts you off with two commands: one that puts you in decimal mode (if you weren&#8217;t already there) and one that multiplies the current value by the universal constant.</p>

<p><a href="http://www.flickr.com/photos/drdrang/8688002070/"><img class="ss" src="http://farm9.staticflickr.com/8546/8688002070_7656d9e800_z.jpg" alt="Defining a new function" title="Defining a new function" /></a></p>

<p>You can change these by tapping them, which will take you to a command editing screen we&#8217;ll discuss in a bit, and add new commands by tapping the ⊞ key.</p>

<h2>The command set</h2>

<p>PCalc gives you 39 commands from which to build your function. Here they are, with descriptions, as they appear in the scrolling list you see as you construct your function.</p>

<p><a href="http://www.flickr.com/photos/drdrang/8685190299/"><img class="ss" src="http://farm9.staticflickr.com/8406/8685190299_e0eea41233_o.png" alt="PCalc command descriptions" title="PCalc command descriptions" /></a></p>

<p>Seven of the commands have only one part—the command itself with no arguments. These are typically commands that set the calculation mode, like the Decimal Mode command we saw above or the Radians Mode command.</p>

<p><a href="http://www.flickr.com/photos/drdrang/8686932567/"><img class="ss" src="http://farm9.staticflickr.com/8124/8686932567_0dc7f3ba85_o.png" alt="One-part command" title="One-part command" /></a></p>

<p>Seventeen of the commands have two parts, in which you have to choose both the command itself and a single argument. The trig, log, and exponential commands work this way, as does the Clear command.</p>

<p><a href="http://www.flickr.com/photos/drdrang/8686932491/"><img class="ss" src="http://farm9.staticflickr.com/8404/8686932491_7c77ec4c75_o.png" alt="Two-part command" title="Two-part command" /></a></p>

<p>We&#8217;ll discuss how to set the argument in a bit.</p>

<p>Nine of the commands have three parts: the command and two arguments. The basic arithmetic commands (My Dear Aunt Sally) fall into this category, as does the command that sets a register.</p>

<p><a href="http://www.flickr.com/photos/drdrang/8688048610/"><img class="ss" src="http://farm9.staticflickr.com/8257/8688048610_78a54225f1_o.png" alt="Three-part command" title="Three-part command" /></a></p>

<p>Finally, six of the commands have four parts: the command and three arguments. These are all branching commands that test one value against another and skip a given number of steps if the test is true.</p>

<p><a href="http://www.flickr.com/photos/drdrang/8686931097/"><img class="ss" src="http://farm9.staticflickr.com/8535/8686931097_ffa36a3187_o.png" alt="Four-part command" title="Four-part command" /></a></p>

<h2>Variables and constants</h2>

<p>Numerical functions need places where they can store numbers and retrieve them from. PCalc provides 29 such places: the X and Y registers, ten memory locations, sixteen registers, and a special register called Tax Rate used in some of the builtin financial functions. In addition to these read/write variables, there are three read-only constants: Pi (π), a uniformly distributed random number between 0 and 1,<sup id="fnref:rnd"><a href="#fn:rnd" rel="footnote">3</a></sup> and a user-defined constant called Value.</p>

<p>Here&#8217;s PCalc&#8217;s scrolling list of variables and constants you can choose from. If you&#8217;re setting or changing a value, the constants don&#8217;t appear in the list.</p>

<p><a href="http://www.flickr.com/photos/drdrang/8688085998/"><img class="ss" src="http://farm9.staticflickr.com/8544/8688085998_ea33a1a7bf_o.png" alt="PCalc variables and constants" title="PCalc variables and constants" /></a></p>

<p>The X and Y registers and the memory locations are accessible any time you&#8217;re using PCalc. Registers 0-9, A-F, and the Tax Rate are accessible only through the programming environment; they&#8217;re the best place to store intermediate results because they don&#8217;t alter what the user has stored in memory.</p>

<p><s>At present,</s> PCalc does <em>not</em> clear these registers after a function is calculated. <s>The Tax Rate register will certainly stay this way, but I don&#8217;t know if that&#8217;s true about the others, so you&#8217;re taking a bit of a risk if you write functions that rely on their persistence.</s></p>

<p><strong>Update</strong>: James says the persistence of the registers is part of the design, so it&#8217;s safe to take advantage of that if you want.</p>

<h2>A simple example</h2>

<p>Let&#8217;s look at a five-step function for calculating the future value of an investment. The formula is elementary:</p>

<span class="MathJax_Preview">[FV = PV \; (1 + i)^n]</span><script type="math/tex; mode=display">FV = PV \; (1 + i)^n</script>

<p>where <span class="MathJax_Preview">[FV]</span><script type="math/tex">FV</script> is the future value, <span class="MathJax_Preview">[PV]</span><script type="math/tex">PV</script> is the present value, <span class="MathJax_Preview">[i]</span><script type="math/tex">i</script> is the interest rate per compounding period, and <span class="MathJax_Preview">[n]</span><script type="math/tex">n</script> is the number of compounding periods.</p>

<p>The function I defined calculates just the <span class="MathJax_Preview">[(1 + i)^n]</span><script type="math/tex">(1 + i)^n</script> part. It gives, in effect, the multiplier associated with the compounding. Here&#8217;s the function defined in PCalc:</p>

<p><a href="http://www.flickr.com/photos/drdrang/8687048431/"><img class="ss" src="http://farm9.staticflickr.com/8118/8687048431_3992a89a2d_o.png" alt="Future value" title="Future value" /></a></p>

<p>It expects the interest rate in the Y register and the number of compounding periods in the X register; it returns the future value multiplier in the X register. To run this function in RPN mode, which is what I use, you type in the interest rate, tap Enter, type in the number of compounding periods, and then select the Future Value function from under the <em>f(x)</em> key. In algebraic mode, you type in the interest rate, tap the x~y key, type the number of compounding periods, and then select the Future Value function from under the <em>f(x)</em> key. It&#8217;s the same amount of work either way.</p>

<p>James has decided that functions that need more than two arguments will have to use the memory locations for the extra arguments. I&#8217;d much prefer to be able to load up the RPN stack with all my arguments (it&#8217;s faster than entering values into memory), but that would leave the algebraic users out in the cold.</p>

<h2>Sharing functions</h2>

<p>You can share the functions you write with others by tapping the share button and sending an email with the functions bundled up in an attachment. When the recipient gets the email, she can tap on the attachment and choose to import them into her copy of PCalc.</p>

<p>It&#8217;s my understanding that functions you define on one iOS device will be automatically available on your other iOS devices through iCloud syncing. With only an iPhone, I have no way of testing this.</p>

<h2>Programming on your computer</h2>

<p>For functions with only a few steps, the tap-scroll-tap method of creating functions on an iPhone or iPad is just fine. But for more complicated functions, it&#8217;s easy to get lost and make mistakes. Fortunately, there&#8217;s a way to program PCalc in your favorite text editor.</p>

<p>When you send an email with a shared bundle of functions, the attachment is a plist file with a <code>.pcalcfunctions</code> extension. If you save this file to your computer, you can open it in a text editor to see the usual plist structure. Each function is a <code>&lt;dict&gt;</code>, with its code stored in a string using a compact little language. Here&#8217;s definition of the Future Value function described above:</p>

<pre><code>xml:
&lt;key&gt;function.user.579085775.3922504026&lt;/key&gt;
&lt;dict&gt;
  &lt;key&gt;Code&lt;/key&gt;
  &lt;string&gt;set r0 1; add r0 y; pwr r0 x; clr y; set x r0&lt;/string&gt;
  &lt;key&gt;Name&lt;/key&gt;
  &lt;string&gt;Future Value&lt;/string&gt;
&lt;/dict&gt;
</code></pre>

<p>If we rearrange the string of code, it&#8217;s easy to see how it relates to our definition above.</p>

<pre><code>set r0 1
add r0 y
pwr r0 x
clr y
set x r0
</code></pre>

<p>This shows us the path to writing long, complicated functions:</p>

<ol>
<li>Create a new function in PCalc. Give it the name you want and put it in the category you want, but don&#8217;t bother changing the definition from the two-command default we saw near the top of the post.</li>
<li>Share that function with yourself via email. Open the email on your computer and save the attached <code>.pcalcfunctions</code> file to disk.</li>
<li>Write the function you really want in the little language used in the <code>,pcalcfunctions</code> plist. I write mine with each command on its own line and then do a search-and-replace to turn it into a long, semicolon separated string.</li>
<li>Replace the default commands in the <code>.pcalcfunctions</code> file with what you just wrote.</li>
<li>Send yourself an email with the edited <code>.pcalcfunctions</code> file attached.</li>
<li>Open that attachment on your iOS device to install the redefined function. It&#8217;ll replace the old definition.</li>
</ol>

<p>This may seem like too many steps, but it&#8217;s much easier than writing a long function directly in PCalc.</p>

<p>One of the functions I wanted is the cumulative distribution function for the standard normal. There is one of those integrals that can&#8217;t be performed analytically, so it has to be approximated. Here&#8217;s a good approximation from <a href="http://people.math.sfu.ca/~cbm/aands/">Abramowitz and Stegun</a>:</p>

<p><a href="http://www.flickr.com/photos/drdrang/8643036867/"><img class="ss" src="http://farm9.staticflickr.com/8381/8643036867_21d31f9c7a_z.jpg" alt="Standard Normal CDF" title="Standard Normal CDF" /></a></p>

<p>And here&#8217;s that formula (generalized to handle negative arguments) converted into a PCalc function:</p>

<pre><code>set r0 x
bgt x 0 1
  neg r0
set r1 r0
mul r1 .2316419
add r1 1
inv r1
set r2 r1
mul r2 .319381530
set r3 r1
pwr r3 2
mul r3 -.356563782
add r2 r3
set r3 r1
pwr r3 3
mul r3 1.781477937
add r2 r3
set r3 r1
pwr r3 4
mul r3 -1.821255978
add r2 r3
set r3 r1
pwr r3 5
mul r3 1.330274429
add r2 r3
pwr r0 2
div r0 2
neg r0
exp r0
set r3 2
mul r3 pi
pwr r3 .5
div r0 r3
mul r0 r2
blt x 0 3
  set x 1
  sub x r0
  stp
set x r0
</code></pre>

<p>It&#8217;s much faster to type the lines than to scroll through the list choosing commands and registers, and it&#8217;s easier to see the overall logic this way.</p>

<h2>All the command abbreviations</h2>

<p>The main difficulty in writing PCalc functions in a text editor is figuring out what the abbreviations are for each of the commands. To help with this, I created, in PCalc, a fake function with 37 steps—one for each of the commands. After sharing this function and opening the <code>.pcalcfunctions</code> file on my computer, I extracted all the commands. Here they are with their default arguments and an explanatory comment:</p>

<pre><code>set x 42      # Set X to 42
clr x         # Clear X
add x 42      # Add 42 to X
sub x 42      # Subtract 42 from X
mul x 42      # Multiply X by 42
div x 42      # Divide X by 42
neg x         # Negate X
inv x         # Invert X
pwr x 42      # Raise X to the power of 42
roo x 42      # Raise X to the power of 1/42
sin x         # Sine of X
cos x         # Cosine of X
tan x         # Tangent of X
asn x         # Arcsine of X
acs x         # Arccosine of X
atn x         # Arctangent of X
ln x          # Natural log of X
log x         # Base 10 log of X
exp x         # e to the power of X
e10 x         # 10 to the power of X
fac x         # Factorial of X
rnd x         # Round X to nearest integer
trn x         # Truncate X to nearest integer
hyp x 42      # Hypotenuse of triangle with legs X and 42
leg x 42      # Leg of triangle with hypotenuse and other leg of X and 42 
dec           # Decimal mode
hex           # Hex mode
oct           # Octal mode
bin           # Binary mode
deg           # Degrees mode
rad           # Radians mode
jmp 1         # Skip 1 step
beq x 42 1    # Skip 1 step if X is equal to 42
bne x 42 1    # Skip 1 step if X is not equal to 42
bgt x 42 1    # Skip 1 step if X is greater than 42
bge x 42 1    # Skip 1 step if X is greater than or equal to 42
blt x 42 1    # Skip 1 step if X is less than 42
ble x 42 1    # Skip 1 step if X is less than or equal to 42
stp           # Stop
</code></pre>

<p>These are in the same order as the screenshot list. Most of the names are immediately obvious; others take a little thinking to understand. The inverse power command, <code>roo</code>, is short for <em>root</em>.<sup id="fnref:roo"><a href="#fn:roo" rel="footnote">4</a></sup> The <em>b</em> at the front of <code>beq</code> and the other skip commands is short for <em>branch</em>. The only one I&#8217;ve had trouble remembering is <code>pwr</code>, which I tend to type as <code>pow</code>.</p>

<h2>Finally</h2>

<p>A calculator isn&#8217;t necessarily the best tool for complicated analyses, but sometimes it&#8217;s the best tool that&#8217;s readily available. Because PCalc is in my phone, its capabilities—whatever they are—are always with me. The addition of user-defined functions allows me to do calculations away from my desk that I couldn&#8217;t do before.</p>

<p>This post wasn&#8217;t intended to be a breezy read. Its main purpose is to act as a reference to help you (and me) get new functions written. I don&#8217;t know if James intends to host a repository of functions at <a href="http://www.pcalc.com/">pcalc.com</a>, but I&#8217;ll be putting all my functions in <a href="https://github.com/drdrang/pcalc-functions">this GitHub repository</a>. At present, it has three sets of functions:</p>

<ul>
<li><code>Financial 2.pcalcfunctions</code>. This has the future value function shown above, a present value function, and a loan payment function.</li>
<li><code>Probability.pcalcfunctions</code>. This has the standard normal PDF, CDF, and inverse CDF.</li>
<li><code>Weather.pcalcfunctions</code>. This has functions for calculating the wind chill factor and the heat index. </li>
</ul>

<p>The README is pretty rudimentary at the moment, but it does explain the inputs and outputs of each function. I&#8217;ll be adding better explanations of the underlying calculations soon.</p>

<div class="footnotes">
<hr />
<ol>

<li id="fn:anniv">
<p>How can an iOS app be 20 years old? Strictly speaking, it can&#8217;t, but its older cousin, PCalc for the Mac, <em>was</em> 20 years old in December, and iOS PCalc joined the celebration.&#160;<a href="#fnref:anniv" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:rules">
<p>There may also have been a question about the iOS developer rules. Programmability used to be a no-no, but with things like <a href="https://itunes.apple.com/us/app/pythonista/id528579881?mt=8&amp;partnerId=30&amp;siteID=L4JhWyGwYTM">Pythonista</a> that restriction has clearly been lifted.&#160;<a href="#fnref:rules" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:rnd">
<p>OK, a random number isn&#8217;t a constant, but I lumped it in with the constants because it can&#8217;t be written to.&#160;<a href="#fnref:rnd" rev="footnote">&#8617;</a></p>
</li>

<li id="fn:roo">
<p>If you were thinking it had something to do with Winnie the Pooh, you&#8217;ve got the wrong beloved English author in mind. If James were going to name a command after a character, it&#8217;d be Zaphod Beeblebrox, which would be tough to squeeze into three characters, even with Unicode.&#160;<a href="#fnref:roo" rev="footnote">&#8617;</a></p>
</li>

</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.leancrew.com/all-this/2013/05/pcalc-2-8/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
	</channel>
</rss>
