<?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>Il Filosofo &#187; filosofo</title>
	<atom:link href="http://ilfilosofo.com/blog/author/filosofo/feed/" rel="self" type="application/rss+xml" />
	<link>http://ilfilosofo.com</link>
	<description>A blog about philosophy, Christianity, web development and whatever else I feel like writing about.</description>
	<lastBuildDate>Fri, 12 Mar 2010 04:29:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=3.0-alpha</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>New WordPress Plugin: Custom Image Sizes</title>
		<link>http://ilfilosofo.com/blog/2010/03/11/plugin-creates-wordpress-thumbnails-on-demand/</link>
		<comments>http://ilfilosofo.com/blog/2010/03/11/plugin-creates-wordpress-thumbnails-on-demand/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 04:29:22 +0000</pubDate>
		<dc:creator>filosofo</dc:creator>
				<category><![CDATA[WordPress]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[plugins]]></category>

		<guid isPermaLink="false">http://ilfilosofo.com/?p=593</guid>
		<description><![CDATA[I make a lot of WordPress themes, and frequently clients want to associate a particular size of image with a post.  You can do this easily with WordPress by using add_image_size() to define an image and then by calling wp_get_attachment_image() later to print the markup for that image.
So for example, if I have an [...]]]></description>
			<content:encoded><![CDATA[<p>I make a lot of WordPress themes, and frequently clients want to associate a particular size of image with a post.  You can do this easily with WordPress by using <code>add_image_size()</code> to define an image and then by calling <code>wp_get_attachment_image()</code> later to print the markup for that image.</p>
<p>So for example, if I have an attachment image of ID number 123, I might do something like the following:</p>
<pre>

add_image_size( 'my-custom-size', 220, 180, true );
...
echo wp_get_attachment_image( 123, 'my-custom-size' );
</pre>
<p>Here, <code>add_image_size()</code> defines the custom thumbnail (in this example the arguments tell <code>add_image_size()</code> to make it 220 pixels wide, 180 high, and cropped), and </p>
<pre>echo wp_get_attachment_image()</pre>
<p>prints the markup of the image itself, <code>&lt;img&gt;</code> element and everything.</p>
<h3>The Problem</h3>
<p>This works great; WordPress even creates thumbnails in this size from now on.  The problem is that it doesn&#8217;t apply to pre-existing thumbnails.  And if people change their minds about what sizes they want their thumbnails to be (clients sometimes change their minds) you&#8217;re stuck with existing thumbnails of the wrong size.</p>
<p>In addition, if you call <code>wp_get_attachment_image( 123, 'my-custom-size' );</code> and that size doesn&#8217;t exist, WordPress just scales down the larger-sized original image, which might cause some performance issues.</p>
<h3>Solution: Custom Image Sizes</h3>
<p>My solution is the <a href="/blog/wordpress-plugins/filosofo-custom-image-sizes/">Custom Image Sizes plugin</a>.  You activate it, and if you call <code>wp_get_attachment_image()</code> and related functions for an attachment that doesn&#8217;t have that size, WordPress will create it on demand.</p>
<p>As a bonus, if you pass a width and height of the desired image to <code>wp_get_attachment_image()</code> (and related functions), you can create any size image.  So for example I could create a thumbnail 50 pixels wide by 40 high of attachment 123 with the following code, where <code>'50x40'<code> is <code>'[width]x[height]'</code>:</p>
<pre>

echo wp_get_attachment_image( 123, '50x40' );
</pre>
<h3>Download</h3>
<p>You can <a href="/blog/wordpress-plugins/filosofo-custom-image-sizes/">download the Custom Image Sizes plugin here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ilfilosofo.com/blog/2010/03/11/plugin-creates-wordpress-thumbnails-on-demand/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Welcome, Benjamin!</title>
		<link>http://ilfilosofo.com/blog/2009/07/26/welcome-benjamin/</link>
		<comments>http://ilfilosofo.com/blog/2009/07/26/welcome-benjamin/#comments</comments>
		<pubDate>Sun, 26 Jul 2009 07:19:02 +0000</pubDate>
		<dc:creator>filosofo</dc:creator>
				<category><![CDATA[Friends and Family]]></category>
		<category><![CDATA[Babies]]></category>

		<guid isPermaLink="false">http://www.ilfilosofo.com/?p=549</guid>
		<description><![CDATA[My second son, Benjamin Eliot, was born today at 3:19 CDT, weighing 8lbs. 15oz. and 21 inches long.  Like his older sister he was born VBAC, and like his older brother he has a full head of hair. 
]]></description>
			<content:encoded><![CDATA[<p>My second son, Benjamin Eliot, was born today at 3:19 CDT, weighing 8lbs. 15oz. and 21 inches long.  <a href="http://www.ilfilosofo.com/blog/2007/12/17/welcome-maggie/">Like his older sister he was born VBAC</a>, and <a href="http://www.ilfilosofo.com/blog/2006/06/08/sam-matzko/">like his older brother he has a full head of hair</a>. </p>
<p>
<a href='http://ilfilosofo.com/blog/2009/07/26/welcome-benjamin/austin_ben/' title='Proud Daddy'><img width="150" height="150" src="http://ilfilosofo.com/wp-content/uploads/austin_ben-150x150.jpg" class="attachment-thumbnail" alt="Proud Daddy" title="Proud Daddy" /></a>
<a href='http://ilfilosofo.com/blog/2009/07/26/welcome-benjamin/ben_bath/' title='Ben getting a bath'><img width="150" height="150" src="http://ilfilosofo.com/wp-content/uploads/ben_bath-150x150.jpg" class="attachment-thumbnail" alt="Ben getting a bath" title="Ben getting a bath" /></a>
<a href='http://ilfilosofo.com/blog/2009/07/26/welcome-benjamin/ben_head/' title='Cozy in his blanket'><img width="150" height="150" src="http://ilfilosofo.com/wp-content/uploads/ben_head-150x150.jpg" class="attachment-thumbnail" alt="Ben cozy in his blanket" title="Cozy in his blanket" /></a>
<a href='http://ilfilosofo.com/blog/2009/07/26/welcome-benjamin/ben_table/' title='Ben in his baby cart'><img width="150" height="150" src="http://ilfilosofo.com/wp-content/uploads/ben_table-150x150.jpg" class="attachment-thumbnail" alt="Ben in his baby cart" title="Ben in his baby cart" /></a>
<a href='http://ilfilosofo.com/blog/2009/07/26/welcome-benjamin/melita_ben/' title='Ben and Mama'><img width="150" height="150" src="http://ilfilosofo.com/wp-content/uploads/melita_ben-150x150.jpg" class="attachment-thumbnail" alt="Ben and Mama" title="Ben and Mama" /></a>
<a href='http://ilfilosofo.com/blog/2009/07/26/welcome-benjamin/family_with_ben/' title='Family with Ben'><img width="150" height="150" src="http://ilfilosofo.com/wp-content/uploads/family_with_ben-150x150.jpg" class="attachment-thumbnail" alt="Family with Benjamin" title="Family with Ben" /></a>
</p>
]]></content:encoded>
			<wfw:commentRss>http://ilfilosofo.com/blog/2009/07/26/welcome-benjamin/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Counterexample</title>
		<link>http://ilfilosofo.com/blog/2008/10/16/counterexample/</link>
		<comments>http://ilfilosofo.com/blog/2008/10/16/counterexample/#comments</comments>
		<pubDate>Thu, 16 Oct 2008 16:29:05 +0000</pubDate>
		<dc:creator>filosofo</dc:creator>
				<category><![CDATA[Politics]]></category>
		<category><![CDATA[Psychology]]></category>
		<category><![CDATA[Bookmarks]]></category>
		<category><![CDATA[William F. Buckley]]></category>

		<guid isPermaLink="false">http://www.ilfilosofo.com/?p=507</guid>
		<description><![CDATA[From Scientific American:
Researchers insist they can tell someone&#8217;s politlcal affiliation by looking at the condition of their offices and bedrooms. Messy? You&#8217;re a lefty. A neatnik? Welcome to the Right.
According to a controversial new study, set to be published in The Journal of Political Psychology, the bedrooms and offices of liberals, who are generally thought [...]]]></description>
			<content:encoded><![CDATA[<p>From <em><a href="http://www.sciam.com/article.cfm?id=organization-and-political-leanings">Scientific American</a></em>:</p>
<blockquote><p>Researchers insist they can tell someone&#8217;s politlcal affiliation by looking at the condition of their offices and bedrooms. Messy? You&#8217;re a lefty. A neatnik? Welcome to the Right.</p>
<p>According to a controversial new study, set to be published in The Journal of Political Psychology, the bedrooms and offices of liberals, who are generally thought of as open, tend to be colorful and awash in books about travel, ethnicity, feminism and music, along with music CDs covering folk, classic and modern rock, as well as art supplies, movie tickets and travel memorabilia.</p>
<p>Conservatives, on the other hand, tend to surround themselves with calendars, postage stamps, laundry baskets, irons and sewing materials in their personal spaces, according to the study. Their bedrooms and offices are well-lighted and decorated with sports paraphernalia and flagsâespecially American ones.</p>
<p>[...]</p>
<p>&#8220;It&#8217;s pleasurable for liberals to think more. They gravitate toward art, to things that are not as concrete,&#8221; says Carney. &#8220;Conservatives have a need for order, for there not to be ambiguity. There you see that expressed by being more orderly, having more cleaning supplies, needing to have everything lined up and organized so that one feels one&#8217;s environment is predictable and therefore safe.&#8221;</p>
</blockquote>
<p>So how do they explain this?</p>
<p><img src="http://www.ilfilosofo.com/wp-content/uploads/buckley_desk.jpg" alt="William F. Buckley at his desk" title="William F. Buckley at his desk" width="600" height="418" class="alignnone size-full wp-image-508" /></p>
]]></content:encoded>
			<wfw:commentRss>http://ilfilosofo.com/blog/2008/10/16/counterexample/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>I Am an Official Regex Day Winner</title>
		<link>http://ilfilosofo.com/blog/2008/06/06/happy-regex-day-to-me/</link>
		<comments>http://ilfilosofo.com/blog/2008/06/06/happy-regex-day-to-me/#comments</comments>
		<pubDate>Sat, 07 Jun 2008 03:38:34 +0000</pubDate>
		<dc:creator>filosofo</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Regular Expressions]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[vi]]></category>

		<guid isPermaLink="false">http://www.ilfilosofo.com/?p=478</guid>
		<description><![CDATA[Ben Nadel declared June 1, 2008 the first National Regular Expression Day, and to celebrate he hosted a giveaway of regex-related prizes, including Jeffrey Friedl&#8217;s Mastering Regular Expressions.  As you can see, I won the book and got it in the mail yesterday. I use regular expressions all the time&#8212;in PHP, JavaScript, Perl, sed, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://bennadel.com/index.cfm?dax=blog:1243.view">Ben Nadel declared June 1, 2008 the first National Regular Expression Day</a>, and to celebrate he hosted a giveaway of regex-related prizes, including Jeffrey Friedl&#8217;s <a href="http://www.amazon.com/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124"><i>Mastering Regular Expressions</i></a>.  As you can see, I won the book and got it in the mail yesterday. I use <a href="http://en.wikipedia.org/wiki/Regular_expressions">regular expressions</a> all the time&#8212;in PHP, JavaScript, Perl, sed, grep, and vi&#8212;and they&#8217;re so essential to my work that I can&#8217;t wait to &#8220;master&#8221; them.  </p>
<p>I think I may have sunk to new lows of geekiness. </p>
<p><img src="http://www.ilfilosofo.com/wp-content/uploads/regex_book.jpg" alt="" title="regex_book" width="300" height="245" class="alignnone size-full wp-image-481" /></p>
]]></content:encoded>
			<wfw:commentRss>http://ilfilosofo.com/blog/2008/06/06/happy-regex-day-to-me/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Webmonkey.com Returns</title>
		<link>http://ilfilosofo.com/blog/2008/05/22/webmonkeycom-returns/</link>
		<comments>http://ilfilosofo.com/blog/2008/05/22/webmonkeycom-returns/#comments</comments>
		<pubDate>Thu, 22 May 2008 15:04:17 +0000</pubDate>
		<dc:creator>filosofo</dc:creator>
				<category><![CDATA[Web development]]></category>
		<category><![CDATA[DHTML]]></category>
		<category><![CDATA[Webmonkey]]></category>

		<guid isPermaLink="false">http://www.ilfilosofo.com/?p=466</guid>
		<description><![CDATA[When I was first learning web development about ten years ago, I frequently consulted Webmonkey.com for tutorials about how to do all things &#8220;DHTML.&#8221;  I still remember how an article comparing frames to a cafeteria tray made it all click for me, for some reason. I also picked up some bad habits that I [...]]]></description>
			<content:encoded><![CDATA[<p>When I was first learning web development about ten years ago, I frequently consulted Webmonkey.com for tutorials about how to do all things &#8220;DHTML.&#8221;  I still remember how an article comparing frames to a cafeteria tray made it all click for me, for some reason. I also picked up some bad habits that I had to unlearn later, such as using table elements for page layout. But that&#8217;s no slam against Webmonkey: they were just explaining the common web practices of the day.</p>
<p>Webmonkey stopped producing new content in the early 2000s and was sold by Wired to Lycos, I think, but much of the old content remained, such as the <a href="http://www.webmonkey.com/reference/Special_Characters">special characters reference</a>, which I consult occasionally.     Now <a href="http://www.webmonkey.com/blog/Welcome_to_the_All_New_Webmonkey">the site has been re-purchased by Wired</a>, which has decided to re-publish the tutorials on a wiki.  That&#8217;s probably the best approach if you can&#8217;t spare the staff to manage the old content, but the historian in me is bothered that <a href="http://web.archive.org/web/20030124061147/hotwired.lycos.com/webmonkey/programming/javascript/tutorials/tutorial1.html">Thau&#8217;s JavaScript tutorial</a> is gone, replaced by <a href="http://www.webmonkey.com/tutorial/JavaScript_Tutorial">something generic</a>.  Why couldn&#8217;t Webmonkey have kept the old articles intact, perhaps with a notice suggesting that a piece might be outdated and a link to the new wiki?  That&#8217;s sort of what <a href="http://www.quirksmode.org/resources.html">PPK does at Quirksmode</a>; he separates articles into &#8220;active&#8221; and &#8220;archived.&#8221;  I&#8217;m sure we can live without knowing how to code for Netscape Navigator 4, but it&#8217;s good to remember where we&#8217;ve come from, to remember how and why things have changed since then.  </p>
<p>However, Webmonkey promises to start creating new content relevant to today&#8217;s web, and that will be good news for those starting into web development.</p>
]]></content:encoded>
			<wfw:commentRss>http://ilfilosofo.com/blog/2008/05/22/webmonkeycom-returns/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>What Motivates Islamic Radicals</title>
		<link>http://ilfilosofo.com/blog/2008/05/20/what-motivates-islamic-radicals/</link>
		<comments>http://ilfilosofo.com/blog/2008/05/20/what-motivates-islamic-radicals/#comments</comments>
		<pubDate>Tue, 20 May 2008 10:58:04 +0000</pubDate>
		<dc:creator>filosofo</dc:creator>
				<category><![CDATA[Mideast]]></category>
		<category><![CDATA[Islam]]></category>
		<category><![CDATA[Terrorism]]></category>

		<guid isPermaLink="false">http://www.ilfilosofo.com/?p=463</guid>
		<description><![CDATA[A friend and I keep having different permutations of the same conversation, which revolves around this question: what is the essential explanation for Islamic terrorism?  My friend&#8217;s answer is that it&#8217;s primarily religious; in other words, that something intrinsic to Islam spurs on suicide bombers and the like.  I disagree for a number [...]]]></description>
			<content:encoded><![CDATA[<p>A friend and I keep having different permutations of the same conversation, which revolves around this question: what is the essential explanation for Islamic terrorism?  My friend&#8217;s answer is that it&#8217;s primarily religious; in other words, that something intrinsic to Islam spurs on suicide bombers and the like.  I disagree for a number of reasons: the vast majority of Muslims do not support terrorism; suicide bombings are a modern phenomenon, etc.  I&#8217;ve been arguing that the moving cause is largely political and economic.</p>
<p><a href="http://www.csmonitor.com/2008/0517/p12s04-wogi.html">A new Gallup poll</a> (HT: <a href="http://txfx.net/2008/05/19/why-do-muslims-support-violence/">Tempus Fugit</a>) suggests that we&#8217;re both wrong to a degree: Islamic radicals don&#8217;t cite religious motivations, but they&#8217;re not economically downtrodden, either. </p>
]]></content:encoded>
			<wfw:commentRss>http://ilfilosofo.com/blog/2008/05/20/what-motivates-islamic-radicals/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>OpenID Servers: Allow Redundant Means of Access</title>
		<link>http://ilfilosofo.com/blog/2008/05/08/openid-servers/</link>
		<comments>http://ilfilosofo.com/blog/2008/05/08/openid-servers/#comments</comments>
		<pubDate>Thu, 08 May 2008 14:43:57 +0000</pubDate>
		<dc:creator>filosofo</dc:creator>
				<category><![CDATA[Internet]]></category>
		<category><![CDATA[OpenID]]></category>

		<guid isPermaLink="false">http://www.ilfilosofo.com/?p=460</guid>
		<description><![CDATA[That&#8217;s the lesson I take from Kyle Neath&#8217;s critique of OpenID  (HT: Ma.tt),  from his first point, the one that I think has the most traction.  OpenID servers should allow users to associate their account with several OpenID providers, if they want, and/or an email address. 
]]></description>
			<content:encoded><![CDATA[<p>That&#8217;s the lesson I take from <a href="http://warpspire.com/features/open-id/">Kyle Neath&#8217;s critique of OpenID </a> (HT: <a href="http://ma.tt/2008/05/kyle-skips-openid/">Ma.tt</a>),  from his first point, the one that I think has the most traction.  <a href="http://openid.net/">OpenID</a> servers should allow users to associate their account with several OpenID providers, if they want, and/or an email address. </p>
]]></content:encoded>
			<wfw:commentRss>http://ilfilosofo.com/blog/2008/05/08/openid-servers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sed and Multi-Line Search and Replace</title>
		<link>http://ilfilosofo.com/blog/2008/04/26/sed-multi-line-search-and-replace/</link>
		<comments>http://ilfilosofo.com/blog/2008/04/26/sed-multi-line-search-and-replace/#comments</comments>
		<pubDate>Sat, 26 Apr 2008 17:21:15 +0000</pubDate>
		<dc:creator>filosofo</dc:creator>
				<category><![CDATA[Computers]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://www.ilfilosofo.com/?p=458</guid>
		<description><![CDATA[I&#8217;ve been experimenting with getting regular expression patterns to match over multiple lines using sed.  For example, one might want to change
&#60;p&#62;previous text&#60;/p&#62;
&#60;h2&#62;
&#60;a href=&#34;http://some-link.com&#34;&#62;A title here&#60;/a&#62;
&#60;/h2&#62;
&#60;p&#62;following text&#60;/p&#62;
to 
&#60;p&#62;previous text&#60;/p&#62;
No title here
&#60;p&#62;following text&#60;/p&#62;
sed cycles through each line of input one line at a time, so the most obvious way to match a pattern that extends [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been experimenting with getting regular expression patterns to match over multiple lines using <a href="http://en.wikipedia.org/wiki/Sed"><code>sed</code></a>.  For example, one might want to change</p>
<div class="filosofo-highlight-light html4strict" style="font-family: monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p&gt;</span></span>previous text<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;h2&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;http://some-link.com&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>A title here<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/a&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/h2&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p&gt;</span></span>following text<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span></div>
<p>to </p>
<div class="filosofo-highlight-light html4strict" style="font-family: monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p&gt;</span></span>previous text<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span><br />
No title here<br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;p&gt;</span></span>following text<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/p&gt;</span></span></div>
<p><code>sed</code> cycles through each line of input one line at a time, so the most obvious way to match a pattern that extends over several lines is to concatenate all the lines into what is called <code>sed</code>&#8217;s &#8220;hold space,&#8221; then look for the pattern in that (long) string.  That&#8217;s what I do in the following lines:</p>
<div class="filosofo-highlight-light bash" style="font-family: monospace;"><span style="color: #808080; font-style: italic;">#!/bin/sh</span><br />
<span style="color: #c20cb9; font-weight: bold;">sed</span> -n <span style="color: #ff0000;">'<br />
# if the first line copy the pattern to the hold buffer<br />
1h<br />
# if not the first line then append the pattern to the hold buffer<br />
1!H<br />
# if the last line then ...<br />
$ {<br />
&nbsp; &nbsp; &nbsp; &nbsp; # copy from the hold to the pattern buffer<br />
&nbsp; &nbsp; &nbsp; &nbsp; g<br />
&nbsp; &nbsp; &nbsp; &nbsp; # do the search and replace<br />
&nbsp; &nbsp; &nbsp; &nbsp; s/&lt;h2.*&lt;/h2&gt;/No title here/g<br />
&nbsp; &nbsp; &nbsp; &nbsp; # print<br />
&nbsp; &nbsp; &nbsp; &nbsp; p<br />
}<br />
'</span> sample.php <span style="color: #000000; font-weight: bold;">&gt;</span> sample-edited.php;</div>
<p>A more compact version: </p>
<div class="filosofo-highlight-light bash" style="font-family: monospace;"><br />
<span style="color: #c20cb9; font-weight: bold;">sed</span> -n <span style="color: #ff0000;">'1h;1!H;${;g;s/&lt;h2.*&lt;/h2&gt;/No title here/g;p;}'</span> sample.php <span style="color: #000000; font-weight: bold;">&gt;</span> sample-edited.php;<br />
&nbsp;</div>
<p>As far as I can tell, that&#8217;s the most efficient way to match general multi-line patterns.  I initially thought it might be more efficient not to keep the complete input in the hold buffer, so I modified the algorithm to print out the string whenever a match is found:</p>
<div class="filosofo-highlight-light bash" style="font-family: monospace;"><br />
<span style="color: #808080; font-style: italic;">#!/bin/sh</span><br />
<span style="color: #c20cb9; font-weight: bold;">sed</span> -n <span style="color: #ff0000;">'1h <br />
1!{<br />
&nbsp; &nbsp; &nbsp; &nbsp; # if the sought-after regex is not found, append the pattern space to hold space<br />
&nbsp; &nbsp; &nbsp; &nbsp; /&lt;h2.*&lt;/h2&gt;/ !H<br />
&nbsp; &nbsp; &nbsp; &nbsp; # copy hold space into pattern space<br />
&nbsp; &nbsp; &nbsp; &nbsp; g<br />
&nbsp; &nbsp; &nbsp; &nbsp; # if the regex is found, then...<br />
&nbsp; &nbsp; &nbsp; &nbsp; /&lt;h2.*&lt;/h2&gt;/ {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # the regular expression<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; s/&lt;h2.*&lt;/h2&gt;/No title here/g<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # print <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # read the next line into the pattern space<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # copy the pattern space into the hold space<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; &nbsp; &nbsp; # copy pattern buffer into hold buffer<br />
&nbsp; &nbsp; &nbsp; &nbsp; h<br />
}<br />
# if the last line then print<br />
$p<br />
'</span> sample.php <span style="color: #000000; font-weight: bold;">&gt;</span> sample-edited.php;<br />
&nbsp;</div>
<p>In the last example, <code>sed</code> concatenates lines only until it finds a match, and then it prints the line (after substituting the text).  Then, it starts again to concatenate the following lines.  </p>
<p>However, that approach is usually massively inefficient, as the regex work increases logarithmically.  Unless a <code>sed</code> guru can point out a better way, I&#8217;m going to continue using the first approach.  </p>
<p>I&#8217;ve put the following script, which I call &#8220;<code>sedml</code>,&#8221; for <code>sed</code> multi-line, in my bash path.</p>
<div class="filosofo-highlight-light bash" style="font-family: monospace;"><span style="color: #808080; font-style: italic;">#!/bin/sh</span><br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">$</span>#&quot;</span> -lt <span style="color: #000000;">2</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span> <br />
<span style="color: #000000; font-weight: bold;">then</span><br />
<span style="color: #7a0874; font-weight: bold;">exit</span>;<br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #808080; font-style: italic;"># change the input file if no 3rd argument</span><br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> -z <span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">$</span>3&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">outputfile=</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">$</span>1&quot;</span><br />
<span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #007800;">outputfile=</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">$</span>3&quot;</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #c20cb9; font-weight: bold;">sed</span> -n <span style="color: #ff0000;">'<br />
# if the first line copy the pattern to the hold buffer<br />
1h<br />
# if not the first line then append the pattern to the hold buffer<br />
1!H<br />
# if the last line then ...<br />
$ {<br />
&nbsp; &nbsp; &nbsp; &nbsp; # copy from the hold to the pattern buffer<br />
&nbsp; &nbsp; &nbsp; &nbsp; g<br />
&nbsp; &nbsp; &nbsp; &nbsp; # do the search and replace<br />
&nbsp; &nbsp; &nbsp; &nbsp; '</span><span style="color: #ff0000;">&quot;<span style="color: #000099; font-weight: bold;">$</span>2&quot;</span><span style="color: #ff0000;">'<br />
&nbsp; &nbsp; &nbsp; &nbsp; # print<br />
&nbsp; &nbsp; &nbsp; &nbsp; p<br />
}<br />
'</span> $<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">&gt;</span> $<span style="color: #000000;">1</span>.tmp;<br />
<span style="color: #c20cb9; font-weight: bold;">mv</span> -f $<span style="color: #000000;">1</span>.tmp <span style="color: #007800;">$outputfile</span>;<br />
&nbsp;</div>
<p>So I can replace multi-line patterns in multiple files like so:</p>
<div class="filosofo-highlight-light bash" style="font-family: monospace;">&nbsp;<span style="color: #c20cb9; font-weight: bold;">grep</span> -rl <span style="color: #ff0000;">'&lt;h2'</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> i; <span style="color: #000000; font-weight: bold;">do</span> sedml <span style="color: #007800;">$i</span> <span style="color: #ff0000;">&quot;s/&lt;h2.*&lt;/h2&gt;/No title here/g&quot;</span> <span style="color: #007800;">$i</span>.tmp; <span style="color: #000000; font-weight: bold;">done</span>;</div>
]]></content:encoded>
			<wfw:commentRss>http://ilfilosofo.com/blog/2008/04/26/sed-multi-line-search-and-replace/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>McDonald&#8217;s Spaced Out</title>
		<link>http://ilfilosofo.com/blog/2008/04/16/mcdonalds-and-astrophysics/</link>
		<comments>http://ilfilosofo.com/blog/2008/04/16/mcdonalds-and-astrophysics/#comments</comments>
		<pubDate>Wed, 16 Apr 2008 16:31:42 +0000</pubDate>
		<dc:creator>filosofo</dc:creator>
				<category><![CDATA[Education]]></category>
		<category><![CDATA[Science]]></category>
		<category><![CDATA[McDonald's]]></category>

		<guid isPermaLink="false">http://www.ilfilosofo.com/?p=445</guid>
		<description><![CDATA[This is McDonald&#8217;s idea of making their Happy Meals educational.  (That I took this photograph may also be proof of bad parenting on our part, but let&#8217;s overlook that.)

I think what they mean is that you can jump six times as high on the Moon.  
In case you were wondering, that&#8217;s because the [...]]]></description>
			<content:encoded><![CDATA[<p>This is McDonald&#8217;s idea of making their Happy Meals educational.  (That I took this photograph may also be proof of bad parenting on our part, but let&#8217;s overlook that.)</p>
<p><img src="http://www.ilfilosofo.com/wp-content/uploads/space_jump.jpg" alt="You can jump 6 times higher in space!" title="You can jump 6 times higher in space!" class="alignnone size-full wp-image-446" /></p>
<p>I think what they mean is that you can jump six times as high on the Moon.  </p>
<p>In case you were wondering, that&#8217;s because the <a href="http://en.wikipedia.org/wiki/Surface_gravity">surface gravity</a> of the Moon is 1/6 that of the Earth&#8217;s.  It&#8217;s <em>not</em> because the moon has 1/6 the mass or the diameter of the Earth, as you might suspect.  In fact, as you can see <a href="http://nssdc.gsfc.nasa.gov/planetary/factsheet/moonfact.html">here</a>, the mass of the Moon is 1.23% of the Earth&#8217;s, and its radius is 27.25%.</p>
<p>Surface gravity can be expressed like so:</p>
<p><code>( Surface gravity of the Moon/Surface gravity of the Earth ) = ( Mass of Moon/Mass of the Earth ) / ( Radius of Moon / Radius of Earth ) <sup>2</sup></code></p>
<p>Plug in the numbers, and you get the following:</p>
<p><code>( Surface gravity of the Moon/Surface gravity of the Earth ) = ( 0.07349 x 10<sup>24</sup> kg/5.9736 x 10<sup>24</sup> kg ) / ( 1738.1 km / 6378.1 km ) <sup>2</sup></code></p>
<p>Which ends up as <code>Surface gravity of the Moon/Surface gravity of the Earth = 0.1656 ~ 1/6</code></p>
]]></content:encoded>
			<wfw:commentRss>http://ilfilosofo.com/blog/2008/04/16/mcdonalds-and-astrophysics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C.S. Lewis on His Dark Materials, Harry Potter, and The Da Vinci Code</title>
		<link>http://ilfilosofo.com/blog/2008/04/15/cs-lewis-dangerous-realism-in-fiction/</link>
		<comments>http://ilfilosofo.com/blog/2008/04/15/cs-lewis-dangerous-realism-in-fiction/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 15:48:10 +0000</pubDate>
		<dc:creator>filosofo</dc:creator>
				<category><![CDATA[Books]]></category>
		<category><![CDATA[C.S. Lewis]]></category>
		<category><![CDATA[Experiment in Criticism]]></category>

		<guid isPermaLink="false">http://www.ilfilosofo.com/?p=444</guid>
		<description><![CDATA[Or whatever certain circles think is the controversial-book-we-need-to-protect-people-from du jour.
There are earnest people who recommend realistic reading for everyone because, they say, it prepares us for real life, and who would, if they could, forbid fairy-tales for children and romances for adults because they &#8216;give a false picture of life&#8217;&#8212;in other words, deceive their readers.
I [...]]]></description>
			<content:encoded><![CDATA[<p>Or whatever certain circles think is the controversial-book-we-need-to-protect-people-from du jour.</p>
<blockquote><p>There are earnest people who recommend realistic reading for everyone because, they say, it prepares us for real life, and who would, if they could, forbid fairy-tales for children and romances for adults because they &#8216;give a false picture of life&#8217;&#8212;in other words, deceive their readers.</p>
<p>I trust that what has already been said about egoistic castle-building [i.e. the reader lives vicariously as the hero of the story] forearms us against this error.  Those who wish to be deceived always demand in what they read at least a superficial or apparent realism of content.  To be sure, the show of such realism which deceives the mere castle-builder would not deceive a literary reader.  If he is to be deceived, a much subtler and closer resemblance to real life will be required.  But without some degree of realism in content&#8212;a degree proportional to the reader&#8217;s intelligence&#8212;no deception will occur at all.  No one can deceive you unless he makes you think he is telling the truth.  The unblushingly romantic has far less power to deceive than the apparently realistic.  Admitted fantasy is precisely the kind of literature which never deceives at all.  Children are not deceived by fairy-tales; they are often and gravely deceived by school-stories.  Adults are not deceived by science fiction; they can be deceived by the stories in the women&#8217;s magazines.  None of us are deceived by the <em>Odyssey</em>, the <em>Kalevala</em>, <em>Beowulf</em>, or Malory. the real danger lurks in sober-faced novels where all appears to be very probable but all is in fact contrived to put across some social or ethical or religious or anti-religious &#8216;comment on life&#8217;.  For some at least of such comments must be false.  To be sure, no novel will deceive the best type of reader.  He never mistakes art either for life or for philosophy.  He can enter, while he reads, into each author&#8217;s point of view without either accepting or rejecting it, suspending when necessary his disbelief and (what is harder) his belief.  </p>
<p>C.S. Lewis, <em>An Experiment in Criticism</em> 67-8</p></blockquote>
<p>The last part makes it clear that he does think some literature is dangerous; but it&#8217;s dangerous in ways different from how many people imagine.  </p>
]]></content:encoded>
			<wfw:commentRss>http://ilfilosofo.com/blog/2008/04/15/cs-lewis-dangerous-realism-in-fiction/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
