<?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>lab.joelGillman.com &#187; Uncategorized</title>
	<atom:link href="http://lab.joelgillman.com/archives/category/uncategorized/feed" rel="self" type="application/rss+xml" />
	<link>http://lab.joelgillman.com</link>
	<description>Sketches, Code Bites and Toys</description>
	<lastBuildDate>Tue, 12 Jul 2011 15:03:29 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Escape User Input for JavaScript Regex</title>
		<link>http://lab.joelgillman.com/archives/186_escape-user-input-for-javascript-regex</link>
		<comments>http://lab.joelgillman.com/archives/186_escape-user-input-for-javascript-regex#comments</comments>
		<pubDate>Tue, 12 Jul 2011 15:02:23 +0000</pubDate>
		<dc:creator>joel gillman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[escape]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[js]]></category>
		<category><![CDATA[regex]]></category>

		<guid isPermaLink="false">http://lab.joelgillman.com/?p=186</guid>
		<description><![CDATA[Escaping strings for regular expressions in JavaScript is pretty easy when you know what you&#8217;re doing. But say that the input is dynamic, possibly coming from an inexperienced user. That shit has got to be scrubbed! Unfortunately, there is no built in way to do that. Luckily it&#8217;s easy enough to add it in yourself. [...]]]></description>
			<content:encoded><![CDATA[<p>Escaping strings for regular expressions in JavaScript is pretty easy when you know what you&rsquo;re doing. But say that the input is dynamic, possibly coming from an inexperienced user. That shit has got to be scrubbed! Unfortunately, there is no built in way to do that. <em>Luckily</em> it&rsquo;s easy enough to add it in yourself.<span id="more-186"></span></p>
<p>Just pop this code in and you&#8217;re good to go!</p>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">RegExp.<span style="color: #660066;">escape</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>text<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> text.<span style="color: #660066;">replace</span><span style="color: #009900;">&#40;</span><span style="color: #009966; font-style: italic;">/[-[\]{}()*+?.,\\^$|#\s]/g</span><span style="color: #339933;">,</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\\</span>$&amp;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<div class="codecolorer-container javascript default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">RegExp.<span style="color: #660066;">escape</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;($2 + $4) × 2 = $12&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #006600; font-style: italic;">// Outputs</span><br />
<span style="color: #006600; font-style: italic;">// &quot;\(\$2\ \+\ \$4\)\ ×\ 2\ =\ \$12&quot;</span></div></div>
<p>Thanks to Simon Willison who <a href="http://simonwillison.net/2006/Jan/20/escape/#p-6">blogged about it first</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://lab.joelgillman.com/archives/186_escape-user-input-for-javascript-regex/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Download a huge file using split and cat</title>
		<link>http://lab.joelgillman.com/archives/179_download-a-huge-file-using-split-and-ca</link>
		<comments>http://lab.joelgillman.com/archives/179_download-a-huge-file-using-split-and-ca#comments</comments>
		<pubDate>Thu, 14 Apr 2011 14:39:20 +0000</pubDate>
		<dc:creator>joel gillman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[cli]]></category>
		<category><![CDATA[command line]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://lab.joelgillman.com/?p=179</guid>
		<description><![CDATA[I&#8217;ve got a decent internet connection at home sitting around 15 Mbps down. Not top of the line, but respectable nonetheless. I have a personal server that I use to store various files that generally range in size from 150 MB to 14 GB. Now if we lived in a perfect world the download would [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve got a decent internet connection at home sitting around 15 Mbps down. Not top of the line, but respectable nonetheless.</p>
<p>I have a personal server that I use to store various files that generally range in size from 150 MB to 14 GB. Now if we lived in a perfect world the download would take up as much bandwidth as it can which would have me downloading at around 1.8 MB/s. Unfortunately through forces that I understand to be outside my control I only get about 200 Kb/s.</p>
<p>Interestingly, I can download several files from the same sever concurrently at that speed. This is great when downloading several smaller files at the same time, but rather useless when you&#8217;ve got one big one. <em>It doesn&#8217;t seem fair.</em><span id="more-179"></span></p>
<p>This is where split and cat come in! These are two commands you can use via command line (though there are many GUI alternatives, but that&#8217;s lame). Split, of course, will take in a file and <em>split</em> it into smaller pieces. Cat (short for <em>concatenate</em>) will take all those pieces and reassemble them on the other side. Don&#8217;t be afraid, it&#8217;s super easy.</p>
<p>First, on the server, split your large file into a bunch of lil&#8217; pieces.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">split</span> <span style="color: #660033;">-b</span> 500m totally.legit.file.mkv my_split_file_</div></div>
<p>This will split &#8216;totally.legit.file.mkv&#8217; into 500 Mb pieces. The last piece will be less than 500 Mb. Your split up files will be named &#8216;my_split_file_aa&#8217;, &#8216;my_split_file_ab&#8217;, &#8216;my_split_file_ac&#8217; and so on.</p>
<p>Download these files to your local computer.</p>
<p>Now we&#8217;ll concatenate the files back together!</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">cat</span> my_split_file_<span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">&gt;</span> totally.legit.file.mkv</div></div>
<p>Depending on how big the file is this could take a little while. When it&#8217;s done the split files will still be there and you&#8217;ll have a shiny new &#8216;totally.legit.file.mkv&#8217; ready to go!</p>
<p>Don&#8217;t forget to delete the split file pieces that are still laying around on your server and local computers.</p>
]]></content:encoded>
			<wfw:commentRss>http://lab.joelgillman.com/archives/179_download-a-huge-file-using-split-and-ca/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>max-device-width CSS3 Media Query</title>
		<link>http://lab.joelgillman.com/archives/174_max-device-width-css3-media-query</link>
		<comments>http://lab.joelgillman.com/archives/174_max-device-width-css3-media-query#comments</comments>
		<pubDate>Sat, 05 Feb 2011 20:36:16 +0000</pubDate>
		<dc:creator>joel gillman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://lab.joelgillman.com/?p=174</guid>
		<description><![CDATA[CSS3 introduces Media Queries which are an extremely powerful way to customize your site depending on the media that is displaying it. Some people have trouble wrapping their head around the max-device-width query which is commonly used to differentiate between a desktop and mobile browser. To target CSS for the iPhone you would use (max-device-width:480px) [...]]]></description>
			<content:encoded><![CDATA[<p>CSS3 introduces Media Queries which are an extremely powerful way to customize your site depending on the media that is displaying it.</p>
<p>Some people have trouble wrapping their head around the max-device-width query which is commonly used to differentiate between a desktop and mobile browser. To target CSS for the iPhone you would use (max-device-width:480px) since the iPhone&#8217;s screen size is 320px by 480px. Then comes the question &#8220;But if the phone is in the portrait orientation wouldn&#8217;t the maximum width be 320px?&#8221;<span id="more-174"></span></p>
<p>Yes and no. In portrait orientation the maximum width is 320px BUT that is different from the maximum <em>device</em> width which is unchanging.  I think the bit where people get confused is the word &#8220;width&#8221; which generally translates to left and right.</p>
<p>In the case of max-device-width it would be more appropriate to think of it as max-device-<em>dimension</em>. Even if you are able to change the width of the browser on your phone, your phone will always have fixed dimensions and therefore a maximum width.</p>
<p>Is that more clear?</p>
<p><a href="http://www.w3.org/TR/css3-mediaqueries/#device-width" target="_blank">More on the device-width media query at w3.org</a></p>
]]></content:encoded>
			<wfw:commentRss>http://lab.joelgillman.com/archives/174_max-device-width-css3-media-query/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pseudo Work (fwork)</title>
		<link>http://lab.joelgillman.com/archives/159_pseudo-work</link>
		<comments>http://lab.joelgillman.com/archives/159_pseudo-work#comments</comments>
		<pubDate>Thu, 05 Nov 2009 22:16:30 +0000</pubDate>
		<dc:creator>joel gillman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[clock]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[processing]]></category>
		<category><![CDATA[source control]]></category>
		<category><![CDATA[test]]></category>

		<guid isPermaLink="false">http://lab.joelgillman.com/?p=159</guid>
		<description><![CDATA[This script takes a text file (any text file should) and displays it one line at a time with short delays in between. In other words, you can run this script to make it look like your computer is actually doing something worthwhile. I had searched around the internet a few times but never really [...]]]></description>
			<content:encoded><![CDATA[<p>This script takes a text file (any text file should) and displays it one line at a time with short delays in between.  In other words, you can run this script to make it <em>look</em> like your computer is actually doing something worthwhile.</p>
<p>I had searched around the internet a few times but never really found anything like this, but that doesn&#8217;t mean it doesn&#8217;t look.  Maybe I&#8217;m just a bad internet searcher.  <a href="http://lab.joelgillman.com/archives/159_pseudo-work">Script after the jump</a>. <span id="more-159"></span></p>
<p><br/></p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<br />
<span style="color: #666666; font-style: italic;">#####################################################</span><br />
<span style="color: #666666; font-style: italic;"># Pseudo Work (fwork) Script - by Joel Gillman 2009</span><br />
<span style="color: #666666; font-style: italic;"># lab.joelgillman.com/archives/159_pseudo-work</span><br />
<span style="color: #666666; font-style: italic;"># </span><br />
<span style="color: #666666; font-style: italic;"># Please feel free to edit and change this as you</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;like! If &nbsp;you do make any edits I would be curious</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;to see what you've done so drop me a line!</span><br />
<span style="color: #666666; font-style: italic;"># </span><br />
<span style="color: #666666; font-style: italic;"># DISCLAIMER</span><br />
<span style="color: #666666; font-style: italic;"># I am in no way a bash scripting expert. Most of what</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;I write is copy and paste and trial and error.</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;While this script shouldn't hurt anything in your</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;system don't hold me responsible if it does! Use</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;at your own risk.</span><br />
<span style="color: #666666; font-style: italic;">#####################################################</span><br />
<br />
<br />
<span style="color: #666666; font-style: italic;">## test if file (default or otherwise)</span><br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;$1&quot;</span> = <span style="color: #ff0000;">''</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; <span style="color: #007800;">filename</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$HOME</span>/garbage.txt&quot;</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: #660033;">-e</span> <span style="color: #007800;">$filename</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">0</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;No file specified and default file '~/garbage.txt' not found.&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-e</span> <span style="color: #007800;">$1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; <span style="color: #007800;">filename</span>=<span style="color: #007800;">$1</span><br />
<span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;No file found at $1&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #666666; font-style: italic;">## execute fakeness</span><br />
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #c20cb9; font-weight: bold;">read</span> p; <span style="color: #000000; font-weight: bold;">do</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: #ff0000;">&quot;<span style="color: #007800;">$(($RANDOM % 10)</span>)&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #ff0000;">&quot;R1 = (<span style="color: #007800;">$RANDOM</span> % 2)&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">elif</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(($RANDOM % 50)</span>)&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #000000;">1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #ff0000;">&quot;R1 = (<span style="color: #007800;">$RANDOM</span> % 20)&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #ff0000;">&quot;R1 = 0&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">let</span> <span style="color: #ff0000;">&quot;R2 = (<span style="color: #007800;">$RANDOM</span> % 10)&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$p</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #007800;">$R1</span>.<span style="color: #007800;">$R2</span><br />
<span style="color: #000000; font-weight: bold;">done</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #007800;">$filename</span></div></div>
<p><a href="http://lab.joelgillman.com/thepress/wp-content/uploads/2009/11/fwork.zip">Download a zip&#8217;d version of the script</a>.<br />
You can <a href="http://lab.joelgillman.com/thepress/wp-content/uploads/2009/11/garbage.txt">download the (2.5MB) text file</a> I&#8217;ve been using.</p>
<p>Let me know what you think!  Any improvements or suggestions would be greatly appreciated.</p>
]]></content:encoded>
			<wfw:commentRss>http://lab.joelgillman.com/archives/159_pseudo-work/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TWenty One</title>
		<link>http://lab.joelgillman.com/archives/150_twenty-one</link>
		<comments>http://lab.joelgillman.com/archives/150_twenty-one#comments</comments>
		<pubDate>Thu, 20 Aug 2009 23:17:20 +0000</pubDate>
		<dc:creator>joel gillman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://lab.joelgillman.com/?p=150</guid>
		<description><![CDATA[I threw this together in an hour or two. I&#8217;ll post the code if anyone likes, but it&#8217;s really just a sketch so it&#8217;s embarrassingly messy and uncommented. It&#8217;s inspired by the font &#8220;TWenty One&#8221; by SMeltery which is &#8220;a French font factory founded in 2002 by Jack Usine&#8221; There&#8217;s also a larger version for [...]]]></description>
			<content:encoded><![CDATA[<p>I threw this together in an hour or two.  I&#8217;ll post the code if anyone likes, but it&#8217;s really just a sketch so it&#8217;s embarrassingly messy and uncommented.  It&#8217;s inspired by the font &#8220;<a href="http://www.smeltery.net/fonts/twenty-one">TWenty One</a>&#8221; by <a href="http://www.smeltery.net/">SMeltery</a> which is &#8220;a French font factory founded in 2002 by Jack Usine&#8221;<span id="more-150"></span></p>
<p>There&#8217;s also a <a href="/thepress/wp-content/uploads/2009/08/round_blocks_big.swf">larger version</a> for your creation pleasure.</p>
<p>Don&#8217;t forget to hit &#8220;s&#8221; to save out a jpeg of what you made!<br />
<object width="470" height="314"><param name="movie" value="/thepress/wp-content/uploads/2009/08/round_blocks_small.swf"><embed src="/thepress/wp-content/uploads/2009/08/round_blocks_small.swf" width="470" height="314"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://lab.joelgillman.com/archives/150_twenty-one/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iSightCapture, now with more SSH!</title>
		<link>http://lab.joelgillman.com/archives/130_isightcapture-now-with-more-ssh</link>
		<comments>http://lab.joelgillman.com/archives/130_isightcapture-now-with-more-ssh#comments</comments>
		<pubDate>Thu, 30 Apr 2009 18:28:50 +0000</pubDate>
		<dc:creator>joel gillman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[isight]]></category>
		<category><![CDATA[scp]]></category>
		<category><![CDATA[screencapture]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[ssh-keys]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://lab.joelgillman.com/?p=130</guid>
		<description><![CDATA[I think this kind of thing is pretty awesome. Take a picture from your iSight. Take a screencapture. Upload them both to a remote server. WHY DOESN&#8217;T EVERYONE WANT TO DO THIS?! Maybe you do, now you can (hopefully). Firstly, props to Dylan O&#8217;Donnell, who wrote the original script. I was personally unsatisfied with FTP [...]]]></description>
			<content:encoded><![CDATA[<p>I think this kind of thing is pretty awesome.  Take a picture from your iSight.  Take a screencapture.  Upload them both to a remote server. WHY DOESN&#8217;T EVERYONE WANT TO DO THIS?!  Maybe you do, now you can (hopefully).<span id="more-130"></span></p>
<p>Firstly, props to Dylan O&#8217;Donnell, who wrote the original script.  I was personally unsatisfied with FTP because it&#8217;s insecure and I always run into technical troubles with it. Probably because I never took the time to learn what I was doing with FTP via command line&#8230; But I favor SCP for my file transferring needs.<br/><br/></p>
<p>I also added a screen cap functionality because there&#8217;s all kinds of cool things you can do with that down the line.  Time-lapse animation, security, you name it!<br/><br/></p>
<p>If you want the iSight captures to work you must download and install <a href='http://lab.joelgillman.com/thepress/wp-content/uploads/2009/04/isightcapture.zip'>isightcapture</a>! I&#8217;ve installed it to /usr/sbin/ and hardcoded the script to look there. If you don&#8217;t know what you&#8217;re doing, I suggest you do the same.<br/><br/></p>
<p><strong>&#8220;Installing&#8221; isightcapture (assuming it&#8217;s unzipped and on your desktop):</strong></p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">user$ </span><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> ~<span style="color: #000000; font-weight: bold;">/</span>Desktop<span style="color: #000000; font-weight: bold;">/</span>isightcapture <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span></div></div>
<p>Quick rundown of what&#8217;s happening here:<br />
- Grab the date and time info and prepare the filenames (YearMonthDayHourMinuteSecond)<br />
- Take a picture with the iSight, save it to a folder (~/Documents/pics/)<br />
- Take a screencap, save it to the same folder (~/Documents/pics/)<br />
- Resize all of the jpgs in the pics folder so they&#8217;re no more than 800px in any dimention<br />
- Check to see if the computer has a network connection, if it does upload the files to a remote server (via scp) and delete the local images. If there&#8217;s no connection, do nothing (images will try to upload next time the script is run)</p>
<p>In order for this to work <strong><em>you must have SSH Keys setup with the server you are connecting to</em></strong>. If you don&#8217;t it will not work.  If you google &#8220;ssh keys&#8221; there are a million ways to do it but this is the site that actually got it working on my modern mac: <a href="http://www.webficient.com/2007/11/16/mac-and-ssh-keys">http://www.webficient.com/2007/11/16/mac-and-ssh-keys</a><br/><br/></p>
<p>Here&#8217;s a quick and dirty run down of how to do that, but I&#8217;m just copying from <a href="http://www.webficient.com/2007/11/16/mac-and-ssh-keys">Phil&#8217;s post</a> so don&#8217;t blame me if it doesn&#8217;t work for you :)<br/><br/></p>
<p>Generate the ssh key (obviously replace the CAPS stuff with your info). When asked for a passphrase just hit enter, this will make an empty passphrase which, I admit, is very insecure but it&#8217;s better than nothing and the script won&#8217;t work with a passphrase :( :</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">user$ </span><span style="color: #c20cb9; font-weight: bold;">ssh-keygen</span> <span style="color: #660033;">-t</span> rsa <span style="color: #660033;">-f</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa</div></div>
<p>If you&#8217;ve never used SSH to make an outgoing connect on the machine you are connecting to you will also need to create the ssh folder on that machine and make it so only your user can read it:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">user$ </span><span style="color: #c20cb9; font-weight: bold;">ssh</span> USER<span style="color: #000000; font-weight: bold;">@</span>YOUR.SERVER.COM <span style="color: #ff0000;">'mkdir ~/.ssh;chmod 700 ~/.ssh'</span></div></div>
<p>Now copy your public key (id_rsa.pub) to the server you&#8217;re connecting to (I always name the copy on the server &#8220;temp_pub_key&#8221; so I know exactly what file I need):</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">user$ </span><span style="color: #c20cb9; font-weight: bold;">scp</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>id_rsa.pub USER<span style="color: #000000; font-weight: bold;">@</span>YOUR.SERVER.COM:~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span>temp_pub_key</div></div>
<p>Now connect to the remote server and navigate to ~/.ssh/</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">remote-user$ </span><span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>.ssh<span style="color: #000000; font-weight: bold;">/</span></div></div>
<p>On the server, check to see if the file &#8220;authorized_keys&#8221; exists, if it doesn&#8217;t rename your &#8220;temp_pub_key&#8221; to &#8220;authorized_keys:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">remote-user$ </span><span style="color: #c20cb9; font-weight: bold;">mv</span> temp_pub_key authorized_keys</div></div>
<p>If &#8220;authorized_keys&#8221; already exists then you want to add your public key to the end of the file:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">remote-user$ </span><span style="color: #c20cb9; font-weight: bold;">cat</span> temp_pub_key <span style="color: #000000; font-weight: bold;">&amp;</span>gt;<span style="color: #000000; font-weight: bold;">&amp;</span>gt; authorized_keys</div></div>
<p>If &#8220;authorized_keys&#8221; didn&#8217;t already exists, you&#8217;ll also have to set the permissions of the authorized_keys file:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">ssh</span> USER<span style="color: #000000; font-weight: bold;">@</span>YOUR.SERVER.COM <span style="color: #ff0000;">'chmod 644 ~/.ssh/authorized_keys2'</span></div></div>
<p>Here is the automation script originally written by Dylan O&#8217;Donnell with my tweaks and editing for SSH and screencaps.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;height:300px;"><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/bash</span><br />
<span style="color: #666666; font-style: italic;">#</span><br />
<span style="color: #666666; font-style: italic;"># Original iSight Auto Upload Script - by Dylan O'Donnell 2006</span><br />
<span style="color: #666666; font-style: italic;"># Edited for ssh and made more awesome by Joel Gillman 2009 </span><br />
<span style="color: #666666; font-style: italic;">#####################################################</span><br />
<span style="color: #666666; font-style: italic;"># Edit CAPITALS with appropriate details </span><br />
<span style="color: #666666; font-style: italic;"># &nbsp;Notes : You must have ssh-keys setup with the server you are </span><br />
<span style="color: #666666; font-style: italic;"># &nbsp; &nbsp; &nbsp; &nbsp;: uploading to before hand. Otherwise this will not work.</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp; &nbsp; &nbsp; &nbsp;:</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp; &nbsp; &nbsp; &nbsp;: Try here for tutorial on ssh-keys (worked for me)</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp; &nbsp; &nbsp; &nbsp;: &nbsp;http://www.webficient.com/2007/11/16/mac-and-ssh-keys</span><br />
<span style="color: #666666; font-style: italic;">#</span><br />
<span style="color: #666666; font-style: italic;">#####################################################</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Generate filename based on date stamp</span><br />
<span style="color: #007800;">picture</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #000000; font-weight: bold;">%</span>H<span style="color: #000000; font-weight: bold;">%</span>M<span style="color: #000000; font-weight: bold;">%</span>S<span style="color: #7a0874; font-weight: bold;">&#41;</span>_pic.jpg;<br />
<span style="color: #007800;">screen</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">date</span> +<span style="color: #000000; font-weight: bold;">%</span>y<span style="color: #000000; font-weight: bold;">%</span>m<span style="color: #000000; font-weight: bold;">%</span>d<span style="color: #000000; font-weight: bold;">%</span>H<span style="color: #000000; font-weight: bold;">%</span>M<span style="color: #000000; font-weight: bold;">%</span>S<span style="color: #7a0874; font-weight: bold;">&#41;</span>_scr.jpg;<br />
<br />
<span style="color: #666666; font-style: italic;"># Take iSight Photo and store with datestamp filename</span><br />
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>isightcapture <span style="color: #660033;">-w</span> <span style="color: #000000;">640</span> <span style="color: #660033;">-h</span> <span style="color: #000000;">480</span> <span style="color: #660033;">-t</span> jpg <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>USERNAME<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>pics<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$picture</span>;<br />
<br />
<span style="color: #666666; font-style: italic;"># Take screen capture</span><br />
<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>sbin<span style="color: #000000; font-weight: bold;">/</span>screencapture <span style="color: #660033;">-C</span> <span style="color: #660033;">-m</span> <span style="color: #660033;">-t</span> jpg <span style="color: #660033;">-x</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>USERNAME<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>pics<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$screen</span>;<br />
<br />
<span style="color: #666666; font-style: italic;">#resize the pictures so they're not too big</span><br />
<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>sips <span style="color: #660033;">--resampleHeightWidthMax</span> <span style="color: #000000;">800</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>USERNAME<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>pics<span style="color: #000000; font-weight: bold;">/*</span>.jpg<br />
<br />
<span style="color: #666666; font-style: italic;"># Generate semaphore for connectivity by pinging NASA</span><br />
<span style="color: #007800;">isconnected</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">ping</span> <span style="color: #660033;">-c</span> <span style="color: #000000;">1</span> www.nasa.gov <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #000000;">64</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">wc</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{print $1}'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>;<br />
<br />
<span style="color: #666666; font-style: italic;"># Wait a few seconds to see if it's connected.</span><br />
<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">3</span>;<br />
<br />
<span style="color: #666666; font-style: italic;"># If connected...</span><br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$isconnected</span>&quot;</span> <span style="color: #660033;">-eq</span> <span style="color: #ff0000;">&quot;1&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span> <br />
<br />
&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;">scp</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>USERNAME<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>pics<span style="color: #000000; font-weight: bold;">/*</span> USERNAME<span style="color: #000000; font-weight: bold;">@</span>YOUR.SERVER.COM:<span style="color: #ff0000;">&quot;REMOTE/PATH&quot;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># Wait a few seconds, just to make sure everything is clear and complete</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">4</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># delete local images</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>USERNAME<span style="color: #000000; font-weight: bold;">/</span>Documents<span style="color: #000000; font-weight: bold;">/</span>pics<span style="color: #000000; font-weight: bold;">/*</span>.jpg;<br />
<br />
<span style="color: #000000; font-weight: bold;">else</span> <br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># If not connected.. leave captures there until next time. </span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;No Connection, Image not transferred or deleted.&quot;</span>;<br />
<span style="color: #000000; font-weight: bold;">fi</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://lab.joelgillman.com/archives/130_isightcapture-now-with-more-ssh/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SVN For Newbies</title>
		<link>http://lab.joelgillman.com/archives/103_svn-for-newbies</link>
		<comments>http://lab.joelgillman.com/archives/103_svn-for-newbies#comments</comments>
		<pubDate>Thu, 05 Feb 2009 16:06:05 +0000</pubDate>
		<dc:creator>joel gillman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[source control]]></category>
		<category><![CDATA[SVN]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://lab.joelgillman.com/?p=103</guid>
		<description><![CDATA[SVN is confusing, or at least it can be for people who don&#8217;t know their way around the Terminal or aren&#8217;t exactly sure what SVN is. I was confused by it for a long time and I&#8217;m decently technologically inclined. (+1 spelling) This article is intended for those who are forced to use SVN against [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://subversion.tigris.org/">SVN is confusing</a>, or at least it can be for people who don&#8217;t know their way around the Terminal or <a href="http://en.wikipedia.org/wiki/Subversion_(software)">aren&#8217;t exactly sure what SVN is</a>. I was confused by it for a long time and I&#8217;m decently technologically inclined. (+1 spelling) This article is intended for those who are forced to use SVN against their will and I will be very explicit and redundant about what is happening and why.</p>
<p>SVN can be learned!<br/>&nbsp;<br />
You too can learn to love it!<br/>&nbsp;<span id="more-103"></span></p>
<p>Some technical information first, I&#8217;m writing on a mac and I use SVN on a mac. If you ALSO are on a mac, you&#8217;ll need to have the latest Developer Tools installed. They&#8217;re not installed by default so if you haven&#8217;t done this already you should do that now. If you&#8217;ve lost the install CD that came with your computer you can grab it <a href="http://developer.apple.com/technology/xcode.html">here</a> for free (it&#8217;s a <stroke>big</stroke> HUGE download). You probably won&#8217;t use 90% of the stuff that it installs, but there&#8217;s some background stuff going on that you&#8217;ll need (SVN for example).<br/>&nbsp;</p>
<p>Check to see if SVN is installed, open Terminal (Applications > Utilities) and type &#8220;svn&#8221;.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">svn</span><br />
Type <span style="color: #ff0000;">'svn help'</span> <span style="color: #000000; font-weight: bold;">for</span> usage.</div></div>
<p>If you see something similar, it worked! If not, sorry, try Google.</p>
<p>OKAY, install done. There are <a href="http://www.syncrosvnclient.com/">several</a> <a href="http://versionsapp.com/">graphical</a> <a href="http://www.lachoseinteractive.net/en/community/subversion/svnx/features/?sid=099cc11e3657867741478a20916b43b4">interfaces</a> <a href="http://odetoapple.com/2006/svn-plugin-for-finder/">for</a> <a href="http://www.panic.com/coda/">SVN</a> but I&#8217;ve found that none of them can really compare to the command line interface (someone will hate me for saying that). Even if you use a GUI for SVN, sometimes something will break and the program won&#8217;t be able to fix it.<br/>&nbsp;</p>
<p>First I&#8217;ll cover some Terminal basics to help you get around.<br/>&nbsp;</p>
<p>How to change directories (folders):</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">$ </span><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>the<span style="color: #000000; font-weight: bold;">/</span>directory<span style="color: #000000; font-weight: bold;">/</span>you<span style="color: #000000; font-weight: bold;">/</span>want<span style="color: #000000; font-weight: bold;">/</span></div></div>
<p>cd, which probably stands for &#8220;change directory&#8221; is how you&#8217;re going to get around. If you&#8217;re in the terminal, you&#8217;re using cd all the time.</p>
<p>This following commands will take you to the root (<em>Macintosh HD</em>), your home folder (<em>/Users/yourname/</em>), and up one folder, respectively.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #7a0874; font-weight: bold;">cd</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><br />
$ <span style="color: #7a0874; font-weight: bold;">cd</span> ..</div></div>
<p>&nbsp;</p>
<p>Want to see what other folders/files are in the directory you&#8217;re in?</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">$ </span><span style="color: #c20cb9; font-weight: bold;">ls</span></div></div>
<p>If you get lost you can use &#8220;pwd&#8221; which will return the current directory that you are in. (Print Working Directory)</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">$ </span><span style="color: #7a0874; font-weight: bold;">pwd</span></div></div>
<p>&nbsp;</p>
<p>Cluttered screen? Try this:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">$ </span><span style="color: #c20cb9; font-weight: bold;">clear</span></div></div>
<p>Okay, that should be enough to get you scooting around nicely. Let&#8217;s get into some SVN goodness! So first you&#8217;re probably going to want to &#8220;checkout&#8221; a copy of the repository (or repo as I will call it from now on). First cd into the directory where you&#8217;d like your local copy to be. I usually checkout to <em>~/myUserName/Sites/</em> because I&#8217;m usually working with websites, but you can put yours wherever you like. Then get the URL to the repo. You&#8217;ll probably get this from the IT guys or from someone sitting next to you. The following will checkout the repo &#8220;superImportantProject&#8221; which will put a folder called &#8220;superImportantProject&#8221; in whatever directory you&#8217;re currently in.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">svn checkout</span> http:<span style="color: #000000; font-weight: bold;">//</span>svn.companywebsite.com<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>lgn<span style="color: #000000; font-weight: bold;">/</span>trunk<span style="color: #000000; font-weight: bold;">/</span>superImportantProject</div></div>
<p>At this point, assuming you typed the url in correctly, you&#8217;ll see a bunch of text start to appear on your screen. If it&#8217;s going slow enough you can see each file that it&#8217;s downloading to your computer. Magic! You&#8217;ll know it&#8217;s done when you&#8217;ve been returned to the prompt. So you just downloaded a bunch of files to your computer, la-dee-dah. Now&#8217;s when you do your thing and jump into the folder, edit a bunch of copy, add some new images, delete some redundant files.</p>
<p>Great! All done for now, finished what you needed? Cool, now it&#8217;s time to CHECK IN YOUR CHANGES! First, before checking in your changes you want to see if anyone else has made changes to the repo while you&#8217;ve been working.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">$ </span><span style="color: #c20cb9; font-weight: bold;">svn update</span></div></div>
<p>&nbsp;</p>
<p>Hold your breath while it checks &#8211; with any luck no one has made any changes, or at least no changes that have to do with your files. If no changes have been made you&#8217;ll see something like this:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">At revision <span style="color: #000000;">764</span>.</div></div>
<p>&nbsp;</p>
<p>If changes <em>have</em> been made you&#8217;ll see something like:</p>
<div class="codecolorer-container text default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">A &nbsp; &nbsp; &nbsp;public/mainpage.html<br />
D &nbsp; &nbsp; &nbsp;public/fullpage.swf<br />
A &nbsp; &nbsp; &nbsp;public/index.html<br />
A &nbsp; &nbsp; &nbsp;public/thank_you.html<br />
A &nbsp; &nbsp; &nbsp;public/why_use_svn.html<br />
A &nbsp; &nbsp; &nbsp;public/images/sweetpic.jpg<br />
U &nbsp; &nbsp; &nbsp;public/images/yourmom.jpg<br />
U &nbsp; &nbsp; &nbsp;public/images/lolz.gif<br />
Updated to revision 765.</div></div>
<p>The letters before each file tell you what is happening to that file. A for added, D for deleted, U for updated.  If you, god forbid, see a C, that means conflict.  If you see that, you&#8217;re fucked.  Well&#8230;at least you are until you read the part where I talk about that.  But that&#8217;s later!</p>
<p>Okay, so you didn&#8217;t see the dreaded C of conflict. On to the next step. Double check to see what files you&#8217;ve changed/added:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">$ </span><span style="color: #c20cb9; font-weight: bold;">svn status</span></div></div>
<p>&nbsp;</p>
<p>Now a list of all the files you changed, added and deleted will be displayed.  Mine looks like this:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">M &nbsp; &nbsp; &nbsp;index.php<br />
M &nbsp; &nbsp; &nbsp;footer.php<br />
? &nbsp; &nbsp; &nbsp;images<span style="color: #000000; font-weight: bold;">/</span>my_logo.jpg<br />
? &nbsp; &nbsp; &nbsp;images<span style="color: #000000; font-weight: bold;">/</span>sweet_image_4.gif<br />
<span style="color: #000000; font-weight: bold;">!</span> &nbsp; &nbsp; &nbsp;redundant.html</div></div>
<p>Woah, what&#8217;s all that crap mean?  M means that you modified a file (most common).  A ? means that file isn&#8217;t under version control (it&#8217;s not in entered into svn yet).  The ! means that a file is missing.</p>
<p>Well let&#8217;s add those ? files into svn first because those are pretty important for my project.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">svn add</span> images<span style="color: #000000; font-weight: bold;">/</span>my_logo.jpg<br />
$ <span style="color: #c20cb9; font-weight: bold;">svn add</span> images<span style="color: #000000; font-weight: bold;">/</span>sweet_image_4.gif</div></div>
<p>&nbsp;</p>
<p>Or you can string the files together (separated by a space) and add a bunch of files at the same time:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">$ </span><span style="color: #c20cb9; font-weight: bold;">svn add</span> images<span style="color: #000000; font-weight: bold;">/</span>my_logo.jpg images<span style="color: #000000; font-weight: bold;">/</span>sweet_image_4.gif</div></div>
<p>&nbsp;</p>
<p>Now run &#8216;svn status&#8217; again:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">svn status</span><br />
M &nbsp; &nbsp; &nbsp;index.php<br />
M &nbsp; &nbsp; &nbsp;footer.php<br />
A &nbsp; &nbsp; &nbsp;images<span style="color: #000000; font-weight: bold;">/</span>my_logo.jpg<br />
A &nbsp; &nbsp; &nbsp;images<span style="color: #000000; font-weight: bold;">/</span>sweet_image_4.gif<br />
<span style="color: #000000; font-weight: bold;">!</span> &nbsp; &nbsp; &nbsp;redundant.html</div></div>
<p>&nbsp;</p>
<p>Cool, we&#8217;ve got the A of added so those files are ready to go.  Now about that missing file (!).  Did you really mean to delete it?  Does it need to be deleted?  Is anyone going to miss this file?  Think about that for a bit because if you delete that file out of the repository you&#8217;re deleting it for everyone else, too.  Still want to get it out of there?  Okay, but be careful with this one.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">$ </span><span style="color: #c20cb9; font-weight: bold;">svn remove</span> redundant.html</div></div>
<p>&nbsp;</p>
<p>Almost too easy, right? &#8216;svn status&#8217; one more time before we commit just to make doubly sure.</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">svn status</span><br />
M &nbsp; &nbsp; &nbsp;index.php<br />
M &nbsp; &nbsp; &nbsp;footer.php<br />
A &nbsp; &nbsp; &nbsp;images<span style="color: #000000; font-weight: bold;">/</span>my_logo.jpg<br />
A &nbsp; &nbsp; &nbsp;images<span style="color: #000000; font-weight: bold;">/</span>sweet_image_4.gif<br />
D &nbsp; &nbsp; &nbsp;redundant.html</div></div>
<p>Awesome, all the files we changed know what they&#8217;re doing now.  It should be said at this time that it&#8217;s okay to leave files unadded and missing (? and !) but they will be ignored when you commit to the repository.</p>
<p>Time to commit:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;">$ </span><span style="color: #c20cb9; font-weight: bold;">svn commit</span> <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;Changed header copy. Added new images to homepage.&quot;</span></div></div>
<p>The -m in there is an &#8220;option&#8221;.  You&#8217;re telling the command &#8216;svn commit&#8217; to look for a message with your commit.  The commit command won&#8217;t work without a message so you&#8217;ll always need to do that.  The actual message can be as explicit or as vague as you like, just know that the message is logged and can be helpful later if you need to go back and find changes you had made in the past.</p>
<p>Hey, congrats!  You know all the basics of svn to get you through the day!<br/>&nbsp;</p>
<p>This next bit holds some basic tricks to clear up any problems you might have as you flounder your way around svn.<br/>&nbsp;</p>
<p><strong>Crap.  I deleted a file that I didn&#8217;t mean to, how can I get it back?!</strong><br />
Well if you deleted the file locally and didn&#8217;t delete it with &#8216;svn remove&#8217; that&#8217;s easy!  Just run &#8216;svn update&#8217; and you&#8217;ll grab any new files along with any you might be missing. If you deleted it with &#8216;svn remove&#8217; then WHAT THE HELL?!  What were you thinking?!  Fuck, just keep reading for now.</p>
<p><strong>Crap. I&#8217;m getting the dreaded C of conflict.</strong><br />
Oh no!  When this happens svn makes a bunch of crazy-ass files.  Let&#8217;s just say your file was called &#8220;example.html&#8221; because I&#8217;m not feeling very creative right now.  Now you&#8217;ve got:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">example.html<br />
example.html.mine<br />
example.html.r767<br />
example.html.r768</div></div>
<p>If you were to take a look in the example.html file right now you&#8217;d potentially see a bunch of weird code that isn&#8217;t yours.  The file that has all of your changes in it is now called &#8220;example.html.mine&#8221;.  The other two files (r767 and r768) are the revision you were editing from (r767) and the latest revision that&#8217;s in the repository (r768).  The easiest way out of this is to decide what version is the right one.</p>
<ul>
<li>Your co-worker has been working there for years and is way smarter than you, so just assume what they did it is right.  Turn to page 768.  Er, go with revision r768.</li>
<li>Your co-worker is worthless which is why you were hired, your changes are right.  Go with your copy (.mine).</li>
<li>Both of you are idiots so let&#8217;s just start over and let the senior devs deal with it. Go with the old revision (.r767).</li>
</ul>
<p>Whatever you decide, you&#8217;ve got to copy the file you want to go with over the original file then tell svn you&#8217;ve resolved the problem.  My co-worker&#8217;s changes are usually right so I&#8217;ll just go with his:</p>
<div class="codecolorer-container bash default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">cp</span> example.html.r768 example.html<br />
$ <span style="color: #c20cb9; font-weight: bold;">svn resolved</span> example.html<br />
Resolved conflicted state of <span style="color: #ff0000;">'example.html'</span></div></div>
<p>The &#8216;cp&#8217; command is used to copy file A to file B.</p>
<p>That should cover you for awhile&#8230; Once you get the hang of this stuff you shouldn&#8217;t have too much of a problem learning the rest yourself.  If not, I&#8217;m still here!</p>
]]></content:encoded>
			<wfw:commentRss>http://lab.joelgillman.com/archives/103_svn-for-newbies/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Map Function</title>
		<link>http://lab.joelgillman.com/archives/87_map-function</link>
		<comments>http://lab.joelgillman.com/archives/87_map-function#comments</comments>
		<pubDate>Mon, 29 Sep 2008 22:39:41 +0000</pubDate>
		<dc:creator>joel gillman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[normalize]]></category>
		<category><![CDATA[processing]]></category>

		<guid isPermaLink="false">http://lab.joelgillman.com/?p=87</guid>
		<description><![CDATA[If you&#8217;ve ever used Processing you&#8217;ve probably used the &#8216;map&#8217; function. From the Processing Reference section it reads: &#8220;Re-maps a number from one range to another.&#8221; Unfortunately the function doesn&#8217;t exist in Flash, so I rewrote it. Why is this function useful? Lets say your mouse can move within the bounds of your stage from [...]]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever used <a href="http://www.processing.org/">Processing</a> you&#8217;ve probably used the &#8216;map&#8217; function.  From the Processing Reference section it <a href="http://processing.org/reference/map_.html">reads</a>: &#8220;Re-maps a number from one range to another.&#8221;</p>
<p><span id="more-87"></span>Unfortunately the function doesn&#8217;t exist in Flash, so I rewrote it.  Why is this function useful?  Lets say your mouse can move within the bounds of your stage from 0 to 550 pixels along its x-axis.  You want a box to move back and forth from 100 to 200 pixels according to the position of the mouse.  So when your mouse is halfway across the stage your box should be halfway between 100 and 200 pixels.  You would simply use:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">myBox<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> = <span style="color: #004993;">map</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">mouseX</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">550</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">100</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>Easy as that!</p>
<p>Usage:<br />
map(value, low1, high1, low2, high2);<br />
<em>low2 and high2 default to 0 and 1, respectively so you don&#8217;t have to put them in if you just want to normalize your value.</em></p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">map</span><span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;low1<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;high1<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;low2<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;high2<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//if the value and the 1st range low are equal to</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// the new value must be low2</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">value</span> == low1<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> low2<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//normalize both sets to a 0-? range</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> range1 = high1 <span style="color: #000066; font-weight: bold;">-</span> low1<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> range2 = high2 <span style="color: #000066; font-weight: bold;">-</span> low2<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//normalize the value to the new normalized range</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> result = <span style="color: #004993;">value</span> <span style="color: #000066; font-weight: bold;">-</span> low1<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//define the range as a percentage (0.0 to 1.0)</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> ratio = result <span style="color: #000066; font-weight: bold;">/</span> range1<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//find the value in the new normalized-range</span><br />
&nbsp; &nbsp; result = ratio <span style="color: #000066; font-weight: bold;">*</span> range2<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//un-normalize the value in the new range</span><br />
&nbsp; &nbsp; result <span style="color: #000066; font-weight: bold;">+</span>= low2<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> result<span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
<p>And super compressed (less readable, less space, works the same):</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">map</span><span style="color: #000000;">&#40;</span>v<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">,</span> a<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">b</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">y</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = <span style="color: #000000; font-weight:bold;">1</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> <span style="color: #000000;">&#40;</span>v == a<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">?</span> <span style="color: #004993;">x</span> <span style="color: #000066; font-weight: bold;">:</span> <span style="color: #000000;">&#40;</span>v <span style="color: #000066; font-weight: bold;">-</span> a<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">*</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">y</span> <span style="color: #000066; font-weight: bold;">-</span> <span style="color: #004993;">x</span><span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">/</span> <span style="color: #000000;">&#40;</span><span style="color: #004993;">b</span> <span style="color: #000066; font-weight: bold;">-</span> a<span style="color: #000000;">&#41;</span> <span style="color: #000066; font-weight: bold;">+</span> <span style="color: #004993;">x</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://lab.joelgillman.com/archives/87_map-function/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Why You Should Embed Your Fonts</title>
		<link>http://lab.joelgillman.com/archives/73_why-you-should-embed-your-fonts</link>
		<comments>http://lab.joelgillman.com/archives/73_why-you-should-embed-your-fonts#comments</comments>
		<pubDate>Mon, 22 Sep 2008 22:52:36 +0000</pubDate>
		<dc:creator>joel gillman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://lab.joelgillman.com/?p=73</guid>
		<description><![CDATA[I think this should go without saying, but not everyone knows how to do this. First I randomly downloaded a font from dafont.com to make sure that I would be using a font that 99% of people didn&#8217;t have. If you check out the Flash below you can see that the top text field is [...]]]></description>
			<content:encoded><![CDATA[<p>I think this should go without saying, but not everyone knows how to do this.  First I randomly downloaded a font from <a href="http://www.dafont.com/">dafont.com</a> to make sure that I would be using a font that 99% of people didn&#8217;t have.  If you check out the Flash below you can see that the top text field is using some crazy bitmap-esque font.  The text field on the bottom is actually using the same font but since I created it on the stage by hand (rather than dynamically with my code) it is probably displaying Times New Roman.  Or some other default serif typeface.  The the source code for a commented explanation.<br />
<span id="more-73"></span></p>
<div id="flashcontent"></div>
<p><script type="text/javascript">
		var flashvars = {};
		var params = {};
		params.menu = "false";
		var attributes = {};
		swfobject.embedSWF("http://lab.joelgillman.com/thepress/wp-content/uploads/2008/09/embed_font01.swf", "flashcontent", "450", "400", "9.0.0", false, flashvars, params, attributes);
	</script></p>
<p>AS3 Code:</p>
<div class="codecolorer-container actionscript3 default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="actionscript3 codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.display</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=sprite%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:sprite.html"><span style="color: #004993;">Sprite</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=antialiastype%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:antialiastype.html"><span style="color: #004993;">AntiAliasType</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=font%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:font.html"><span style="color: #004993;">Font</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=fontstyle%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:fontstyle.html"><span style="color: #004993;">FontStyle</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=fonttype%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:fonttype.html"><span style="color: #004993;">FontType</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=textfield%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textfield.html"><span style="color: #004993;">TextField</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=textformat%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textformat.html"><span style="color: #004993;">TextFormat</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=textformatalign%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textformatalign.html"><span style="color: #004993;">TextFormatAlign</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #0033ff; font-weight: bold;">import</span> <span style="color: #004993;">flash.text</span><span style="color: #000066; font-weight: bold;">.</span><a href="http://www.google.com/search?q=textrenderer%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textrenderer.html"><span style="color: #004993;">TextRenderer</span></a><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<br />
<span style="color: #6699cc; font-weight: bold;">var</span> format<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=textformat%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textformat.html"><span style="color: #004993;">TextFormat</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=textformat%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textformat.html"><span style="color: #004993;">TextFormat</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">font</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=font%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:font.html"><span style="color: #004993;">Font</span></a> &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color: #0033ff; font-weight: bold;">new</span> bitmapRegular36<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//use the linkage name for the font in the library</span><br />
<span style="color: #6699cc; font-weight: bold;">var</span> <span style="color: #004993;">size</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> &nbsp; &nbsp; &nbsp; = <span style="color: #000000; font-weight:bold;">36</span><span style="color: #000066; font-weight: bold;">;</span><br />
<br />
<br />
<span style="color: #339966; font-weight: bold;">function</span> <span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; format = makeTextFormat<span style="color: #000000;">&#40;</span><span style="color: #004993;">size</span><span style="color: #000066; font-weight: bold;">,</span> <span style="color: #004993;">font</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; makeTextField<span style="color: #000000;">&#40;</span><span style="color: #990000;">&quot;This ridiculous font is dynamicly embedded.&quot;</span><span style="color: #000066; font-weight: bold;">,</span> format<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #339966; font-weight: bold;">function</span> makeTextFormat<span style="color: #000000;">&#40;</span>__size<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a><span style="color: #000066; font-weight: bold;">,</span> __font<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=font%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:font.html"><span style="color: #004993;">Font</span></a><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=textformat%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textformat.html"><span style="color: #004993;">TextFormat</span></a> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> result<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=textformat%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textformat.html"><span style="color: #004993;">TextFormat</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=textformat%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textformat.html"><span style="color: #004993;">TextFormat</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; result<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">font</span> &nbsp; &nbsp; = __font<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">fontName</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; result<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">size</span> &nbsp; &nbsp; = __size<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; result<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">kerning</span> &nbsp;= <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//not availible for non-embedded fonts</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #0033ff; font-weight: bold;">return</span> result<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp;<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #339966; font-weight: bold;">function</span> makeTextField<span style="color: #000000;">&#40;</span>_inputText<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=string%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:string.html"><span style="color: #004993;">String</span></a><span style="color: #000066; font-weight: bold;">,</span> __format<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=textformat%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textformat.html"><span style="color: #004993;">TextFormat</span></a><span style="color: #000066; font-weight: bold;">,</span> __x<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000066; font-weight: bold;">,</span> __y<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=number%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:number.html"><span style="color: #004993;">Number</span></a> = <span style="color: #000000; font-weight:bold;">0</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">:</span><span style="color: #0033ff; font-weight: bold;">void</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #6699cc; font-weight: bold;">var</span> tf<span style="color: #000066; font-weight: bold;">:</span><a href="http://www.google.com/search?q=textfield%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textfield.html"><span style="color: #004993;">TextField</span></a> = <span style="color: #0033ff; font-weight: bold;">new</span> <a href="http://www.google.com/search?q=textfield%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textfield.html"><span style="color: #004993;">TextField</span></a><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">x</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= __x<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">y</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= __y<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">width</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;= <span style="color: #000000; font-weight:bold;">450</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">height</span> &nbsp; &nbsp; &nbsp; &nbsp; = <span style="color: #000000; font-weight:bold;">200</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">type</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = <a href="http://www.google.com/search?q=textfieldtype%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:textfieldtype.html"><span style="color: #004993;">TextFieldType</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">INPUT</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">wordWrap</span> &nbsp; &nbsp; &nbsp; = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">multiline</span> &nbsp; &nbsp; &nbsp;= <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">selectable</span> &nbsp; &nbsp; = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">embedFonts</span> &nbsp; &nbsp; = <span style="color: #0033ff; font-weight: bold;">true</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">antiAliasType</span> &nbsp;= <a href="http://www.google.com/search?q=antialiastype%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:antialiastype.html"><span style="color: #004993;">AntiAliasType</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">ADVANCED</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//not availible for non-embedded fonts</span><br />
&nbsp; &nbsp; tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">gridFitType</span> &nbsp; &nbsp;= <a href="http://www.google.com/search?q=gridfittype%20inurl:http://livedocs.adobe.com/flex/201/langref/%20inurl:gridfittype.html"><span style="color: #004993;">GridFitType</span></a><span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">PIXEL</span><span style="color: #000066; font-weight: bold;">;</span> <span style="color: #009900; font-style: italic;">//not availible for non-embedded fonts</span><br />
&nbsp; &nbsp; tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">text</span> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; = _inputText<span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">//as a general rule, set the textFormat last</span><br />
&nbsp; &nbsp; tf<span style="color: #000066; font-weight: bold;">.</span><span style="color: #004993;">setTextFormat</span><span style="color: #000000;">&#40;</span>__format<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
&nbsp; &nbsp; <br />
&nbsp; &nbsp; <span style="color: #004993;">addChild</span><span style="color: #000000;">&#40;</span>tf<span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #009900; font-style: italic;">//start</span><br />
<span style="color: #004993;">init</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000066; font-weight: bold;">;</span></div></div>
<p>Download the <a href="http://lab.joelgillman.com/thepress/wp-content/uploads/2008/09/embedded_font_demo.zip">source</a>.</p>
<p>Original font by <a href="http://www.dafont.com/sam-derrick.d1882">Sam Derrick</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://lab.joelgillman.com/archives/73_why-you-should-embed-your-fonts/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>False 3D in Flash: Displacement Maps</title>
		<link>http://lab.joelgillman.com/archives/30_false-3d-in-flash-displacement-maps</link>
		<comments>http://lab.joelgillman.com/archives/30_false-3d-in-flash-displacement-maps#comments</comments>
		<pubDate>Wed, 17 Sep 2008 21:53:48 +0000</pubDate>
		<dc:creator>joel gillman</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[AS3]]></category>
		<category><![CDATA[displacement mapping]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[photoshop]]></category>
		<category><![CDATA[source code]]></category>

		<guid isPermaLink="false">http://lab.joelgillman.com/?p=30</guid>
		<description><![CDATA[After seeing a post on the Puny Blog about displacement maps I became interested in how they did it. Unfortunately there wasn&#8217;t any source code so I&#8217;ve replicated the effect from scratch. Turns out displacement maps are really hard to wrap your head around, so I&#8217;ll try to explain it very carefully and slowly. I [...]]]></description>
			<content:encoded><![CDATA[<p>After seeing a <a href="http://www.punyblog.com/2008/08/displacement-map-filter.html">post</a> on the Puny Blog about displacement maps I became interested in how they did it.  Unfortunately there wasn&#8217;t any source code so I&#8217;ve replicated the effect from scratch.<br />
Turns out displacement maps are really hard to wrap your head around, so I&#8217;ll try to explain it very carefully and slowly.<br />
<span id="more-30"></span><br />
I feel that Wikipedia is always a good place to start:</p>
<blockquote><p><b>Displacement mapping</b> is an alternative computer graphics technique in contrast to <a href="/wiki/Bump_mapping" title="Bump mapping">bump mapping</a>, <a href="/wiki/Normal_mapping" title="Normal mapping">normal mapping</a>, and <a href="/wiki/Parallax_mapping" title="Parallax mapping">parallax mapping</a>, using a (<a href="/wiki/Procedural_texture" title="Procedural texture">procedural</a>-) <a href="/wiki/Texture_mapping" title="Texture mapping">texture-</a> or <a href="/wiki/Heightmap" title="Heightmap">height map</a> to cause an effect where the actual geometric position of points over the textured surface are <i>displaced</i>, often along the <a href="/wiki/Locally" title="Locally" class="mw-redirect">local</a> <a href="/wiki/Surface_normal" title="Surface normal">surface normal</a>, according to the value the texture function evaluates to at each point on the surface. It gives surfaces a great sense of depth and detail, permitting in particular self-occlusion, self-shadowing and silhouettes; on the other hand, it is the most costly of this class of techniques owing to the large amount of additional geometry.</p></blockquote>
<p>Displacement maps are commonly used in 3D programs to make complicated geometry using simple 2D images.  In those programs it actually morphs objects in a 3D-space (along a z-axis).  But in our (so far) 2D flash world, it&#8217;s easier to think of the displacement maps as <a href="http://www.edwardsamuels.com/illustratedstory/chapter%204/goo%20-%20mona%20lisa.jpg">distortion</a>.  In plain English, you distort an image using a separate gray scale image.</p>
<p>I&#8217;m a visual thinker so I drew it out in my sketch book first:<br />
<img src="http://lab.joelgillman.com/thepress/wp-content/uploads/2008/09/displacement_breakthrough.png" alt="" title="displacement_breakthrough" width="450" height="275" class="alignnone size-full wp-image-35" /><br />
This is the distortion I wanted to achieve.  If you can&#8217;t read my chicken scratch it says, &#8220;x: -30 to 0 to +30&#8243;.  Meaning that if every square were for 5 pixels, at the grid&#8217;s most distorted point the bottom-left point would be offset by -30 pixels along it&#8217;s &#8216;x&#8217; axis while the bottom-right point is offset by +30 pixels.  The bottom-middle is not offset along the &#8216;x&#8217; axis.</p>
<p><img src="http://lab.joelgillman.com/thepress/wp-content/uploads/2008/09/photoshop_channles.png" alt="" title="photoshop_channels" width="222" height="180" class="alignright size-full wp-image-48" />After drawing out and writing down what would happen to each pixel, translating it into a gradient was pretty easy.  A gray scale image consists of 255 levels, 0 being black and 255 being white.  If you&#8217;re reading this you probably already know that.  You also know that any digital image is made up of three channels: Red, green and blue.  In Photoshop, you can see these channels individually by opening the channels window.  This will be important, or at least handy to know later.  SO, converting those levels into hex you get 00 (black, -30px offset), 80 (middle gray, 0 offset) and FF (white, +30 offset).</p>
<p>I didn&#8217;t want the whole image to be distorted, so part of the image needed to remain unchanged.  This is where the middle-gray comes in.  The gray fades in from the bottom to about a third of the way up the image and from there it is the same even color all the way up.<br />
<img src="http://lab.joelgillman.com/thepress/wp-content/uploads/2008/09/displacement02.png" alt="" title="My second, more successful attempt" width="450" height="327" class="alignnone size-full wp-image-35" /></p>
<p>If you break it out into channels you get this:<br />
<img src="http://lab.joelgillman.com/thepress/wp-content/uploads/2008/09/displacement02_breakout.png" alt="" title="Channel breakout of the displacement map" width="450" height="327" class="alignnone size-full wp-image-35" /><br />
For this example I am only using the RED and BLUE channels (though since the BLUE and GREEN are the same in this case, they are interchangeable).  The BLUE channel goes from black to gray meaning that pixels will be moved in a negative direction, this is the first part of the skewed illusion.  The second, and most important part, comes from the RED channel.  Starting with the most extreme black (00) and fading to the most extreme red (FF), we get our most extreme distortion. Cowabunga!<br />
From there, as we move up, the image fades more and more to middle-gray creating less and less distortion until there is no distortion at all.</p>
<p>At first I used a picture of some pretty flowers to test the distortion, but I realized that with a real photo, it wasn&#8217;t very obvious what had actually been morphed.  I ditched it for a good ol&#8217; grid.  The grid makes it ridiculously easy to tell what&#8217;s been morphed, plus it looks like a cool Tron-esque world.<br />
<img src="http://lab.joelgillman.com/thepress/wp-content/uploads/2008/09/grid.jpg" alt="" title="Grid to be displaced" width="450" height="327" class="alignnone size-full wp-image-35" /></p>
<hr class="space"/>
<p>Check out the <a href="http://lab.joelgillman.com/thepress/wp-content/uploads/2008/09/false3d_demo.html">working demo</a>. (click to turn the distortion on and off)</p>
<hr class="space"/>
<p><a href="http://lab.joelgillman.com/thepress/wp-content/uploads/2008/09/false3d_demo.zip">Download the source</a>.  All code is EXPLICITLY commented.</p>
<hr class="space"/>
<p>A few sites that I found helpful:
<ul>
<li><a href="http://objectpainters.com/blog/2007/01/09/getting-the-displacement-you-need/">Getting the Displacement Your Need</a></li>
<li><a href="http://www.terrypaton.com/as3-bitmap-displacement/">AS3 Bitmap Displacement</a></li>
<li><a href="http://www.emanueleferonato.com/2007/12/03/understanding-flash-displacement-map-filter/">Understanding Flash Displacement Map Filter</a></li>
</ul>
<hr class="space"/>
<p>After all of that the one thing that I still don&#8217;t get is <em>why</em> when the image is distorted why it looks so crappy.  I&#8217;ve tried using different image formats (jpeg vs png) and I&#8217;ve even dynamically drawn in a vector grid, but it still give me that pixelly crap.  Anyone have an answer? (<a href="#comment-2087">Philipp does!</a>)</p>
<p>So it&#8217;s cleaner looking now, but there&#8217;s still some monster pixelation going on.  Anyone know how to .smoothing=true for a displacement map?  Displacement maps need bitmapData and I don&#8217;t think you can do too much to that in the way of smoothing&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://lab.joelgillman.com/archives/30_false-3d-in-flash-displacement-maps/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

