<?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>Joel&#039;s Writings</title>
	<atom:link href="http://www.joel.lopes-da-silva.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.joel.lopes-da-silva.com</link>
	<description></description>
	<lastBuildDate>Mon, 18 Oct 2010 01:27:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>The annoying double &#8220;is&#8221;</title>
		<link>http://www.joel.lopes-da-silva.com/2010/10/11/the-annoying-double-is/</link>
		<comments>http://www.joel.lopes-da-silva.com/2010/10/11/the-annoying-double-is/#comments</comments>
		<pubDate>Mon, 11 Oct 2010 07:37:13 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[Language]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[grammar]]></category>

		<guid isPermaLink="false">http://www.joel.lopes-da-silva.com/?p=364</guid>
		<description><![CDATA[Since I arrived in the United States, I heard a lot of people using a phrase that I always found very awkward. People tend to say things like: The problem is is that the economy is not in good shape. I&#8217;m not really trying to talk about the economy here, it was just an example. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://grammar.quickanddirtytips.com/" target="_blank"><img class="alignright size-thumbnail wp-image-369" title="Grammar Girl" src="http://www.joel.lopes-da-silva.com/wp-content/uploads/2010/10/Grammar-Girl-150x150.jpg" alt="Grammar Girl" width="150" height="150" /></a><br />
Since I arrived in the United States, I heard a lot of people using a phrase that I always found very awkward. People tend to say things like:</p>
<blockquote><p>The problem is is that the economy is not in good shape.</p></blockquote>
<p>I&#8217;m not really trying to talk about the economy here, it was just an example. So what&#8217;s the problem in that sentence? The repetition of the word &#8220;is&#8221;. I don&#8217;t really know why, but a lot of people use that phrase around here. And it&#8217;s not just with sentences that start with &#8220;The problem is&#8221;: it often happens with sentences that start with &#8220;The thing is&#8221;, or &#8220;The question is&#8221;.</p>
<p>I heard this phrase so often that I almost thought it was proper English&#8230;</p>
<p><span id="more-364"></span></p>
<p>Fortunately, a few weeks ago, I listened to an episode of the <a href="http://grammar.quickanddirtytips.com/" target="_blank">Grammar Girl</a> podcast about <a href="http://grammar.quickanddirtytips.com/double-is-double-has.aspx" target="_blank">double words</a>, which explains that this phrase is actually incorrect. She even has a great explanation for why people repeat the word &#8220;is&#8221; in such sentences:</p>
<blockquote><p>We probably say such ungrammatical sentences because we’re stalling as we think of what to say next. Thinking longer before you speak is a better idea.</p></blockquote>
<p class="joelquoteauthor"><a href="http://grammar.quickanddirtytips.com/double-is-double-has.aspx" target="_blank">Grammar Girl</a></p>
<p>So, now, the mystery is solved: we should not repeat the word &#8220;is&#8221; in such sentences.</p>
<p>Thanks for clearing that up Grammar Girl!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joel.lopes-da-silva.com/2010/10/11/the-annoying-double-is/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compute MD5 or SHA hash of large file efficiently on iOS and Mac OS X</title>
		<link>http://www.joel.lopes-da-silva.com/2010/09/07/compute-md5-or-sha-hash-of-large-file-efficiently-on-ios-and-mac-os-x/</link>
		<comments>http://www.joel.lopes-da-silva.com/2010/09/07/compute-md5-or-sha-hash-of-large-file-efficiently-on-ios-and-mac-os-x/#comments</comments>
		<pubDate>Tue, 07 Sep 2010 06:18:56 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[Mac OS X Development]]></category>
		<category><![CDATA[iOS Development]]></category>
		<category><![CDATA[c]]></category>
		<category><![CDATA[cocoa]]></category>
		<category><![CDATA[core foundation]]></category>
		<category><![CDATA[cryptography]]></category>
		<category><![CDATA[efficient]]></category>
		<category><![CDATA[foundation]]></category>
		<category><![CDATA[hash]]></category>
		<category><![CDATA[objective-c]]></category>

		<guid isPermaLink="false">http://www.joel.lopes-da-silva.com/?p=331</guid>
		<description><![CDATA[Computing cryptographic hashes of files on iOS and Mac OS X using the CommonCrypto APIs is fairly easy, but doing it in a way that minimizes memory consumption even with large files can be a little more difficult&#8230; The other day, I was reading what some people were saying about this on a forum about [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-thumbnail wp-image-330" title="Xcode" src="http://www.joel.lopes-da-silva.com/wp-content/uploads/2010/09/Xcode-150x150.png" alt="Xcode" width="150" height="150" />Computing cryptographic hashes of files on iOS and Mac OS X using the CommonCrypto APIs is fairly easy, but doing it in a way that minimizes memory consumption even with large files can be a little more difficult&#8230; The other day, I was reading <a href="http://www.iphonedevsdk.com/forum/iphone-sdk-development/17659-calculating-md5-hash-large-file.html" target="_blank">what some people were saying about this on a forum about iPhone development</a>, and they thought they found the trick, but they still had a growing memory footprint with large files because they forgot something fundamental about memory management in Cocoa.</p>
<p><span id="more-331"></span></p>
<p><span class="joelpostupdate">Updated</span></p>
<ul>
<li><span class="joelpostupdate-date">Friday, October 1, 2010:</span> removed comment about the fact that I used character arrays on the heap with the more modular solution described at the end of the post; this is now <a href="http://contribute.tagada.me/changeset/219" target="_blank">fixed</a>, and that more general solution is now as efficient as the simple one described here.</li>
<li><span class="joelpostupdate-date">Sunday, October 17, 2010:</span> added link to a simple <a href="http://github.com/JoeKun/FileMD5Hash" target="_blank">GitHub repository</a> that I created to show exactly how to integrate my function <span class="joelcode">FileMD5HashCreateWithPath</span> with a simple iOS or Mac application.</li>
</ul>
<h2>What was wrong with that solution?</h2>
<p>Even though they had a solution to read bytes from the file progressively instead of reading everything at once, it did not improve the memory consumption of their program when computing hashes of large files. The mistake they made is that the bytes read in the while loop were in an autoreleased instance of <span class="joelcode">NSData</span>. So, unless they create a local autorelease pool within the while loop, the memory will just accumulate, until the next autorelease pool is drained. But I think it would be very inefficient to add an autorelease pool in the while loop, because you would end up allocating a new object in every pass of the loop.</p>
<p>So, in my opinion, the right question is: how do we read those bytes without getting an autoreleased object? </p>
<h2>How to get around that problem?</h2>
<p>I looked for a solution, and I couldn&#8217;t find anything that would do the same thing as <span class="joelcode">-[NSFileHandle readDataOfLength:]</span> at the Foundation level without returning an autoreleased object. So I thought: we have to go deeper. I looked for something similar in Core Foundation, and sure enough, I found the <span class="joelcode">CFReadStream</span> API.</p>
<p>And since I was going to do this using Core Foundation to read those bytes, I decided to go all the way with Core Foundation, with a solution in pure C.</p>
<p>Here&#8217;s how you can compute efficiently the MD5 hash of a large file with CommonCrypto and Core Foundation:</p>
<p><span class="joelfilequotetitle">FileMD5Hash.c</span></p>
<div class="codecolorer-container c dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br />64<br />65<br />66<br />67<br />68<br />69<br />70<br />71<br />72<br />73<br />74<br />75<br />76<br />77<br />78<br />79<br />80<br />81<br />82<br />83<br />84<br />85<br />86<br />87<br />88<br />89<br />90<br />91<br />92<br /></div></td><td><div class="c codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">// Standard library</span><br />
<span style="color: #339933;">#include &lt;stdint.h&gt;</span><br />
<span style="color: #339933;">#include &lt;stdio.h&gt;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Core Foundation</span><br />
<span style="color: #339933;">#include &lt;CoreFoundation/CoreFoundation.h&gt;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Cryptography</span><br />
<span style="color: #339933;">#include &lt;CommonCrypto/CommonDigest.h&gt;</span><br />
<br />
<span style="color: #666666; font-style: italic;">// In bytes</span><br />
<span style="color: #339933;">#define FileHashDefaultChunkSizeForReadingData 4096</span><br />
<br />
<span style="color: #666666; font-style: italic;">// Function</span><br />
CFStringRef FileMD5HashCreateWithPath<span style="color: #009900;">&#40;</span>CFStringRef filePath<span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; size_t chunkSizeForReadingData<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Declare needed variables</span><br />
&nbsp; &nbsp; CFStringRef result <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; CFReadStreamRef readStream <span style="color: #339933;">=</span> NULL<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Get the file URL</span><br />
&nbsp; &nbsp; CFURLRef fileURL <span style="color: #339933;">=</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; CFURLCreateWithFileSystemPath<span style="color: #009900;">&#40;</span>kCFAllocatorDefault<span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span>CFStringRef<span style="color: #009900;">&#41;</span>filePath<span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; kCFURLPOSIXPathStyle<span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span>Boolean<span style="color: #009900;">&#41;</span><span style="color: #000000; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>fileURL<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">goto</span> done<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Create and open the read stream</span><br />
&nbsp; &nbsp; readStream <span style="color: #339933;">=</span> CFReadStreamCreateWithFile<span style="color: #009900;">&#40;</span>kCFAllocatorDefault<span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span>CFURLRef<span style="color: #009900;">&#41;</span>fileURL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>readStream<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">goto</span> done<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; bool didSucceed <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>bool<span style="color: #009900;">&#41;</span>CFReadStreamOpen<span style="color: #009900;">&#40;</span>readStream<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>didSucceed<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">goto</span> done<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Initialize the hash object</span><br />
&nbsp; &nbsp; CC_MD5_CTX hashObject<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; CC_MD5_Init<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>hashObject<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Make sure chunkSizeForReadingData is valid</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>chunkSizeForReadingData<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; chunkSizeForReadingData <span style="color: #339933;">=</span> FileHashDefaultChunkSizeForReadingData<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Feed the data to the hash object</span><br />
&nbsp; &nbsp; bool hasMoreData <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">true</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>hasMoreData<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; uint8_t buffer<span style="color: #009900;">&#91;</span>chunkSizeForReadingData<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CFIndex readBytesCount <span style="color: #339933;">=</span> CFReadStreamRead<span style="color: #009900;">&#40;</span>readStream<span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span>UInt8 <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>buffer<span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span>CFIndex<span style="color: #009900;">&#41;</span><span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>buffer<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>readBytesCount <span style="color: #339933;">==</span> <span style="color: #339933;">-</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>readBytesCount <span style="color: #339933;">==</span> <span style="color: #0000dd;">0</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; hasMoreData <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">false</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #b1b100;">continue</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CC_MD5_Update<span style="color: #009900;">&#40;</span><span style="color: #339933;">&amp;</span>hashObject<span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">void</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>buffer<span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#40;</span>CC_LONG<span style="color: #009900;">&#41;</span>readBytesCount<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Check if the read operation succeeded</span><br />
&nbsp; &nbsp; didSucceed <span style="color: #339933;">=</span> <span style="color: #339933;">!</span>hasMoreData<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Compute the hash digest</span><br />
&nbsp; &nbsp; <span style="color: #993333;">unsigned</span> <span style="color: #993333;">char</span> digest<span style="color: #009900;">&#91;</span>CC_MD5_DIGEST_LENGTH<span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; CC_MD5_Final<span style="color: #009900;">&#40;</span>digest<span style="color: #339933;">,</span> <span style="color: #339933;">&amp;</span>hashObject<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Abort if the read operation failed</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>didSucceed<span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">goto</span> done<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;">// Compute the string result</span><br />
&nbsp; &nbsp; <span style="color: #993333;">char</span> hash<span style="color: #009900;">&#91;</span><span style="color: #0000dd;">2</span> <span style="color: #339933;">*</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>digest<span style="color: #009900;">&#41;</span> <span style="color: #339933;">+</span> <span style="color: #0000dd;">1</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">for</span> <span style="color: #009900;">&#40;</span>size_t i <span style="color: #339933;">=</span> <span style="color: #0000dd;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> <span style="color: #993333;">sizeof</span><span style="color: #009900;">&#40;</span>digest<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #339933;">++</span>i<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; snprintf<span style="color: #009900;">&#40;</span>hash <span style="color: #339933;">+</span> <span style="color: #009900;">&#40;</span><span style="color: #0000dd;">2</span> <span style="color: #339933;">*</span> i<span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #0000dd;">3</span><span style="color: #339933;">,</span> <span style="color: #ff0000;">&quot;%02x&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#40;</span>digest<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; result <span style="color: #339933;">=</span> CFStringCreateWithCString<span style="color: #009900;">&#40;</span>kCFAllocatorDefault<span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&#40;</span><span style="color: #993333;">const</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span><span style="color: #009900;">&#41;</span>hash<span style="color: #339933;">,</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;kCFStringEncodingUTF8<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <br />
done<span style="color: #339933;">:</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>readStream<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CFReadStreamClose<span style="color: #009900;">&#40;</span>readStream<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CFRelease<span style="color: #009900;">&#40;</span>readStream<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>fileURL<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; CFRelease<span style="color: #009900;">&#40;</span>fileURL<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #b1b100;">return</span> result<span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></td></tr></tbody></table></div>
<p>Then, from your Objective-C code, you can just use that function like this:</p>
<div class="codecolorer-container objc dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br /></div></td><td><div class="objc codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span>filePath <span style="color: #002200;">=</span> ...; <span style="color: #6e371a;">// Let's assume filePath is defined...</span><br />
CFStringRef md5hash <span style="color: #002200;">=</span> <br />
&nbsp; &nbsp; FileMD5HashCreateWithPath<span style="color: #002200;">&#40;</span><span style="color: #002200;">&#40;</span>CFStringRef<span style="color: #002200;">&#41;</span>filePath, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FileHashDefaultChunkSizeForReadingData<span style="color: #002200;">&#41;</span>;<br />
NSLog<span style="color: #002200;">&#40;</span><span style="color: #bf1d1a;">@</span><span style="color: #bf1d1a;">&quot;MD5 hash of file at path <span style="color: #2400d9;">\&quot;</span>%@<span style="color: #2400d9;">\&quot;</span>: %@&quot;</span>, <br />
&nbsp; &nbsp; &nbsp; filePath, <span style="color: #002200;">&#40;</span><a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/"><span style="color: #400080;">NSString</span></a> <span style="color: #002200;">*</span><span style="color: #002200;">&#41;</span>md5hash<span style="color: #002200;">&#41;</span>;<br />
CFRelease<span style="color: #002200;">&#40;</span>md5hash<span style="color: #002200;">&#41;</span>;</div></td></tr></tbody></table></div>
<p>Remember that <span class="joelcode">FileMD5HashCreateWithPath</span> transfers ownership of the returned string, so you must release it yourself.</p>
<p>I also created a small <a href="http://www.github.com/" target="_blank">GitHub</a> repository that may help you understand how to integrate that code in your project. It contains a very simple Xcode project, with a target for iOS and another one for Mac OS X. In both cases, the application just provides a simple button to compute the MD5 hash of the executable file (the binary). Here is where you can find that repository: <a href="http://github.com/JoeKun/FileMD5Hash" target="_blank">FileMD5Hash GitHub repository</a>.</p>
<h2>Advantages of this solution</h2>
<p>There are several nice things about this implementation:</p>
<ul>
<li>first, it works as advertised: it computes the MD5 hash of the file correctly, and it doesn&#8217;t make the memory footprint of your app grow, even if you give it the path to a huge file;</li>
<li>even though the path argument is a <span class="joelcode">CFStringRef</span>, it&#8217;s really easy to use this from Objective-C, thanks to the fact that <span class="joelcode">NSString</span> and <span class="joelcode">CFStringRef</span> are toll-free bridged; cf. example above for usage;</li>
<li>it works just fine both on iOS and on Mac OS X;</li>
<li>by reusing <span class="joelcode">sizeof(digest)</span>, I avoided the pitfall of exposing the real value of <span class="joelcode">CC_MD5_DIGEST_LENGTH</span>, which would make it more difficult to adapt to other cryptographic algorithms.</li>
</ul>
<h2>How about SHA1, SHA256, and others?</h2>
<p>It&#8217;s really simple to adapt this function to other algorithms. Say you want to adapt it to get the SHA1 hash instead. Here&#8217;s what you need to do:</p>
<ul>
<li>replace <span class="joelcode">CC_MD5_CTX</span> with <span class="joelcode">CC_SHA1_CTX</span>;</li>
<li>replace <span class="joelcode">CC_MD5_Init</span> with <span class="joelcode">CC_SHA1_Init</span>;</li>
<li>replace <span class="joelcode">CC_MD5_Update</span> with <span class="joelcode">CC_SHA1_Update</span>;</li>
<li>replace <span class="joelcode">CC_MD5_Final</span> with <span class="joelcode">CC_SHA1_Final</span>;</li>
<li>replace <span class="joelcode">CC_MD5_DIGEST_LENGTH</span> with <span class="joelcode">CC_SHA1_DIGEST_LENGTH</span>;</li>
</ul>
<p>Or more simply, just do a find and replace to transform every occurrence of the string &#8220;<span class="joelcode">MD5</span>&#8221; with &#8220;<span class="joelcode">SHA1</span>&#8220;. Voilà, you got it!</p>
<p>Another way to extend this to other algorithms is to make this function more modular, and basically take all of those things as arguments. This is a little more difficult, but I did it for my project TagAdA. With this <a href="http://contribute.tagada.me/browser/branches/mac/Sources/Model/TGDFileHash.c" target="_blank">more advanced and more modular solution</a>, you have a third argument that represents the algorithm that you wish to use, and you only have one instance of the code associated to that logic in your binary, even if you use several of those cryptographic algorithms in your app. I even went to great lengths using the preprocessor to minimize the amount of duplicated code in my source file.</p>
<p>Anyway, there you go! I hope you will find this useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joel.lopes-da-silva.com/2010/09/07/compute-md5-or-sha-hash-of-large-file-efficiently-on-ios-and-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Configure common command-line tools on Mac OS X</title>
		<link>http://www.joel.lopes-da-silva.com/2009/01/29/configure-common-command-line-tools-on-mac-os-x/</link>
		<comments>http://www.joel.lopes-da-silva.com/2009/01/29/configure-common-command-line-tools-on-mac-os-x/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 19:24:38 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[tool]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.joel.lopes-da-silva.com/?p=259</guid>
		<description><![CDATA[Even if you properly configured the Terminal application on your Mac, you may think that using it is difficult, and not intuitive at all. Indeed, with the default configuration for the common command-line tools, you won&#8217;t get syntax highlighting within vim, nor will you have a shell which facilitates your work, and so on. But [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-54" title="My beautiful Terminal with great tools" src="http://www.joel.lopes-da-silva.com/wp-content/uploads/2008/05/Terminal-300x224.jpg" alt="My beautiful Terminal with great tools" width="300" height="224" /></p>
<p>Even if you <a href="/2009/01/28/configure-terminal-on-mac-os-x/" target="_blank">properly configured the Terminal application on your Mac</a>, you may think that using it is difficult, and not intuitive at all. Indeed, with the default configuration for the common command-line tools, you won&#8217;t get syntax highlighting within <span class="joelcode">vim</span>, nor will you have a shell which facilitates your work, and so on. But since I started my journey in Mac universe after spending some time on Linux, I am used to configure some of these tools, and I simply decided to make my shell and my other command-line tools on my mac look like what I previously had in my Linux box.</p>
<p>So, let me tell you what I did to have <em>really usable</em> command-line tools on my Mac&#8230;</p>
<p><span id="more-259"></span></p>
<p><span class="joelpostupdate">Updated</span></p>
<ul>
<li><span class="joelpostupdate-date">Sunday, September 5, 2010:</span> adapted the tutorial to Snow Leopard; incorporated Louis Romero&#8217;s idea about hiding <span class="joelpath">/opt</span> for the Finder; other minor changes.</li>
</ul>
<p>For your information, I did all these things on Mac OS X Snow Leopard 10.6.4. Let&#8217;s get started!</p>
<h2>Install MacPorts</h2>
<p>First of all, I noticed that some of the tools I liked were missing on my Mac. Basically, every command-line tool can be difficult to find, and at the same time, you may want to use a package management system to manage such software. So I could choose between MacPorts, and Fink. Although Fink seemed more powerful (in fact, more Debian-like), I had the impression that there wasn&#8217;t any kind of active development on Fink at the time I wanted to install it. So I chose <a href="http://www.macports.org/" target="_blank">MacPorts</a>.</p>
<p>MacPorts is rather handy in fact, since it will automatically fetch the sources of what you want to install, and compile them with the right options. By the way, that&#8217;s why the first thing you need to do even before installing MacPorts is to install Apple Developer Tools. You can find them on <a href="http://developer.apple.com/" target="_blank">Apple&#8217;s Developer website</a>.</p>
<p>MacPorts is not perfect, and I already experienced some compilation failures with it, but it works most of the time, and it&#8217;s rather straightforward. One of the things I regret when I remember Debian&#8217;s <span class="joelcode">aptitude</span>, though, is its advanced dependency management system; indeed, I think MacPorts&#8217; one is very basic. But hey, nothing is perfect.</p>
<p>Anyway, I just installed MacPorts using the Snow Leopard “dmg” disk image. Just refer to the <a href="http://www.macports.org/install.php" target="_blank">download page of MacPorts</a>. I also encourage you to read the <a href="http://guide.macports.org/" target="_blank">MacPorts Guide</a>, which explains with more details how to install MacPorts properly and how to use it. But you can just skip the part called “MacPorts and the Shell”, and instead do the following in a Terminal window:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'echo &quot;/opt/local/bin\n/opt/local/sbin&quot; &gt; /etc/paths.d/macports'</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'echo &quot;/opt/local/share/man&quot; &gt; /etc/manpaths.d/macports'</span></div></div>
<p>Also, you may want the <span class="joelpath">/opt</span> directory (where MacPorts lives) hidden in the Finder, like a lot of other system directories. Here&#8217;s how you do that:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> SetFile <span style="color: #660033;">-a</span> V <span style="color: #000000; font-weight: bold;">/</span>opt</div></div>
<p>Now, just make sure you quit the Terminal application and relaunch it. Let&#8217;s continue&#8230;</p>
<h2>Install some tools with MacPorts</h2>
<p>Once MacPorts is installed, you can easily install some useful tools. For the rest of this tutorial, you will just need to do the following:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> figlet fortune par <span style="color: #c20cb9; font-weight: bold;">wget</span></div></div>
<p>The tools <span class="joelcode">figlet</span> and <span class="joelcode">fortune</span> are some fun tools, you will see later why we need them; <span class="joelcode">par</span> is very useful to wrap lines with <span class="joelcode">vim</span>, and <span class="joelcode">wget</span> can be used to fetch some files from the internet without using <span class="joelcode">curl</span>.</p>
<p>But for your information, here is the list of the other tools I usually install:</p>
<ul>
<li><span class="joelcode">convmv</span>: to re-encode some filenames;</li>
<li><span class="joelcode">nmap</span>: to discover open ports on remote servers;</li>
<li><span class="joelcode">irssi</span>: an excellent text based IRC client;</li>
<li><span class="joelcode">p7zip</span>, <span class="joelcode">pbzip2</span>, <span class="joelcode">unrar</span>: compression utilities;</li>
<li><span class="joelcode">potrace</span>: to vectorize bitmap image files;</li>
<li><span class="joelcode">pstree</span>: to see in a fancy way the list of processes running on your Mac;</li>
<li><span class="joelcode">signing-party</span>: to help you sign some GnuPG keys;</li>
<li><span class="joelcode">w3m</span>: a text based web browser.</li>
</ul>
<p>I also install the excellent text based mail client <span class="joelcode">mutt</span>, but this one is a little tricky; here is how you should install it:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> mutt-devel +gdbm +headercache +imap +pop +ssl</div></div>
<p>It will install the right version of <span class="joelcode">mutt</span> with the right variants to enable everything that can be useful for normal email usage.</p>
<p>That&#8217;s it for MacPorts!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joel.lopes-da-silva.com/2009/01/29/configure-common-command-line-tools-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Configure Terminal on Mac OS X</title>
		<link>http://www.joel.lopes-da-silva.com/2009/01/28/configure-terminal-on-mac-os-x/</link>
		<comments>http://www.joel.lopes-da-silva.com/2009/01/28/configure-terminal-on-mac-os-x/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 20:28:19 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[terminal]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.joel.lopes-da-silva.com/?p=242</guid>
		<description><![CDATA[Every time someone asks me for help about something geek on a Mac, I often prefer to use the Terminal, because I never got used to editing a configuration file under /etc with a graphical text editor. Don&#8217;t misunderstand me, I am not a Terminal addict, and I often prefer using graphical tools that are [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-54" title="The Terminal application on Mac OS X" src="http://www.joel.lopes-da-silva.com/wp-content/uploads/2008/05/Terminal-300x224.jpg" alt="The Terminal application on Mac OS X" width="300" height="224" /></p>
<p>Every time someone asks me for help about something geek on a Mac, I often prefer to use the Terminal, because I never got used to editing a configuration file under <span class="joelpath">/etc</span> with a graphical text editor. Don&#8217;t misunderstand me, I am not a Terminal addict, and I often prefer using graphical tools that are extremely integrated with Mac OS X: for example, I wouldn&#8217;t code in C or C++ with something else than Xcode, which turns out to be an incredible IDE. But for some other things, I still launch this Terminal, and there are a few things in its default configuration I never liked, such as the behavior of the keys page up/page down, home/end, etc.</p>
<p><span id="more-242"></span></p>
<p>So, let me tell you how you can configure your Terminal like I did on my mac, running Mac OS X Snow Leopard 10.6.4.</p>
<h2>General settings</h2>
<p>First, launch Terminal (using Spotlight, my favorite!), open the <em>Preferences</em> window, and click on <em>Settings</em>. Here, you will see on the left a list of predefined themes with different colors. If you decide to change your default theme, just click on it, and then click the button <em>Default</em>. I always preferred a black terminal with white text, so I chose the theme called <em>Pro</em>. Then, to be sure this will work (specially if you already changed some preferences here), you can click on the cogwheel button next to the minus button, and choose <em>Restore Defaults</em>.</p>
<p>In order to have a much more beautiful text on your terminal, you should check the box <em>Antialias text</em>.</p>
<p>If, like me, you don&#8217;t understand why a Terminal window doesn&#8217;t close automatically once the shell exits (for example, when using the common shortcut <em>^+D</em>), then you should go to the <em>Shell</em> tab, and under <em>When the shell exits:</em> select <em>Close the window</em>.</p>
<h2>Keys and actions</h2>
<p>Let&#8217;s go to the tricky part: keys and actions. Go to the <em>Keyboard</em> tab, and set the following keys to the corresponding actions:</p>
<table class="joeleverythingcentered">
<thead>
<tr>
<th>Key &amp; modifier</th>
<th>Action</th>
<th>Corresponding string</th>
<th>What to type?</th>
</tr>
</thead>
<tbody>
<tr>
<td>control cursor left</td>
<td>send string to shell</td>
<td>\033b</td>
<td>esc B</td>
</tr>
<tr>
<td>control cursor right</td>
<td>send string to shell</td>
<td>\033f</td>
<td>esc F</td>
</tr>
<tr>
<td>home</td>
<td>send string to shell</td>
<td>\001</td>
<td>^+A</td>
</tr>
<tr>
<td>end</td>
<td>send string to shell</td>
<td>\005</td>
<td>^+E</td>
</tr>
<tr>
<td>page up</td>
<td>send string to shell</td>
<td>\033[5~</td>
<td>esc [5~</td>
</tr>
<tr>
<td>page down</td>
<td>send string to shell</td>
<td>\033[6~</td>
<td>esc [6~</td>
</tr>
<tr>
<td>shift home</td>
<td>scroll to start of buffer</td>
<td></td>
<td></td>
</tr>
<tr>
<td>shift end</td>
<td>scroll to end of buffer</td>
<td></td>
<td></td>
</tr>
<tr>
<td>shift page up</td>
<td>scroll to previous page in buffer</td>
<td></td>
<td></td>
</tr>
<tr>
<td>shift page down</td>
<td>scroll to next page in buffer</td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<p>As you will see, when typing the corresponding string in the text area under <em>send string to shell</em>, every keystroke you type can create a weird output. So you should just type what is in the last column, knowing that <em>esc</em> represents the escape button, that <em>^</em> is the control button, and that <em>+</em> means <em>press both keys at the same time</em>.</p>
<h2>What if you use a remote <span class="joelcode">screen</span> with <span class="joelcode">ssh</span> on a Linux server?</h2>
<p>Everything should work properly now&#8230; except if you&#8217;re like me and you often use a <span class="joelcode">screen</span> on Linux boxes through <span class="joelcode">ssh</span>. If you didn&#8217;t even understand this sentence, you should just skip this part.</p>
<p>In this case, your backspace key won&#8217;t work properly on the remote <span class="joelcode">screen</span>, and it&#8217;s a shame. To solve this problem, the best solution I found was to upload the file <span class="joelpath">/usr/share/terminfo/78/xterm-color</span> of the Mac to the server (with <span class="joelcode">scp</span> for instance, or with the excellent <a href="http://cyberduck.ch/" target="_blank">Cyberduck</a> application through SFTP) and to do the following on the server:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> ~<span style="color: #000000; font-weight: bold;">/</span>.terminfo<span style="color: #000000; font-weight: bold;">/</span>x<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #c20cb9; font-weight: bold;">mv</span> ~<span style="color: #000000; font-weight: bold;">/</span>path<span style="color: #000000; font-weight: bold;">/</span>to<span style="color: #000000; font-weight: bold;">/</span>xterm-color ~<span style="color: #000000; font-weight: bold;">/</span>.terminfo<span style="color: #000000; font-weight: bold;">/</span>x<span style="color: #000000; font-weight: bold;">/</span></div></div>
<p>This trick works for me, but if you use a remote <span class="joelcode">screen</span> on many different Linux servers, then it can be a pain. Hopefully, like me, you will only need it for a single account on a single Linux server where you run <span class="joelcode">irssi</span> in a <span class="joelcode">screen</span>; in that case, you just found the solution for the backspace problem.</p>
<h2>The end</h2>
<p>And you&#8217;re done! Just quit the Terminal application, launch it again. That&#8217;s it!</p>
<p>One last word, you should also look at the feature called <em>Window groups</em>: it allows you to save the way several Terminal windows are on the <span class="joelcode">screen</span>, and it can be useful for someone who often uses more than one Terminal window at a time.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joel.lopes-da-silva.com/2009/01/28/configure-terminal-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Draggable Screen Ruler for Web Development</title>
		<link>http://www.joel.lopes-da-silva.com/2009/01/25/draggable-screen-ruler-for-web-development/</link>
		<comments>http://www.joel.lopes-da-silva.com/2009/01/25/draggable-screen-ruler-for-web-development/#comments</comments>
		<pubDate>Sun, 25 Jan 2009 23:27:31 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[bookmarklet]]></category>
		<category><![CDATA[tool]]></category>

		<guid isPermaLink="false">http://www.joel.lopes-da-silva.com/?p=224</guid>
		<description><![CDATA[When doing some web development work, I used to use Screenshot Plus to measure the width of some elements. While this Mac OS X widget is very handy, it wasn&#8217;t very appropriate for this job: it required me to load Mac OS X&#8217;s Dashboard, activate Drag a picture in the widget, drag around what I [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-thumbnail wp-image-223" title="A small bookmarklet for web developers" src="http://www.joel.lopes-da-silva.com/wp-content/uploads/2009/01/Dashcode-150x150.png" alt="A small bookmarklet for web developers" width="150" height="150" /></p>
<p>When doing some web development work, I used to use <a href="http://www.apple.com/downloads/dashboard/business/screenshotplus.html" target="_blank">Screenshot Plus</a> to measure the width of some elements. While this Mac OS X widget is very handy, it wasn&#8217;t very appropriate for this job: it required me to load Mac OS X&#8217;s Dashboard, activate <em>Drag a picture</em> in the widget, drag around what I wanted to measure, and finally drop the screenshot which was just taken. I thought it was a complex way to simply measure things in a web page, but I also thought there should a much better way to do that, which would be far more integrated within the web browser.</p>
<p><span id="more-224"></span></p>
<h2>How to use the Draggable Screen Ruler bookmarklet</h2>
<p>Well, I was right, since this <a href="javascript:(function(){if((typeof rulerInstance)=='object'){rulerInstance.load();}else{var start=function(){new Ruler();};var url='http://bit.ly/bZa47D';var s=document.createElement('script');s.setAttribute('src',url);s.setAttribute('type','text/javascript');if(s.addEventListener){s.addEventListener('load',start,false);}else{s.onreadystatechange=function(){if(this.readyState=='complete'){start();s=null;}}}document.getElementsByTagName('head')[0].appendChild(s);}})();">Draggable Screen Ruler</a> bookmarklet actually does the job quite efficiently, while also giving some useful information such as absolute position in the window. I wrote it a few days ago, and I actually use it every time I work on web design with CSS. You just have to drag and drop the previous link to your bookmarks bar, and you will be able to measure anything from any website you visit. To deactivate it, simply double click with your mouse, or press any key on your keyboard. Isn&#8217;t it nice?</p>
<h2>How it all works</h2>
<p>In fact, the bookmarklet will simply retrieve <a href="http://files.lopes-da-silva.com/code/web/javascript/tools/Ruler.js" target="_blank">this much bigger Javascript file</a> over the internet, which means that you won&#8217;t be able to use it when your are not connected to the internet. But this also guarantees transparent updates in case I enhance it, or fix a bug in the javascript file.</p>
<p>However, there is a simple solution if you really want to use it without internet connectivity, provided that you have a local web server activated (which I assume you have if you are a web developer): just download the Javascript file, and put it somewhere on your computer, so that it is available at local address, such as <span class="joelpath">http://localhost/path/to/scripts/Ruler.js</span>; then replace the content of the variable called <span class="joelcode">url</span> in the bookmarklet code by this local URL, and you&#8217;re all set.</p>
<p>This bookmarklet has been tested only with Firefox 3.0 and Safari 3.1.2, and it worked perfectly with those two browsers.</p>
<h2>Where the idea came from</h2>
<p>Actually, this bookmarklet is not one of my ideas: I found this <a href="http://centricle.com/archive/2003/04/ruler-1.2">Draggable Screen Ruler</a> made by Kevin C. Smith by chance, and I thought it was a very good idea, but I regretted a few things about the implementation.</p>
<p>For example, the original bookmarklet didn&#8217;t allow us to measure something, deactivate it, and then reactivate it clicking on the bookmarklet without reloading the web page. It turns out the main reason for that was the fact that everything was done with global javascript variables which status was not properly updated in this case, and that forced us to reload the page to measure something else when the bookmarlet had already been deactivated.</p>
<p>I also regretted that the colors of the elements in the info box of the ruler could change with some web pages, which would result in bad contrast and poor readability. And finally, I found the bookmarklet code <em>very</em> difficult to understand: variables have very short names which are not explicit at all&#8230;</p>
<p>So I decided to come up with my own version of the bookmarklet, a version which solves all those issues. I think it&#8217;s much easier to understand, and therefore easier to maintain. Of course, I left a reference to the original bookmarlet web page next to the copyright notice.</p>
<p>I hope you will like this nifty tool as much as I do!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joel.lopes-da-silva.com/2009/01/25/draggable-screen-ruler-for-web-development/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How can Windows be easier to use than other Operating Systems?</title>
		<link>http://www.joel.lopes-da-silva.com/2008/07/06/how-can-windows-be-easier-to-use-than-other-operating-systems/</link>
		<comments>http://www.joel.lopes-da-silva.com/2008/07/06/how-can-windows-be-easier-to-use-than-other-operating-systems/#comments</comments>
		<pubDate>Sun, 06 Jul 2008 13:57:56 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[Opinion]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[macosx]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://www.joel.lopes-da-silva.com/?p=166</guid>
		<description><![CDATA[Before I got into graduate school, I almost knew nothing but Microsoft Windows as an Operating System. I even knew many tricks about Windows, and learned some of the things that would inevitably make it unstable&#8230; Then, I just thought that Computers had to be that way&#8230; The real question… Fortunately, I am not such [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-medium wp-image-165 alignright" title="Windows, Linux, and Mac OS X" src="http://www.joel.lopes-da-silva.com/wp-content/uploads/2008/07/Operating-Systems-300x100.png" alt="Windows, Linux, and Mac OS X" width="300" height="100" />Before I got into graduate school, I almost knew nothing but Microsoft Windows as an Operating System. I even knew many tricks about Windows, and learned some of the things that would inevitably make it unstable&#8230; Then, I just thought that Computers had to be that way&#8230;</p>
<p><span id="more-166"></span></p>
<h2>The real question…</h2>
<p>Fortunately, I am not such a narrow-minded guy, and I definitely wanted to know why many scientists and engineers hated Windows, and chose to use something else, such as Linux. Entering VIA Centrale Réseaux, the organization which provides a high speed internet access to more than a thousand students in the Residence of the École Centrale Paris, was a real revolution to me&#8230; In order to be able to manage the organizations&#8217; Debian Servers, as a member of the Root team, I had to learn quite fast what Linux was, and how to use it with a command-line interface. A few months later, I had become some sort of a geek who wouldn&#8217;t want to use Windows at all&#8230; But, putting the ideological fight <em>free vs. proprietary</em> aside, you might want to know what was so great with Debian or Ubuntu (the Linux distributions I use) for a simple user.</p>
<h2>Windows is <em>very</em> buggy</h2>
<p>I think that the best thing with Linux is its stability. Haven&#8217;t you heard any Windows user saying things such as <em>&#8220;I need to format my C: drive once more&#8230;&#8221;</em>? This is not a myth: as a former Windows geek, I knew that starting all over again was, most of the time, the only solution to get rid of Windows instability. What I mean by instability might simply be error messages which pop up just after login&#8230; And once again, I experienced this sort of problem: my Mom has a computer with both Ubuntu and Windows XP. For your information, I always make sure not to install software that is not really needed on Windows, and this computer hasn&#8217;t been really used on Windows yet: it&#8217;s just there, in case of an urgent need. Indeed, my Mom uses exclusively Ubuntu, which she likes very much.</p>
<p>A few months ago, I decided to boot Windows (such a rare thing now!), in order to upgrade it to the SP3. Not only did I have to install 15 upgrades and to do the classic reboot before Microsoft Update would suggest me to install the SP3, but after this very long upgrade another Microsoft program became buggy&#8230; I had the pleasure to welcome a wonderful &#8220;2771 error&#8221; from Windows Live Messenger&#8230; What can you expect from a firm which doesn&#8217;t really know how to upgrade its OS without affecting its other flagship products? Fortunately, after 5 minutes of googling about this error, I found out that I just had to uninstall Windows Live Messenger, and to install it again.</p>
<p>Yet, can we say that such problems must be accepted by all users? Can we really say to a grandma that using Windows is simple, and that she wouldn&#8217;t have any problem? Can we really say that such bugs are acceptable? You might say &#8220;but the solution to your problem was so easy&#8230; anyone would have thought about it!&#8221;. But I won&#8217;t agree with you: I progressively understood that most users are not so comfortable with technology as I am, and for some users, those things have no logic at all, and they may be completely clueless when facing such a bug.</p>
<h2>Software management</h2>
<p>Besides, haven&#8217;t you already heard someone saying to a Windows user, talking about a non-Microsoft program: &#8220;but this feature is available in the new version of the software, you just have to upgrade it&#8221;? Such answers simply reveal an enormous problem in Windows: software management is not uniform at all&#8230; What is so great about Debian, Ubuntu, or other famous Linux Distributions is indeed the Distribution concept itself.</p>
<p>From what I understood, a Linux Distribution is an operating system based on a Linux Kernel, and a <em>set of coherent pieces of software</em>, which may have been adapted to the distribution&#8217;s main choices and organization, with a common tool which makes software management easy. With Debian or Ubuntu, we can think about APT, or its Graphical User Interface Synaptic. Although Linux Distributions are definitely modular, the set of pieces of software of one Linux distribution is really coherent, and one piece of software just works well with the rest of the software of this distribution. The great thing about this way of managing software is that all software can be installed, removed, or upgraded with a single tool: the distribution&#8217;s package management system. Even better, APT is very good at managing dependencies, or conflicts between software. This way, with such a Linux Distribution, you can manage your software very easily, and be sure that everything is up to date at all time. Isn&#8217;t it simplicity itself?</p>
<p>Furthermore, when using Microsoft Update, I always get angry when I realize, once more, how slow upgrading Microsoft programs is. Indeed, APT is much faster for that, and it is able to upgrade the whole system without asking to reboot in order to install the rest of the available upgrades, which occurs quite frequently with Microsoft Update&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joel.lopes-da-silva.com/2008/07/06/how-can-windows-be-easier-to-use-than-other-operating-systems/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Installing Tomcat on Mac OS X</title>
		<link>http://www.joel.lopes-da-silva.com/2008/05/13/installing-tomcat-on-mac-os-x/</link>
		<comments>http://www.joel.lopes-da-silva.com/2008/05/13/installing-tomcat-on-mac-os-x/#comments</comments>
		<pubDate>Tue, 13 May 2008 22:30:45 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[server]]></category>
		<category><![CDATA[tomcat]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.joel.lopes-da-silva.com/?p=131</guid>
		<description><![CDATA[Having to use Tomcat for an important project I am working on, I installed it on my Mac. However, in the beginning, I didn&#8217;t make much effort: I just uncompressed the official archive in my /usr/local, and I was able to start and stop Tomcat manually, that&#8217;s all&#8230; But today I decided to learn a [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-134" title="Tomcat" src="http://www.joel.lopes-da-silva.com/wp-content/uploads/2008/05/Tomcat.gif" alt="Tomcat" width="130" height="92" /></p>
<p>Having to use Tomcat for an important project I am working on, I installed it on my Mac. However, in the beginning, I didn&#8217;t make much effort: I just uncompressed the official archive in my <span class="joelpath">/usr/local</span>, and I was able to start and stop Tomcat manually, that&#8217;s all&#8230; But today I decided to learn a few things about Mac OS X, trying to install it properly. Let&#8217;s see what I did!</p>
<p><span id="more-131"></span></p>
<p><span class="joelpostupdate">Updated</span></p>
<ul>
<li><span class="joelpostupdate-date">Friday, January 30, 2009:</span> added instructions to create an admin user for Tomcat; corrected and enhanced instructions for permissions; added comments on deploying applications which need access to the filesystem; added link to Lambda Probe; corrected the StartupItem files; many thanks to Derk Norton for suggesting some of those corrections.</li>
<li><span class="joelpostupdate-date">Saturday, September 4, 2010:</span> replaced instructions about setting up Tomcat as a StartupItem by instructions to set it up as a launchd job; added a section about Tomcat 7.</li>
</ul>
<p>This tutorial is based on my experience installing Tomcat 6.0.29 on a Mac OS X Snow Leopard 10.6.4 system, and I have not tested those instructions with other versions of the operating system.</p>
<h2>Downloading and uncompressing Tomcat</h2>
<p>First, download from <a href="http://tomcat.apache.org/" target="_blank">Tomcat&#8217;s website</a> the version of Tomcat you want to use. Choose the <span class="joelpath">.tar.gz</span> file in the <em>Core</em> section of the <em>Binary Distributions</em>. Let&#8217;s say you just downloaded it to your Downloads directory (usually <span class="joelpath">/Users/<em>username</em>/Downloads/</span>). Open a Terminal and execute the following commands:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><br />
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">local</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">tar</span> xvzf ~<span style="color: #000000; font-weight: bold;">/</span>Downloads<span style="color: #000000; font-weight: bold;">/</span>apache-tomcat-6.0.29.tar.gz<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> apache-tomcat-6.0.29 tomcat</div></div>
<p>You also need to create an admin user for Tomcat. I will assume you are familiar with vim, but you can use any other text editor. Let&#8217;s edit the right file:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>tomcat<span style="color: #000000; font-weight: bold;">/</span>conf<span style="color: #000000; font-weight: bold;">/</span>tomcat-users.xml</div></div>
<p>Then replace its contents by the following:</p>
<p><span class="joelfilequotetitle">/usr/local/tomcat/conf/tomcat-users.xml</span></p>
<div class="codecolorer-container xml dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">'1.0'</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">'utf-8'</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tomcat-users<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role</span> <span style="color: #000066;">rolename</span>=<span style="color: #ff0000;">&quot;manager&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role</span> <span style="color: #000066;">rolename</span>=<span style="color: #ff0000;">&quot;admin&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;user</span> <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;admin&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;pass&quot;</span> <span style="color: #000066;">roles</span>=<span style="color: #ff0000;">&quot;admin,manager&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tomcat<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<p>Of course, you can replace the word <em>pass</em> by any password you want to use.</p>
<p>Tomcat should already be working, but we should not run it as <span class="joelcode">root</span>, since it may be a huge security issue. That is why we need to first create an unprivileged user as well as its primary group.</p>
<h2>Creating an unprivileged user</h2>
<p>We will be using the command-line utility <span class="joelcode">dscl</span> for this. First, you need to choose the User ID and the Group ID, which must be a positive integer, lower than 500, since User IDs above 500 are reserved to normal users. You just have to pick a number between 0 and 500 which is not yet used by any other user or group. Check this out with the commands:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">dscl . <span style="color: #660033;">-list</span> <span style="color: #000000; font-weight: bold;">/</span>Groups PrimaryGroupID<br />
dscl . <span style="color: #660033;">-list</span> <span style="color: #000000; font-weight: bold;">/</span>Users &nbsp;UniqueID</div></div>
<p>For this tutorial, I will be using the number 107. We can create the group and the user with the following commands:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> dscl . <span style="color: #660033;">-create</span> <span style="color: #000000; font-weight: bold;">/</span>Groups<span style="color: #000000; font-weight: bold;">/</span>_tomcat PrimaryGroupID <span style="color: #000000;">107</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> dscl . <span style="color: #660033;">-create</span> <span style="color: #000000; font-weight: bold;">/</span>Groups<span style="color: #000000; font-weight: bold;">/</span>_tomcat RealName &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">&quot;Tomcat Users&quot;</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> dscl . <span style="color: #660033;">-create</span> <span style="color: #000000; font-weight: bold;">/</span>Groups<span style="color: #000000; font-weight: bold;">/</span>_tomcat Password &nbsp; &nbsp; &nbsp; \<span style="color: #000000; font-weight: bold;">*</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> dscl . <span style="color: #660033;">-create</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>_tomcat &nbsp;UniqueID &nbsp; &nbsp; &nbsp; <span style="color: #000000;">107</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> dscl . <span style="color: #660033;">-create</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>_tomcat &nbsp;PrimaryGroupID <span style="color: #000000;">107</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> dscl . <span style="color: #660033;">-create</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>_tomcat &nbsp;HomeDirectory &nbsp;<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>tomcat<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> dscl . <span style="color: #660033;">-create</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>_tomcat &nbsp;UserShell &nbsp; &nbsp; &nbsp;<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">false</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> dscl . <span style="color: #660033;">-create</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>_tomcat &nbsp;RealName &nbsp; &nbsp; &nbsp; <span style="color: #ff0000;">&quot;Tomcat Administrator&quot;</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> dscl . <span style="color: #660033;">-create</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>_tomcat &nbsp;Password &nbsp; &nbsp; &nbsp; \<span style="color: #000000; font-weight: bold;">*</span></div></div>
<p>Choosing <span class="joelpath">/usr/bin/false</span> as the UserShell, and setting the Password to &#8220;*&#8221; turns this account unusable as a standard user account.</p>
<h2>Setting permissions</h2>
<p>Since Tomcat will be run as the <span class="joelcode">_tomcat</span> user, you must change the ownership of some directories and files. Just run the following commands:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>tomcat<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> root:wheel .<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">644</span> conf<span style="color: #000000; font-weight: bold;">/*</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> root:_tomcat conf<span style="color: #000000; font-weight: bold;">/</span>tomcat-users.xml<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">640</span> conf<span style="color: #000000; font-weight: bold;">/</span>tomcat-users.xml<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> conf<span style="color: #000000; font-weight: bold;">/</span>Catalina<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> _tomcat:_tomcat conf<span style="color: #000000; font-weight: bold;">/</span>Catalina<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> _tomcat:admin logs temp webapps work<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #000000;">2770</span> logs temp webapps work<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> -</div></div>
<p>This way, Tomcat should have the right permissions for all the directories it needs to write into, and at the same time, you won&#8217;t need to use <span class="joelcode">root</span> privileges to read the logs, and so on.</p>
<p>But be careful when developing an application which needs to have access to some directories in the filesystem (for storing files inside the web application for example): you might need to give Tomcat specific permissions on those directories for this to work.</p>
<p>However, I think that a good way to avoid a lot of Unix permissions headaches is to deploy your web applications only using tools such as the Tomcat Manager, or the excellent <a href="http://www.lambdaprobe.org/" target="_blank">Lambda Probe</a>.</p>
<h2>Setting Tomcat as a launchd job</h2>
<p>If we want to have Tomcat start up automatically at boot time, or if we simply want to easily start it and stop it without having to think about details like paths and permissions, it&#8217;s a good idea to use it as a <a href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man8/launchd.8.html" target="_blank">launchd</a> job.</p>
<p>The first big thing we need to do for that is to create a wrapper script that will start Tomcat and not return until the Tomcat process exits, which is not what the <span class="joelpath">startup.sh</span> and <span class="joelpath">catalina.sh</span> scripts do, as they launch Tomcat as a background process.</p>
<p>To do that, let&#8217;s first create a new shell script in Tomcat&#8217;s bin directory:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">touch</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>tomcat<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>tomcat-launchd.sh<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> +x <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>tomcat<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>tomcat-launchd.sh<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>tomcat<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>tomcat-launchd.sh</div></div>
<p>Then put the following content:</p>
<p><span class="joelfilequotetitle">/usr/local/tomcat/bin/tomcat-launchd.sh</span></p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br />54<br />55<br />56<br />57<br />58<br />59<br />60<br />61<br />62<br />63<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#! /bin/sh</span><br />
<br />
<span style="color: #666666; font-style: italic;"># tomcat-launchd.sh</span><br />
<span style="color: #666666; font-style: italic;"># </span><br />
<span style="color: #666666; font-style: italic;"># Wrapper script that starts Tomcat and waits for the Tomcat process </span><br />
<span style="color: #666666; font-style: italic;"># to exit. This is needed for proper interaction with launchd.</span><br />
<br />
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------</span><br />
<span style="color: #666666; font-style: italic;"># Helper functions</span><br />
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------</span><br />
<br />
<span style="color: #666666; font-style: italic;"># NOTE: We are inheriting CATALINA_HOME from launchd, because its value </span><br />
<span style="color: #666666; font-style: italic;"># &nbsp; &nbsp; &nbsp; was defined in the launchd plist configuration file.</span><br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> shutdown<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Bye Tomcat!</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Shutting down Tomcat... &quot;</span><br />
&nbsp; &nbsp; <span style="color: #007800;">$CATALINA_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>catalina.sh stop<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done.&quot;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Cleaning up the temporary file</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$CATALINA_PID</span><br />
&nbsp; &nbsp; <br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> startup<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Define the file where we want the Tomcat process ID to be stored.</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">CATALINA_PID</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">mktemp</span> <span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/`</span><span style="color: #c20cb9; font-weight: bold;">basename</span> <span style="color: #660033;">-s</span> .sh <span style="color: #007800;">$0</span><span style="color: #000000; font-weight: bold;">`</span>.XXXXXX<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #007800;">$?</span> <span style="color: #660033;">-ne</span> <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;$0: Failed to create temporary file. Aborting.&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #007800;">$CATALINA_PID</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Let's go!</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Starting up Tomcat... &quot;</span><br />
&nbsp; &nbsp; . <span style="color: #007800;">$CATALINA_HOME</span><span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>catalina.sh start<br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Register the shutdown function as callback to execute when a signal </span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># is sent to this process.</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">trap</span> shutdown HUP INT QUIT ABRT KILL ALRM TERM TSTP<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done.&quot;</span><br />
&nbsp; &nbsp; <br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
<br />
<span style="color: #000000; font-weight: bold;">function</span> wait_for_tomcat_to_exit<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Waiting for Tomcat to exit (PID: <span style="color: #780078;">`cat $CATALINA_PID`</span>)... &quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">wait</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">cat</span> <span style="color: #007800;">$CATALINA_PID</span><span style="color: #000000; font-weight: bold;">`</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done waiting for Tomcat to exit.&quot;</span><br />
<span style="color: #7a0874; font-weight: bold;">&#125;</span><br />
<br />
<br />
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------</span><br />
<span style="color: #666666; font-style: italic;"># Let's go</span><br />
<span style="color: #666666; font-style: italic;">#---------------------------------------------------------</span><br />
<br />
startup<br />
wait_for_tomcat_to_exit</div></td></tr></tbody></table></div>
<p>Then, we need to create a configuration plist file for the Tomcat launchd job:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">vim</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchDaemons<span style="color: #000000; font-weight: bold;">/</span>org.apache.tomcat.plist</div></div>
<p>Then put the following content:</p>
<p><span class="joelfilequotetitle">/Library/LaunchDaemons/org.apache.tomcat.plist</span></p>
<div class="codecolorer-container xml dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;UTF-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #00bbdd;">&lt;!DOCTYPE plist PUBLIC &quot;-//Apple Computer//DTD PLIST 1.0//EN&quot;</span><br />
<span style="color: #00bbdd;">&nbsp; &nbsp; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;</span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;plist</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Label<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>org.apache.tomcat<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ServiceDescription<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>Tomcat Servlet/JSP Server<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>UserName<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>_tomcat<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>GroupName<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>_tomcat<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>EnvironmentVariables<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>CATALINA_HOME<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/usr/local/tomcat<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>JAVA_HOME<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/System/Library/Frameworks/JavaVM.framework/Home<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>ProgramArguments<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/usr/local/tomcat/bin/tomcat-launchd.sh<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/array<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>StandardOutPath<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/usr/local/tomcat/logs/launchd-stdout.log<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>StandardErrorPath<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/usr/local/tomcat/logs/launchd-stderr.log<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/string<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>RunAtLoad<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;true</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>KeepAlive<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/key<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;true</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/dict<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/plist<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<h2>Using launchd to manage Tomcat</h2>
<p>The first thing we need to do is load this configuration file:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> launchctl load <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchDaemons<span style="color: #000000; font-weight: bold;">/</span>org.apache.tomcat.plist</div></div>
<p>Tomcat should be launching as the user <span class="joelcode">_tomcat</span>, and if you go to <a href="http://localhost:8080/" target="_blank">http://localhost:8080/</a> using your favorite browser, you should get to the homepage of your new Tomcat server.</p>
<p>With the above launchd configuration file, Tomcat is pretty much guaranteed to always be running on your system: it will be restarted automatically for you, by launchd, even if it exits for any reason (for example, a crash, or a reboot). The key that controls the fact that Tomcat is launched at boot time is actually the key named <span class="joelcode">RunAtLoad</span>. So, if you don&#8217;t like this behavior, you can always set that key to <span class="joelcode">false</span>, and reload the configuration:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> launchctl unload <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchDaemons<span style="color: #000000; font-weight: bold;">/</span>org.apache.tomcat.plist<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> launchctl load &nbsp; <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>LaunchDaemons<span style="color: #000000; font-weight: bold;">/</span>org.apache.tomcat.plist</div></div>
<p>You should run those two commands to reload the configuration anytime you make a change to the plist file.</p>
<p>Now, let&#8217;s say that you want to just restart the Tomcat server (maybe because you changed some of Tomcat&#8217;s configuration files). With the above launchd configuration file, all you have to do is this:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> launchctl stop org.apache.tomcat</div></div>
<p>Indeed, you don&#8217;t even need to do an equivalent start call, because launchd will take care of relaunching the Tomcat server. That is because we set the key <span class="joelcode">KeepAlive</span> to <span class="joelcode">true</span>. If you prefer to be able to really shut down Tomcat, then you can just change that key to <span class="joelcode">false</span>, reload the launchd configuration, and then, to achieve the same result, you&#8217;ll have to run two commands now:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> launchctl stop &nbsp;org.apache.tomcat<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> launchctl start org.apache.tomcat</div></div>
<p>Of course, if you omit the start command, then the server will be permanently shut down (until the next reboot, if you still have the key <span class="joelcode">RunAtLoad</span> set to <span class="joelcode">true</span>).</p>
<p>You can customize the behavior of launchd with regard to Tomcat even further, but I suggest you just check out <a href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man5/launchd.plist.5.html" target="_blank">launchd plists&#8217;s man page</a> if you want to learn more about that.</p>
<h2>Update for Tomcat 7</h2>
<p>Tomcat 7 is around the corner. It&#8217;s still considered beta software at the moment (at time of writing, the latest released version of Tomcat is 7.0.2), but it seems to work pretty well. I tried to see if those instructions would work with Tomcat 7, and apparently, they do, except for one thing. The content you need to put in the <span class="joelpath">tomcat-users.xml</span> file is a little different:</p>
<p><span class="joelfilequotetitle">/usr/local/tomcat/conf/tomcat-users.xml</span></p>
<div class="codecolorer-container xml dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="xml codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">'1.0'</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">'utf-8'</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;tomcat-users<span style="color: #000000; font-weight: bold;">&gt;</span></span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role</span> <span style="color: #000066;">rolename</span>=<span style="color: #ff0000;">&quot;manager-gui&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;role</span> <span style="color: #000066;">rolename</span>=<span style="color: #ff0000;">&quot;admin&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
&nbsp; &nbsp; <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;user</span> <span style="color: #000066;">username</span>=<span style="color: #ff0000;">&quot;admin&quot;</span> <span style="color: #000066;">password</span>=<span style="color: #ff0000;">&quot;pass&quot;</span> <span style="color: #000066;">roles</span>=<span style="color: #ff0000;">&quot;admin,manager-gui&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span><br />
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/tomcat<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></div></td></tr></tbody></table></div>
<p>The difference is that I had to replace the role <span class="joelcode">manager</span> by <span class="joelcode">manager-gui</span>. <a href="http://tomcat.apache.org/migration.html" target="_blank">Tomcat&#8217;s migration page</a> explains that difference very well.</p>
<p>Other than that, you should be able to install Tomcat 7 on your Mac using those instructions.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joel.lopes-da-silva.com/2008/05/13/installing-tomcat-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>mmv on Mac OS X</title>
		<link>http://www.joel.lopes-da-silva.com/2008/05/12/mmv-on-mac-os-x/</link>
		<comments>http://www.joel.lopes-da-silva.com/2008/05/12/mmv-on-mac-os-x/#comments</comments>
		<pubDate>Mon, 12 May 2008 13:18:02 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[command-line]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://www.joel.lopes-da-silva.com/?p=52</guid>
		<description><![CDATA[Since I switched from Debian and Ubuntu to Mac OS X, I got used to most of the differences between those operating systems. Yet one very important thing for me was still lacking: A command-line utility called mmv… Updated Friday, January 30, 2009: added a small command to rebuild the whatis database after install and [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-medium wp-image-54" title="mmv" src="http://www.joel.lopes-da-silva.com/wp-content/uploads/2008/05/Terminal-300x224.jpg" alt="mmv" width="300" height="224" /></p>
<p>Since I switched from Debian and Ubuntu to Mac OS X, I got used to most of the differences between those operating systems. Yet one very important thing for me was still lacking: A command-line utility called <span class="joelcode">mmv</span>…</p>
<p><span id="more-52"></span></p>
<p><span class="joelpostupdate">Updated</span></p>
<ul>
<li><span class="joelpostupdate-date">Friday, January 30, 2009:</span> added a small command to rebuild the <span class="joelcode">whatis</span> database after install and uninstall.</li>
<li><span class="joelpostupdate-date">Wednesday, September 1, 2010:</span> replaced the version of <span class="joelcode">mmv</span> distributed by a newer one, compiled differently, and specially targeted at Mac OS X Snow Leopard; also added a small update about the fact that <span class="joelcode">mmv</span> is now available through MacPorts.</li>
</ul>
<h2>Description</h2>
<p>According to this <a href="http://debaday.debian.net/2007/06/13/mmv-mass-moving-and-renaming-files/" target="_blank">article</a>, which describes very well what <span class="joelcode">mmv</span> can do for you:</p>
<blockquote><p><span class="joelcode">mmv</span> is a command-line tool which allows the user to move, rename, copy, append and link large amounts of files with a single command. The tool is especially useful when you need to rename a lot of files that have similar filenames, yet subtle differences.</p></blockquote>
<p class="joelquoteauthor"><a href="http://debaday.debian.net/" target="_blank">Debian Package of the Day</a></p>
<h2>The problem, and my idea&#8230;</h2>
<p>Unfortunately, <span class="joelcode">mmv</span> is not available through MacPorts, which I tend to use when I want to install some specific command-line tools on my Mac. But then I thought that I could try recompiling myself the source code for <span class="joelcode">mmv</span> that is used to create the <a href="http://packages.debian.org/squeeze/mmv" target="_blank"><span class="joelcode">mmv</span> package for Debian</a>.</p>
<p><span class="joelpostupdate">Update:</span> At the time of initial writing, this was true, but it is no longer the case: I just discovered that <span class="joelcode">mmv</span> is now available through MacPorts. However, looking at the version number they advertise, my version is more recent.</p>
<p>Sure enough, it wasn&#8217;t that complicated, I quickly got a 3-way Universal Binary (x86_64, i386 and ppc) version of <span class="joelcode">mmv</span> for Mac OS X. Finally, <span class="joelcode">mmv</span> on the Mac! Then, I thought: Why wouldn&#8217;t I make an archive of all those files, and distribute my binary version of <span class="joelcode">mmv</span> for Mac OS X? According to <span class="joelcode">mmv</span>&#8216;s license, there is no reason why I couldn&#8217;t do that.</p>
<h2>Download</h2>
<p><a href="http://files.lopes-da-silva.com/macosx/mmv/mmv-binary-MacOSX-10.6.tar.bz2"><img class="alignleft size-full wp-image-64" title="Download mmv for Mac OS X" src="http://www.joel.lopes-da-silva.com/wp-content/uploads/2010/09/Download.png" alt="Download mmv for Mac OS X" width="48" height="48" /></a>Therefore, here is my version of <span class="joelcode">mmv</span>:</p>
<p>Binary version of <a href="http://files.lopes-da-silva.com/macosx/mmv/mmv-binary-MacOSX-10.6.tar.bz2"><span class="joelcode">mmv</span> for Mac OS X Snow Leopard</a>.</p>
<h2>Install</h2>
<p>First, download the <span class="joelpath">.tar.bz2</span> file, and be sure to let it in your Downloads directory (usually <span class="joelpath">/Users/<em>username</em>/Downloads/</span>).</p>
<p>Then, launch the Terminal application and execute the following commands:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">tar</span> xvjf ~<span style="color: #000000; font-weight: bold;">/</span>Downloads<span style="color: #000000; font-weight: bold;">/</span>mmv-binary-MacOSX-<span style="color: #000000;">10.6</span>.tar.bz2<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'/etc/periodic/weekly/320.whatis 2&gt; /dev/null; exit 0'</span></div></div>
<p>That&#8217;s it!</p>
<h2>Uninstall</h2>
<p>Launch the Terminal application and execute the following commands:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-R</span> <span style="color: #660033;">-f</span> bin<span style="color: #000000; font-weight: bold;">/</span>m<span style="color: #7a0874; font-weight: bold;">&#123;</span>ad,<span style="color: #c20cb9; font-weight: bold;">cp</span>,<span style="color: #c20cb9; font-weight: bold;">ln</span>,<span style="color: #c20cb9; font-weight: bold;">mv</span><span style="color: #7a0874; font-weight: bold;">&#125;</span> share<span style="color: #000000; font-weight: bold;">/</span>doc<span style="color: #000000; font-weight: bold;">/</span>mmv<span style="color: #000000; font-weight: bold;">/</span> share<span style="color: #000000; font-weight: bold;">/</span>man<span style="color: #000000; font-weight: bold;">/</span>man1<span style="color: #000000; font-weight: bold;">/</span>m<span style="color: #7a0874; font-weight: bold;">&#123;</span>ad,<span style="color: #c20cb9; font-weight: bold;">cp</span>,<span style="color: #c20cb9; font-weight: bold;">ln</span>,<span style="color: #c20cb9; font-weight: bold;">mv</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>.1<br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">sh</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">'/etc/periodic/weekly/320.whatis 2&gt; /dev/null; exit 0'</span></div></div>
<p>That&#8217;s it!</p>
<h2>Important Notes</h2>
<p>As the distributor of this binary version of <span class="joelcode">mmv</span>, I want to add to <span class="joelcode">mmv</span>&#8216;s copyright notice my own warning:</p>
<blockquote><p>This software is provided by the distributor “as is” and any express or implied warranties, including, but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In no event shall the distributor be liable for any direct, indirect, incidental, special, exemplary, or consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data, or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if advised of the possibility of such damage.</p></blockquote>
<p>Another important thing is that I only tested this version of <span class="joelcode">mmv</span> on Mac OS X Snow Leopard 10.6.4, but it should work with all versions of Snow Leopard, and most likely with future major versions of the Mac OS X. If you find that it works with older versions of the operating system, please let me know.</p>
<p>I also wrote a README file containing all the important things you should know about this package. Once the software installed, it should be located at <span class="joelpath">/usr/local/share/doc/mmv/README</span>.</p>
<h2>One more thing&#8230;</h2>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joel.lopes-da-silva.com/2008/05/12/mmv-on-mac-os-x/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Japanese in LaTeX documents in Unicode with MacTeX</title>
		<link>http://www.joel.lopes-da-silva.com/2008/05/10/japanese-in-latex-documents-in-unicode-with-mactex/</link>
		<comments>http://www.joel.lopes-da-silva.com/2008/05/10/japanese-in-latex-documents-in-unicode-with-mactex/#comments</comments>
		<pubDate>Sat, 10 May 2008 13:51:31 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[japanese]]></category>
		<category><![CDATA[latex]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[unicode]]></category>

		<guid isPermaLink="false">http://www.joel.lopes-da-silva.com/?p=11</guid>
		<description><![CDATA[Since I discovered LaTeX, I have become a real fan of this typesetting system. Yet, something bothered me very much: I could not use easily Japanese with LaTeX using a normal encoding, that is to say using UTF-8. Using CJK is not too difficult, but getting CJKutf8 to work is much harder. I just couldn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.joel.lopes-da-silva.com/wp-content/uploads/2008/05/LaTeX.jpg"><img class="alignright size-medium wp-image-46" title="LaTeX" src="http://www.joel.lopes-da-silva.com/wp-content/uploads/2008/05/LaTeX-300x129.jpg" alt="" width="300" height="129" /></a>Since I discovered LaTeX, I have become a real fan of this typesetting system. Yet, something bothered me very much: I could not use easily Japanese with LaTeX using a <em>normal</em> encoding, that is to say using UTF-8. Using <span class="joelcode">CJK</span> is not too difficult, but getting <span class="joelcode">CJKutf8</span> to work is much harder. I just couldn&#8217;t resign myself to use some strange encoding popular in Japan, mostly for <em>Windows Addicts</em>&#8230;</p>
<p>But I just found how to do it. Since it is not so easy, I want to do a very simple tutorial explaining precisely how to install UTF-8 Japanese support in MacTeX. So, just follow the guide&#8230;</p>
<p><span id="more-11"></span></p>
<p><strong>Important Note</strong></p>
<p>Even though this tutorial worked just fine a while back (with Mac OS X Leopard 10.5.2, I believe), it stopped working for some reason with later updates (including the latest software updates for Leopard and Snow Leopard). The problem is that at the end of the whole process, the PDF generated using <span class="joelcode">pdflatex</span> uses crazy glyphs instead of Japanese ones.</p>
<p>However, I know that copying the generated files from another machine on which this procedure has worked makes it also work on other machines. So I may end up publishing those files someday.</p>
<p><span class="joelpostupdate">Updated</span></p>
<ul>
<li><span class="joelpostupdate-date">Friday, November 14, 2008:</span> updated for MacTeX 2008 support on Leopard; small &#8220;bugfix&#8221; of the tutorial.</li>
<li><span class="joelpostupdate-date">Monday, December 1, 2008:</span> replaced <span class="joelcode">wget</span> by <span class="joelcode">curl -O</span>.</li>
</ul>
<p>Of course, installing MacTeX is a prerequisite. This tutorial has been tested on Mac OS X 10.5.2 (Leopard) with both versions 2007 and 2008 of MacTeX, and it is just the adaptation of a procedure described in a Debian <span class="joelcode">README</span> file (<span class="joelpath">/usr/share/doc/latex-cjk-common/README.Debian.gz</span> in Debian Etch)&#8230;</p>
<p>The problem when we want to type Japanese directly in UTF-8 encoding in a LaTeX document is that we have to use the package <span class="joelcode">CJKutf8</span> instead of <span class="joelcode">CJK</span>, and by default, there is no font with Japanese symbols adapted for UTF-8 typesetting in LaTeX. Therefore, the main goal of this tutorial is to install the font Cyberbit into your LaTeX distribution. Please, be sure to acknowledge the <a href="http://http.netscape.com.edgesuite.net/pub/communicator/extras/fonts/windows/License.wri" target="_blank">font&#8217;s license</a> before proceeding with this tutorial.</p>
<p>First, in a terminal, download and unzip the font file:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">curl <span style="color: #660033;">-O</span> <span style="color: #c20cb9; font-weight: bold;">ftp</span>:<span style="color: #000000; font-weight: bold;">//</span>ftp.netscape.com<span style="color: #000000; font-weight: bold;">/</span>pub<span style="color: #000000; font-weight: bold;">/</span>communicator<span style="color: #000000; font-weight: bold;">/</span>extras<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span>windows<span style="color: #000000; font-weight: bold;">/</span>Cyberbit.ZIP<br />
<span style="color: #c20cb9; font-weight: bold;">unzip</span> Cyberbit.ZIP<br />
<span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> Cyberbit.ZIP</div></div>
<p>Then, we need to become <span class="joelcode">root</span> in order to prepare some directories and files:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-s</span> &nbsp; <span style="color: #666666; font-style: italic;"># Enter your password if needed</span><br />
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span>truetype<span style="color: #000000; font-weight: bold;">/</span>bitstream<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #c20cb9; font-weight: bold;">mv</span> Cyberbit.ttf <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span>truetype<span style="color: #000000; font-weight: bold;">/</span>bitstream<span style="color: #000000; font-weight: bold;">/</span>cyberbit.ttf<br />
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>cyberbit-fonts<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #7a0874; font-weight: bold;">exit</span> &nbsp; &nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># After this you should be back in a shell without superuser privileges</span><br />
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$USER</span>&quot;</span>:staff <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>cyberbit-fonts<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>cyberbit-fonts<span style="color: #000000; font-weight: bold;">/</span></div></div>
<p><span class="joelpath">/usr/src/cyberbit-fonts/</span> will be our build directory. We must now prepare some more files in that directory:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">ln</span> <span style="color: #660033;">-s</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span>truetype<span style="color: #000000; font-weight: bold;">/</span>bitstream<span style="color: #000000; font-weight: bold;">/</span>cyberbit.ttf<br />
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>TeX<span style="color: #000000; font-weight: bold;">/</span>Root<span style="color: #000000; font-weight: bold;">/</span>texmf-dist<span style="color: #000000; font-weight: bold;">/</span>source<span style="color: #000000; font-weight: bold;">/</span>latex<span style="color: #000000; font-weight: bold;">/</span>CJK<span style="color: #000000; font-weight: bold;">/</span>utils<span style="color: #000000; font-weight: bold;">/</span>subfonts<span style="color: #000000; font-weight: bold;">/</span>subfonts.pe .</div></div>
<p>You mustn&#8217;t forget the final &#8220;.&#8221;, since it means the working directory. Then, you have to run the following command:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">fontforge <span style="color: #660033;">-script</span> subfonts.pe cyberbit.ttf cyberbit \<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>TeX<span style="color: #000000; font-weight: bold;">/</span>Root<span style="color: #000000; font-weight: bold;">/</span>texmf<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span>sfd<span style="color: #000000; font-weight: bold;">/</span>Unicode.sfd</div></div>
<p>This will take a very long time, probably several hours, so if you have something else to do, go for it! Then you must generate a file called <span class="joelpath">cyberbit.map</span>:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">touch</span> cyberbit.map<br />
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">*</span>.pfb<br />
<span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(basename $i .pfb)</span> <span style="color: #007800;">$(basename $i .pfb)</span>&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> cyberbit.map<br />
<span style="color: #000000; font-weight: bold;">done</span></div></div>
<p>Then, we need <span class="joelcode">root</span>&#8216;s privileges for pretty much all the commands we need to run, so type the following command:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #660033;">-s</span></div></div>
<p>in order to become <span class="joelcode">root</span>, and type your password. Then do the following:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>texlive<span style="color: #000000; font-weight: bold;">/</span>texmf-local<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span>map<span style="color: #000000; font-weight: bold;">/</span>dvips<span style="color: #000000; font-weight: bold;">/</span>cyberbit<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>texlive<span style="color: #000000; font-weight: bold;">/</span>texmf-local<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>afm,type1,tfm<span style="color: #7a0874; font-weight: bold;">&#125;</span><span style="color: #000000; font-weight: bold;">/</span>cyberbit<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #c20cb9; font-weight: bold;">cp</span> cyberbit.map <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>texlive<span style="color: #000000; font-weight: bold;">/</span>texmf-local<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span>map<span style="color: #000000; font-weight: bold;">/</span>dvips<span style="color: #000000; font-weight: bold;">/</span>cyberbit<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">*</span>.afm <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>texlive<span style="color: #000000; font-weight: bold;">/</span>texmf-local<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span>afm<span style="color: #000000; font-weight: bold;">/</span>cyberbit<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">*</span>.pfb <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>texlive<span style="color: #000000; font-weight: bold;">/</span>texmf-local<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span>type1<span style="color: #000000; font-weight: bold;">/</span>cyberbit<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #000000; font-weight: bold;">*</span>.tfm <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>texlive<span style="color: #000000; font-weight: bold;">/</span>texmf-local<span style="color: #000000; font-weight: bold;">/</span>fonts<span style="color: #000000; font-weight: bold;">/</span>tfm<span style="color: #000000; font-weight: bold;">/</span>cyberbit<span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Map cyberbit.map&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>TeX<span style="color: #000000; font-weight: bold;">/</span>Root<span style="color: #000000; font-weight: bold;">/</span>texmf-var<span style="color: #000000; font-weight: bold;">/</span>web2c<span style="color: #000000; font-weight: bold;">/</span>updmap.cfg<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> ..<br />
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=<span style="color: #ff0000;">&quot;/usr/texbin:<span style="color: #007800;">$PATH</span>&quot;</span><br />
texhash<br />
<span style="color: #c20cb9; font-weight: bold;">updmap</span><br />
updmap-sys</div></div>
<p>Then you have to replace a file of the MacTeX distribution by another one:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>Library<span style="color: #000000; font-weight: bold;">/</span>TeX<span style="color: #000000; font-weight: bold;">/</span>Root<span style="color: #000000; font-weight: bold;">/</span>texmf-dist<span style="color: #000000; font-weight: bold;">/</span>tex<span style="color: #000000; font-weight: bold;">/</span>latex<span style="color: #000000; font-weight: bold;">/</span>CJK<span style="color: #000000; font-weight: bold;">/</span>UTF8<span style="color: #000000; font-weight: bold;">/</span>c70song.fd<br />
<span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>texlive<span style="color: #000000; font-weight: bold;">/</span>texmf-local<span style="color: #000000; font-weight: bold;">/</span>tex<span style="color: #000000; font-weight: bold;">/</span>latex<span style="color: #000000; font-weight: bold;">/</span>CJK<span style="color: #000000; font-weight: bold;">/</span>UTF-<span style="color: #000000;">8</span><span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>texlive<span style="color: #000000; font-weight: bold;">/</span>texmf-local<span style="color: #000000; font-weight: bold;">/</span>tex<span style="color: #000000; font-weight: bold;">/</span>latex<span style="color: #000000; font-weight: bold;">/</span>CJK<span style="color: #000000; font-weight: bold;">/</span>UTF-<span style="color: #000000;">8</span><span style="color: #000000; font-weight: bold;">/</span><br />
<span style="color: #c20cb9; font-weight: bold;">touch</span> c70song.fd <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #660033;">-R</span> go+<span style="color: #c20cb9; font-weight: bold;">w</span> .<br />
open <span style="color: #660033;">-a</span> TextEdit c70song.fd</div></div>
<p>Now, a new TextEdit window should have opened, with an empty file. Copy-paste the following text into the empty file:</p>
<p><span class="joelfilequotetitle">/usr/local/texlive/texmf-local/tex/latex/CJK/UTF-8/c70song.fd</span></p>
<div class="codecolorer-container latex dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br /></div></td><td><div class="latex codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #2C922C; font-style: italic;">%%%%%%</span><br />
<span style="color: #2C922C; font-style: italic;">% This is the file c70song.fd of the CJK package</span><br />
<span style="color: #2C922C; font-style: italic;">% for using Asian logographs (Chinese/Japanese/Korean) with LaTeX2e</span><br />
<span style="color: #2C922C; font-style: italic;">%</span><br />
<span style="color: #2C922C; font-style: italic;">% created by Werner Lemberg</span><br />
<span style="color: #2C922C; font-style: italic;">%</span><br />
<span style="color: #2C922C; font-style: italic;">% Version 4.6.0 (11-Aug-2005)</span><br />
<br />
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdef"><span style="color: #800000;">def</span></a><span style="color: #800000; font-weight: normal;">\fileversion</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">4.6.0</span><span style="color: #E02020; ">}</span><br />
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdef"><span style="color: #800000;">def</span></a><span style="color: #800000; font-weight: normal;">\filedate</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">2005/08/11</span><span style="color: #E02020; ">}</span><br />
<span style="color: #800000; font-weight: normal;">\ProvidesFile</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">c70song.fd</span><span style="color: #E02020; ">}[</span><span style="color: #C08020; font-weight: normal;"><span style="color: #800000; font-weight: normal;">\filedate</span><span style="color: #800000; font-weight: normal;">\space</span><span style="color: #800000; font-weight: normal;">\fileversion</span></span><span style="color: #E02020; ">]</span><br />
<br />
<span style="color: #2C922C; font-style: italic;">% character set: Unicode U+0080 - U+FFFD</span><br />
<span style="color: #2C922C; font-style: italic;">% font encoding: Unicode</span><br />
<br />
<span style="color: #800000; font-weight: normal;">\DeclareFontFamily</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">C70</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">song</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #800000; font-weight: normal;">\hyphenchar</span> <span style="color: #800000; font-weight: normal;">\font</span><span style="color: #800000; font-weight: normal;">\m</span>@ne</span><span style="color: #E02020; ">}</span><br />
<br />
<span style="color: #800000; font-weight: normal;">\DeclareFontShape</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">C70</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">song</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">m</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">n</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">&lt;-&gt; CJK * cyberbit</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #E02020; ">}</span><br />
<span style="color: #800000; font-weight: normal;">\DeclareFontShape</span>{C70</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">song</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">bx</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">n</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">&lt;-&gt; CJKb * cyberbit</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #800000; font-weight: normal;">\CJKbold</span></span><span style="color: #E02020; ">}</span><br />
<br />
<span style="color: #800000; font-weight: normal;">\endinput</span><br />
<span style="color: #2C922C; font-style: italic;">%%%%%%</span></div></td></tr></tbody></table></div>
<p>Then save the file. Lastly, run:</p>
<div class="codecolorer-container bash dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> root:wheel . <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #660033;">-R</span> go-w .<br />
texhash</div></div>
<p>That&#8217;s it! Now you can enter the following LaTeX code as UTF-8 (double check the preferences of your LaTeX editor) in a new LaTeX file and compile it with <span class="joelcode">pdflatex</span>:</p>
<p><span class="joelfilequotetitle">Example.tex</span></p>
<div class="codecolorer-container latex dawn joelcodecolorer" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:580px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br />15<br />16<br />17<br />18<br />19<br />20<br />21<br />22<br />23<br />24<br />25<br />26<br />27<br />28<br />29<br />30<br />31<br />32<br />33<br />34<br />35<br />36<br />37<br />38<br />39<br />40<br />41<br />42<br />43<br />44<br />45<br />46<br />47<br />48<br />49<br />50<br />51<br />52<br />53<br /></div></td><td><div class="latex codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cdocumentclass"><span style="color: #800000;">documentclass</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">a4paper,12pt</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">article</span><span style="color: #E02020; ">}</span><br />
<br />
<span style="color: #2C922C; font-style: italic;">%%%%%%%%%%%%%%%%%%%%%%%</span><br />
<span style="color: #2C922C; font-style: italic;">% Encodings, fonts... %</span><br />
<span style="color: #2C922C; font-style: italic;">%%%%%%%%%%%%%%%%%%%%%%%</span><br />
<br />
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">utf8</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">inputenc</span><span style="color: #E02020; ">}</span><br />
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">T1</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">fontenc</span><span style="color: #E02020; ">}</span><br />
<br />
<span style="color: #2C922C; font-style: italic;">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span><br />
<span style="color: #2C922C; font-style: italic;">% Oriental languages specificic options %</span><br />
<span style="color: #2C922C; font-style: italic;">%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%</span><br />
<br />
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">T1</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">CJKutf8</span><span style="color: #E02020; ">}</span><br />
<br />
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cusepackage"><span style="color: #800000;">usepackage</span></a><span style="color: #E02020; ">[</span><span style="color: #C08020; font-weight: normal;">overlap,CJK</span><span style="color: #E02020; ">]{</span><span style="color: #2020C0; font-weight: normal;">ruby</span><span style="color: #E02020; ">}</span>&nbsp; &nbsp; <span style="color: #2C922C; font-style: italic;">% Furigana support</span><br />
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Crenewcommand"><span style="color: #800000;">renewcommand</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #800000; font-weight: normal;">\rubysize</span></span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">0.5</span><span style="color: #E02020; ">}</span> &nbsp; &nbsp; <span style="color: #2C922C; font-style: italic;">% Furigana size</span><br />
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Crenewcommand"><span style="color: #800000;">renewcommand</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #800000; font-weight: normal;">\rubysep</span></span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">-0.3ex</span><span style="color: #E02020; ">}</span> &nbsp; <span style="color: #2C922C; font-style: italic;">% Spacing between Furigana and Kanji</span><br />
<br />
<span style="color: #2C922C; font-style: italic;">%%%%%%%%%%%%%%%%%</span><br />
<span style="color: #2C922C; font-style: italic;">% Title, author %</span><br />
<span style="color: #2C922C; font-style: italic;">%%%%%%%%%%%%%%%%%</span><br />
<br />
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Ctitle"><span style="color: #800000;">title</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Japanese in UTF-8 with \<a href="http://www.golatex.de/wiki/index.php?title=%5CLaTeX"><span style="color: #800000;">LaTeX</span></a></span><span style="color: #E02020; ">}</span><br />
<span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cauthor"><span style="color: #800000;">author</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Joel <span style="color: #800000; font-weight: normal;">\textsc</span>{Lopes Da Silva</span><span style="color: #E02020; ">}}</span><br />
<br />
<span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span><br />
<br />
&nbsp; &nbsp; <span style="color: #C00000; font-weight: normal;">\begin</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">CJK</span></span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">UTF8</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">song</span><span style="color: #E02020; ">}</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cmaketitle"><span style="color: #800000;">maketitle</span></a><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #800000; font-weight: normal;">\thispagestyle</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">empty</span><span style="color: #E02020; ">}</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csection"><span style="color: #800000;">section</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">タイトル</span><span style="color: #E02020; ">}</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; おめでとうございます。<span style="color: #800000; font-weight: normal;">\ruby</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">自分</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">じぶん</span><span style="color: #E02020; ">}</span>でできましたね。<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cbigskip"><span style="color: #800000;">bigskip</span></a><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; これから、日本語で <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5CLaTeX"><span style="color: #800000;">LaTeX</span></a> の<span style="color: #800000; font-weight: normal;">\ruby</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">資料</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">しりょう</span><span style="color: #E02020; ">}</span>を<span style="color: #800000; font-weight: normal;">\ruby</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">書</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">か</span><span style="color: #E02020; ">}</span>けます。<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Csection"><span style="color: #800000;">section</span></a><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">Another title</span><span style="color: #E02020; ">}</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; You can even use English words within a<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 日本語の<span style="color: #800000; font-weight: normal;">\ruby</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;">資料</span><span style="color: #E02020; ">}{</span><span style="color: #2020C0; font-weight: normal;">しりょう</span><span style="color: #E02020; ">}</span>~(document in Japanese).<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #E02020; ">\</span><a href="http://www.golatex.de/wiki/index.php?title=%5Cbigskip"><span style="color: #800000;">bigskip</span></a><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Have fun!<br />
<br />
&nbsp; &nbsp; <span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">CJK</span></span><span style="color: #E02020; ">}</span><br />
<br />
<span style="color: #C00000; font-weight: normal;">\end</span><span style="color: #E02020; ">{</span><span style="color: #2020C0; font-weight: normal;"><span style="color: #0000D0; font-weight: normal;">document</span></span><span style="color: #E02020; ">}</span></div></td></tr></tbody></table></div>
<p>Once compiled with <span class="joelcode">pdflatex</span>, you should get the expected result: a <a href="http://www.joel.lopes-da-silva.com/wp-content/uploads/2008/05/Japanese-LaTeX-Unicode-MacTeX-Example.pdf" target="_blank">nice PDF document generated by LaTeX with Japanese text</a>. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joel.lopes-da-silva.com/2008/05/10/japanese-in-latex-documents-in-unicode-with-mactex/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>A matter of language</title>
		<link>http://www.joel.lopes-da-silva.com/2008/03/03/a-matter-of-language/</link>
		<comments>http://www.joel.lopes-da-silva.com/2008/03/03/a-matter-of-language/#comments</comments>
		<pubDate>Mon, 03 Mar 2008 10:44:25 +0000</pubDate>
		<dc:creator>Joel</dc:creator>
				<category><![CDATA[Language]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[french]]></category>

		<guid isPermaLink="false">http://www.joel.lopes-da-silva.com/?p=3</guid>
		<description><![CDATA[As you can see, although English is not my native language, I chose to write articles in English for my personal website. The reason why I chose to write in English is quite simple: English is the most spoken language in the world, and I didn&#8217;t want to translate every article in some secondary language. Yet, I [...]]]></description>
			<content:encoded><![CDATA[<p>As you can see, although English is not my native language, I chose to write articles in English for my personal website. The reason why I chose to write in English is quite simple: English is the most spoken language in the world, and I didn&#8217;t want to translate every article in some secondary language.</p>
<p>Yet, I may use French for some articles which have nothing to do with non-French people. I hope you will understand that!</p>
<p>However, my English surely is not perfect nor genuine. Therefore, if you see some mistake in my articles, please report it with the Contact form. By the way, don&#8217;t hesitate to make comments on my website or my articles: I do like having feedback, and I try to keep my articles up to date.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.joel.lopes-da-silva.com/2008/03/03/a-matter-of-language/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

