<?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>Cory O&#039;Daniel - These are just words</title>
	<atom:link href="http://coryodaniel.com/index.php/feed/" rel="self" type="application/rss+xml" />
	<link>http://coryodaniel.com</link>
	<description>Software development, thoughts, and randomness</description>
	<lastBuildDate>Fri, 05 Mar 2010 22:53:18 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Attaching local or remote files to Paperclip and Milton Models in Rails (Mocking content_type and original_filename in a Tempfile)</title>
		<link>http://coryodaniel.com/index.php/2010/03/05/attaching-local-or-remote-files-to-paperclip-and-milton-models-in-rails-mocking-content_type-and-original_filename-in-a-tempfile/</link>
		<comments>http://coryodaniel.com/index.php/2010/03/05/attaching-local-or-remote-files-to-paperclip-and-milton-models-in-rails-mocking-content_type-and-original_filename-in-a-tempfile/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 22:53:18 +0000</pubDate>
		<dc:creator>Cory O'Daniel</dc:creator>
				<category><![CDATA[RubyDevelopment]]></category>
		<category><![CDATA[content_type]]></category>
		<category><![CDATA[milton]]></category>
		<category><![CDATA[paperclip]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[tempfile]]></category>

		<guid isPermaLink="false">http://coryodaniel.com/?p=495</guid>
		<description><![CDATA[I was working on a project today where I needed to import some data from MySpace accounts (yeah, MySpace), which included importing the users profile image. In the controller that did the importing I was using OpenURI to retrieve the image and then turn it into a Tempfile to be attached the the model, like [...]]]></description>
			<content:encoded><![CDATA[<p>I was working on a project today where I needed to import some data from MySpace accounts (yeah, MySpace), which included importing the users profile image. In the controller that did the importing I was using OpenURI to retrieve the image and then turn it into a Tempfile to be attached the the model, like so:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> import
<span style="color:#008000; font-style:italic;">#...snip</span>
  tempfile = <span style="color:#CC00FF; font-weight:bold;">Tempfile</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> my_filename<span style="color:#006600; font-weight:bold;">&#41;</span>
  tempfile.<span style="color:#9900CC;">write</span> <span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span> image_url <span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">read</span>
  <span style="color:#0066ff; font-weight:bold;">@imported_user</span>.<span style="color:#9900CC;">images</span>.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:file</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> tempfile<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#008000; font-style:italic;">#...snip</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>This doesn't work.  It blows up missing one of two methods:</p>
<ol>
<li>#original_filename</li>
<li>#content_type</li>
</ol>
<p>If you inspect a normal file upload in Rails which has these methods, you'll find that is just a regular old Tempfile.  But it has the methods! If you create a Tempfile manually, it won't have the methods.  That's because Rails magics them on.  I am not sure why they don't create a subclass like Rails::Tempfile that contains these methods and just use that.  I guess its because OOP is retarded (sarcasm).</p>
<p>So, I wrote a little subclass that will take a file path, and quack like the magic'd rails Tempfiles you get from an upload so you can attach local files to models or even remote files.</p>
<p>This works pretty straightforward and I'm currently using it in production. It won't work on windows systems because the dependency on the 'file' binary. Also, some linux systems are missing this library by default, so make sure you yum|dpkg|apt|port or whatever to get it installed.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'open-uri'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'digest/sha1'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> RemoteFile <span style="color:#006600; font-weight:bold;">&lt;</span> ::<span style="color:#CC00FF; font-weight:bold;">Tempfile</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> initialize<span style="color:#006600; font-weight:bold;">&#40;</span>path, tmpdir = <span style="color:#CC00FF; font-weight:bold;">Dir</span>::tmpdir<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@original_filename</span>  = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">basename</span><span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0066ff; font-weight:bold;">@remote_path</span>        = path
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">super</span> <span style="color:#6666ff; font-weight:bold;">Digest::SHA1</span>.<span style="color:#9900CC;">hexdigest</span><span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span>, tmpdir
    fetch
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> fetch
    string_io = OpenURI.<span style="color:#9900CC;">send</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:open</span>, <span style="color:#0066ff; font-weight:bold;">@remote_path</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">write</span> string_io.<span style="color:#9900CC;">read</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">rewind</span>
    <span style="color:#0000FF; font-weight:bold;">self</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> original_filename
    <span style="color:#0066ff; font-weight:bold;">@original_filename</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> content_type
    mime = <span style="color:#996600;">`file --mime -br #{self.path}`</span>.<span style="color:#9900CC;">strip</span>
    mime = mime.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>^.<span style="color:#006600; font-weight:bold;">*</span>: <span style="color:#006600; font-weight:bold;">*/</span>,<span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    mime = mime.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>;.<span style="color:#006600; font-weight:bold;">*</span>$<span style="color:#006600; font-weight:bold;">/</span>,<span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    mime = mime.<span style="color:#CC0066; font-weight:bold;">gsub</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">/</span>,.<span style="color:#006600; font-weight:bold;">*</span>$<span style="color:#006600; font-weight:bold;">/</span>,<span style="color:#996600;">&quot;&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    mime
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Usage is pretty simple:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">remote_file = RemoteFile.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;http://www.google.com/intl/en_ALL/images/logo.gif&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
remote_file.<span style="color:#9900CC;">original_filename</span> <span style="color:#008000; font-style:italic;">#=&gt; logo.gif</span>
remote_file.<span style="color:#9900CC;">content_type</span> <span style="color:#008000; font-style:italic;">#= image/gif</span></pre></td></tr></table></div>

<p>Using it in your controller:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">def</span> import
  <span style="color:#008000; font-style:italic;">#...snip</span>
  <span style="color:#0066ff; font-weight:bold;">@imported_user</span>.<span style="color:#9900CC;">images</span>.<span style="color:#9900CC;">create</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:file</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> RemoteFile.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span> url_to_image <span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#008000; font-style:italic;">#...snip</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p align="left"><a class="tt" href="http://twitter.com/home/?status=Attaching+local+or+remote+files+to+Paperclip+and+Milton+Models+in+Rails+%28Mocking+content_type+and+original_filename+i...+http://bit.ly/8ZmCoU" title="Post to Twitter"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://digg.com/submit?url=http://coryodaniel.com/index.php/2010/03/05/attaching-local-or-remote-files-to-paperclip-and-milton-models-in-rails-mocking-content_type-and-original_filename-in-a-tempfile/&amp;title=Attaching+local+or+remote+files+to+Paperclip+and+Milton+Models+in+Rails+%28Mocking+content_type+and+original_filename+i..." title="Post to Digg"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-digg-big2.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://coryodaniel.com/index.php/2010/03/05/attaching-local-or-remote-files-to-paperclip-and-milton-models-in-rails-mocking-content_type-and-original_filename-in-a-tempfile/&amp;t=Attaching+local+or+remote+files+to+Paperclip+and+Milton+Models+in+Rails+%28Mocking+content_type+and+original_filename+i..." title="Post to Facebook"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-facebook-big2.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://coryodaniel.com/index.php/2010/03/05/attaching-local-or-remote-files-to-paperclip-and-milton-models-in-rails-mocking-content_type-and-original_filename-in-a-tempfile/&amp;title=Attaching+local+or+remote+files+to+Paperclip+and+Milton+Models+in+Rails+%28Mocking+content_type+and+original_filename+i..." title="Post to Reddit"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-reddit-big2.png" alt="Post to Reddit" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://coryodaniel.com/index.php/2010/03/05/attaching-local-or-remote-files-to-paperclip-and-milton-models-in-rails-mocking-content_type-and-original_filename-in-a-tempfile/&amp;title=Attaching+local+or+remote+files+to+Paperclip+and+Milton+Models+in+Rails+%28Mocking+content_type+and+original_filename+i..." title="Post to StumbleUpon"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-su-big2.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://coryodaniel.com/index.php/2010/03/05/attaching-local-or-remote-files-to-paperclip-and-milton-models-in-rails-mocking-content_type-and-original_filename-in-a-tempfile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A ruby wrapper for Google AjaxLibs (jquery, jquery ui, mootools, prototype, swfobject, etc) [Lazy GoogleJsApi Wrapper]</title>
		<link>http://coryodaniel.com/index.php/2010/02/25/a-ruby-wrapper-for-google-ajaxlibs-jquery-jquery-ui-mootools-prototype-swfobject-etc/</link>
		<comments>http://coryodaniel.com/index.php/2010/02/25/a-ruby-wrapper-for-google-ajaxlibs-jquery-jquery-ui-mootools-prototype-swfobject-etc/#comments</comments>
		<pubDate>Thu, 25 Feb 2010 20:13:27 +0000</pubDate>
		<dc:creator>Cory O'Daniel</dc:creator>
				<category><![CDATA[RubyDevelopment]]></category>
		<category><![CDATA[ajax libs]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://coryodaniel.com/?p=489</guid>
		<description><![CDATA[I like using the Google AjaxLibs API. Its cool to not host files when I don't have to, especially ones I know a user has already probably cached from Google anyway (even though Google Page speed busts my balls about too many DNS lookups  ).
I do on the other hand hate watching in the [...]]]></description>
			<content:encoded><![CDATA[<p>I like using the Google AjaxLibs API. Its cool to not host files when I don't have to, especially ones I know a user has already probably cached from Google anyway (even though Google Page speed busts my balls about too many DNS lookups <img src='http://coryodaniel.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ).</p>
<p>I do on the other hand hate watching in the bottom of my browser "Waiting for google.com" when using the standard Javascript API for loading the Libraries like so:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;http://www.google.com/jsapi?key=INSERT-YOUR-KEY&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
 google.load(&quot;jquery&quot;, &quot;1.4.2&quot;);
&lt;/script&gt;</pre></td></tr></table></div>

<p>And you don't have to wait, you can totally do something like:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="html" style="font-family:monospace;">&lt;script type=&quot;text/javascript&quot; src=&quot;http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js&quot;&gt;&lt;/script&gt;</pre></td></tr></table></div>

<p>Which is why I wrote this little ruby wrapper. Its nothing special. It just encapsulates all the URLs for the libraries and their versions to allow you to not remember the URL and not have to go looking for the documentation when you start a new app or just need an additional library.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Docs: http://code.google.com/apis/ajaxlibs/documentation/index.html</span>
<span style="color:#008000; font-style:italic;">#</span>
<span style="color:#9966CC; font-weight:bold;">class</span> GoogleJsApi
  BaseURL = <span style="color:#996600;">&quot;http://ajax.googleapis.com/ajax/libs&quot;</span>.<span style="color:#9900CC;">freeze</span>
&nbsp;
  Libraries = <span style="color:#006600; font-weight:bold;">&#123;</span> 
    <span style="color:#996600;">&quot;jquery&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#ff3333; font-weight:bold;">:versions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>1.2.3 1.2.6 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1 1.4.2<span style="color:#006600; font-weight:bold;">&#41;</span>,
      <span style="color:#ff3333; font-weight:bold;">:compressed_url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/jquery/%s/jquery.min.js&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:uncompressed_url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/jquery/%s/jquery.js&quot;</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>,
    <span style="color:#996600;">&quot;jqueryui&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#ff3333; font-weight:bold;">:versions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>1.5.2 1.5.3 <span style="color:#006666;">1.6</span> 1.7.0 1.7.1 1.7.2<span style="color:#006600; font-weight:bold;">&#41;</span>,
      <span style="color:#ff3333; font-weight:bold;">:compressed_url</span>   <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/jqueryui/%s/jquery-ui.min.js&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:uncompressed_url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/jqueryui/%s/jquery-ui.js&quot;</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>,
    <span style="color:#996600;">&quot;prototype&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#ff3333; font-weight:bold;">:versions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>1.6.0.2 1.6.0.3 1.6.1.0<span style="color:#006600; font-weight:bold;">&#41;</span>,
      <span style="color:#ff3333; font-weight:bold;">:compressed_url</span>   <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:uncompressed_url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/prototype/%s/prototype.js&quot;</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>,
    <span style="color:#996600;">&quot;scriptaculous&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#ff3333; font-weight:bold;">:versions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>1.8.1 1.8.2 1.8.3<span style="color:#006600; font-weight:bold;">&#41;</span>,
      <span style="color:#ff3333; font-weight:bold;">:compressed_url</span>   <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:uncompressed_url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/scriptaculous/%s/scriptaculous.js&quot;</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>,
    <span style="color:#996600;">&quot;mootools&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#ff3333; font-weight:bold;">:versions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>1.1.1 1.1.2 1.2.1 1.2.2 1.2.3 1.2.4<span style="color:#006600; font-weight:bold;">&#41;</span>,
      <span style="color:#ff3333; font-weight:bold;">:compressed_url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/mootools/%s/mootools-yui-compressed.js&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:uncompressed_url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/mootools/%s/mootools.js&quot;</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>,
    <span style="color:#996600;">&quot;dojo&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#ff3333; font-weight:bold;">:versions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>1.1.1 1.2.0 1.2.3 1.3.0 1.3.1 1.3.2 1.4.0 1.4.1<span style="color:#006600; font-weight:bold;">&#41;</span>,
      <span style="color:#ff3333; font-weight:bold;">:compressed_url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/dojo/%s/dojo/dojo.xd.js&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:uncompressed_url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/dojo/%s/dojo/dojo.xd.js.uncompressed.js&quot;</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>,
    <span style="color:#996600;">&quot;swfobject&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#ff3333; font-weight:bold;">:versions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006666;">2.1</span> <span style="color:#006666;">2.2</span><span style="color:#006600; font-weight:bold;">&#41;</span>,
      <span style="color:#ff3333; font-weight:bold;">:compressed_url</span>   <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/swfobject/%s/swfobject.js&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:uncompressed_url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/swfobject/%s/swfobject_src.js&quot;</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>,
    <span style="color:#996600;">&quot;yui&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#ff3333; font-weight:bold;">:versions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>2.6.0 2.7.0 2.8.0r4<span style="color:#006600; font-weight:bold;">&#41;</span>,
      <span style="color:#ff3333; font-weight:bold;">:compressed_url</span>   <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/yui/%s/build/yuiloader/yuiloader-min.js&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:uncompressed_url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/yui/%s/build/yuiloader/yuiloader.js&quot;</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>,
    <span style="color:#996600;">&quot;ext-core&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#ff3333; font-weight:bold;">:versions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>3.0.0 3.1.0<span style="color:#006600; font-weight:bold;">&#41;</span>,
      <span style="color:#ff3333; font-weight:bold;">:compressed_url</span>   <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/ext-core/%s/ext-core.js&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:uncompressed_url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/ext-core/%s/ext-core-debug.js&quot;</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span>,
    <span style="color:#996600;">&quot;chrome-frame&quot;</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span>
      <span style="color:#ff3333; font-weight:bold;">:versions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">%</span>w<span style="color:#006600; font-weight:bold;">&#40;</span>1.0.0 1.0.1 1.0.2<span style="color:#006600; font-weight:bold;">&#41;</span>,
      <span style="color:#ff3333; font-weight:bold;">:compressed_url</span>   <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/chrome-frame/%s/CFInstall.min.js&quot;</span>,
      <span style="color:#ff3333; font-weight:bold;">:uncompressed_url</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;/chrome-frame/%s/CFInstall.js&quot;</span>
    <span style="color:#006600; font-weight:bold;">&#125;</span> 
  <span style="color:#006600; font-weight:bold;">&#125;</span>.<span style="color:#9900CC;">freeze</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#0000FF; font-weight:bold;">self</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#9966CC; font-weight:bold;">include</span><span style="color:#006600; font-weight:bold;">&#40;</span>name, version=<span style="color:#0000FF; font-weight:bold;">nil</span>, compressed=<span style="color:#0000FF; font-weight:bold;">true</span>, validate_version=<span style="color:#0000FF; font-weight:bold;">true</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      name = name.<span style="color:#9900CC;">to_s</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> lib = <span style="color:#6666ff; font-weight:bold;">GoogleJsApi::Libraries</span><span style="color:#006600; font-weight:bold;">&#91;</span>name<span style="color:#006600; font-weight:bold;">&#93;</span>
        version <span style="color:#006600; font-weight:bold;">||</span>= lib<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:versions</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">last</span>
&nbsp;
        <span style="color:#9966CC; font-weight:bold;">if</span> validate_version <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> lib<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:versions</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9966CC; font-weight:bold;">include</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>version<span style="color:#006600; font-weight:bold;">&#41;</span>
          GoogleJsApi.<span style="color:#9900CC;">url_for</span><span style="color:#006600; font-weight:bold;">&#40;</span>name, version, compressed<span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">elsif</span> !validate_version
          GoogleJsApi.<span style="color:#9900CC;">url_for</span><span style="color:#006600; font-weight:bold;">&#40;</span>name, version, compressed<span style="color:#006600; font-weight:bold;">&#41;</span>
        <span style="color:#9966CC; font-weight:bold;">else</span>
          <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#CC00FF; font-weight:bold;">Exception</span>, <span style="color:#996600;">&quot;Invalid version (#{version}) for #{name}&quot;</span>
        <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>
        <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#CC00FF; font-weight:bold;">Exception</span>, <span style="color:#996600;">&quot;Unknown Google Javascript Library&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#9966CC; font-weight:bold;">def</span> version_info
      tmp_version = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
      <span style="color:#6666ff; font-weight:bold;">GoogleJsApi::Libraries</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>k,v<span style="color:#006600; font-weight:bold;">|</span>
        tmp_version<span style="color:#006600; font-weight:bold;">&#91;</span> k <span style="color:#006600; font-weight:bold;">&#93;</span> = v<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:versions</span><span style="color:#006600; font-weight:bold;">&#93;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      tmp_version
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    protected
    <span style="color:#9966CC; font-weight:bold;">def</span> url_for<span style="color:#006600; font-weight:bold;">&#40;</span>name, version, compressed<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#6666ff; font-weight:bold;">GoogleJsApi::BaseURL</span> <span style="color:#006600; font-weight:bold;">+</span>
      <span style="color:#6666ff; font-weight:bold;">GoogleJsApi::Libraries</span><span style="color:#006600; font-weight:bold;">&#91;</span> name <span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#91;</span> compressed ? <span style="color:#ff3333; font-weight:bold;">:compressed_url</span> : <span style="color:#ff3333; font-weight:bold;">:uncompressed_url</span> <span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">%</span> version
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Here are some tests for it if you are interested in how/if it works:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'pp'</span>
&nbsp;
pp GoogleJsApi.<span style="color:#9900CC;">version_info</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Include the newest version of a library</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> GoogleJsApi.<span style="color:#9966CC; font-weight:bold;">include</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'jquery'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Include a specific version of a library</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> GoogleJsApi.<span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#996600;">&quot;chrome-frame&quot;</span>, <span style="color:#996600;">&quot;1.0.0&quot;</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Include a specific version of a library uncompressed</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> GoogleJsApi.<span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#996600;">&quot;chrome-frame&quot;</span>, <span style="color:#996600;">&quot;1.0.0&quot;</span>, <span style="color:#0000FF; font-weight:bold;">false</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># Include a specific version of a library w/o validating the version; useful if this goes out of date :P</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> GoogleJsApi.<span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#996600;">&quot;jquery&quot;</span>, <span style="color:#996600;">&quot;NOT_A_VERSION&quot;</span>, <span style="color:#0000FF; font-weight:bold;">false</span>, <span style="color:#0000FF; font-weight:bold;">false</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">begin</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> GoogleJsApi.<span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#ff3333; font-weight:bold;">:jqueryui</span>, <span style="color:#996600;">&quot;1.0&quot;</span>
<span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">Exception</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> e
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;This should blow up...&quot;</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> e.<span style="color:#9900CC;">message</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>If you want to use it in your Rails or Merb app you can do:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Rails</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'google_js_api'</span> <span style="color:#008000; font-style:italic;">#or whatever you named the file when you dropped it in lib</span>
&nbsp;
<span style="color:#008000; font-style:italic;"># In your application layout or whatever</span>
javascript_include_tag GoogleJsApi.<span style="color:#9966CC; font-weight:bold;">include</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:jquery</span>, <span style="color:#996600;">&quot;1.4.0&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># Merb</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'google_js_api'</span> <span style="color:#008000; font-style:italic;">#or whatever you named the file when you dropped it in lib</span>
&nbsp;
<span style="color:#008000; font-style:italic;">#in your application layout or where ever</span>
require_js GoogleJsApi.<span style="color:#9966CC; font-weight:bold;">include</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:swfobject</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>Its simple, its lazy. I like it.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=A+ruby+wrapper+for+Google+AjaxLibs+%28jquery%2C+jquery+ui%2C+mootools%2C+prototype%2C+swfobject%2C+etc%29+%5BLazy+GoogleJsApi+Wrapper%5D+http://bit.ly/cX2ihG" title="Post to Twitter"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://digg.com/submit?url=http://coryodaniel.com/index.php/2010/02/25/a-ruby-wrapper-for-google-ajaxlibs-jquery-jquery-ui-mootools-prototype-swfobject-etc/&amp;title=A+ruby+wrapper+for+Google+AjaxLibs+%28jquery%2C+jquery+ui%2C+mootools%2C+prototype%2C+swfobject%2C+etc%29+%5BLazy+GoogleJsApi+Wrapper%5D" title="Post to Digg"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-digg-big2.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://coryodaniel.com/index.php/2010/02/25/a-ruby-wrapper-for-google-ajaxlibs-jquery-jquery-ui-mootools-prototype-swfobject-etc/&amp;t=A+ruby+wrapper+for+Google+AjaxLibs+%28jquery%2C+jquery+ui%2C+mootools%2C+prototype%2C+swfobject%2C+etc%29+%5BLazy+GoogleJsApi+Wrapper%5D" title="Post to Facebook"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-facebook-big2.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://coryodaniel.com/index.php/2010/02/25/a-ruby-wrapper-for-google-ajaxlibs-jquery-jquery-ui-mootools-prototype-swfobject-etc/&amp;title=A+ruby+wrapper+for+Google+AjaxLibs+%28jquery%2C+jquery+ui%2C+mootools%2C+prototype%2C+swfobject%2C+etc%29+%5BLazy+GoogleJsApi+Wrapper%5D" title="Post to Reddit"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-reddit-big2.png" alt="Post to Reddit" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://coryodaniel.com/index.php/2010/02/25/a-ruby-wrapper-for-google-ajaxlibs-jquery-jquery-ui-mootools-prototype-swfobject-etc/&amp;title=A+ruby+wrapper+for+Google+AjaxLibs+%28jquery%2C+jquery+ui%2C+mootools%2C+prototype%2C+swfobject%2C+etc%29+%5BLazy+GoogleJsApi+Wrapper%5D" title="Post to StumbleUpon"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-su-big2.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://coryodaniel.com/index.php/2010/02/25/a-ruby-wrapper-for-google-ajaxlibs-jquery-jquery-ui-mootools-prototype-swfobject-etc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why the hell can&#8217;t Apple fix this bug? &#8211; Snow Leopard Keyboard hangs when changing spaces</title>
		<link>http://coryodaniel.com/index.php/2010/02/23/why-the-hell-cant-apple-fix-this-bug-snow-leopard-keyboard-hangs-when-changing-spaces/</link>
		<comments>http://coryodaniel.com/index.php/2010/02/23/why-the-hell-cant-apple-fix-this-bug-snow-leopard-keyboard-hangs-when-changing-spaces/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 00:49:36 +0000</pubDate>
		<dc:creator>Cory O'Daniel</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[bug]]></category>
		<category><![CDATA[die die die]]></category>
		<category><![CDATA[keyboard]]></category>
		<category><![CDATA[kill dock]]></category>
		<category><![CDATA[spaces]]></category>
		<category><![CDATA[suckfest]]></category>

		<guid isPermaLink="false">http://coryodaniel.com/?p=482</guid>
		<description><![CDATA[Everyone knows about this bug, except apparently Apple. 
In Snow Leopard the keyboard hangs occasionally when changing spaces. Sometimes for only a few seconds, sometimes forever. All sorts of people are talking or reporting about this issue. 
Why isn't it being fixed? Hallo there, Apple? Are you there?
There are currently about 100 posts in the [...]]]></description>
			<content:encoded><![CDATA[<p>Everyone knows about this bug, except apparently Apple. </p>
<p>In Snow Leopard the keyboard hangs occasionally when changing spaces. Sometimes for only a few seconds, sometimes forever. All sorts of people are talking or <a href="http://reviews.cnet.com/8301-13727_7-10369937-263.html">reporting</a> <a href="http://reviews.cnet.com/8301-13727_7-10361439-263.html?tag=mncol;txt">about</a> this <a href="http://discussions.apple.com/thread.jspa?threadID=2161076&#038;start=90&#038;tstart=0">issue</a>. </p>
<p>Why isn't it being fixed? Hallo there, Apple? Are you there?</p>
<p>There are currently about 100 posts in the Apple support thread dating back from Sep 15, 2009. You know whats annoying? Killing your Dock constantly while you are working.</p>
<p>Apple: SrSLy 4real. Fix this. Its equivalent to working really hard and someone smacking you in the forehead randomly. It kinda sucks, and its really irritating.</p>
<p>(Note: My keyboard only hung once during this post).</p>
<p><strong><br />
Update: March 3, 2010</strong></p>
<p>After some further research, at least for me and a few others, this bug is tied to an application called <a href="http://getsatisfaction.com/irradiatedsoftware/topics/cinch_causing_switching_spaces_by_hotkey_to_stuck_the_screen_keyboard">Cinch</a>. If you have Cinch installed, try uninstalling it and seeing if this problem goes away. A pretty useful app, but I'd rather resize my windows manually than 'get interrupted' when I'm in my workflow.</p>
<p>I uninstalled Cinch 5 days ago, and the problem has gone away for me. I was having my keyboard hang 4 or 5 times a day with it installed.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Why+the+hell+can%E2%80%99t+Apple+fix+this+bug%3F+%E2%80%93+Snow+Leopard+Keyboard+hangs+when+changing+spaces+http://bit.ly/doaABF" title="Post to Twitter"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://digg.com/submit?url=http://coryodaniel.com/index.php/2010/02/23/why-the-hell-cant-apple-fix-this-bug-snow-leopard-keyboard-hangs-when-changing-spaces/&amp;title=Why+the+hell+can%E2%80%99t+Apple+fix+this+bug%3F+%E2%80%93+Snow+Leopard+Keyboard+hangs+when+changing+spaces" title="Post to Digg"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-digg-big2.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://coryodaniel.com/index.php/2010/02/23/why-the-hell-cant-apple-fix-this-bug-snow-leopard-keyboard-hangs-when-changing-spaces/&amp;t=Why+the+hell+can%E2%80%99t+Apple+fix+this+bug%3F+%E2%80%93+Snow+Leopard+Keyboard+hangs+when+changing+spaces" title="Post to Facebook"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-facebook-big2.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://coryodaniel.com/index.php/2010/02/23/why-the-hell-cant-apple-fix-this-bug-snow-leopard-keyboard-hangs-when-changing-spaces/&amp;title=Why+the+hell+can%E2%80%99t+Apple+fix+this+bug%3F+%E2%80%93+Snow+Leopard+Keyboard+hangs+when+changing+spaces" title="Post to Reddit"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-reddit-big2.png" alt="Post to Reddit" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://coryodaniel.com/index.php/2010/02/23/why-the-hell-cant-apple-fix-this-bug-snow-leopard-keyboard-hangs-when-changing-spaces/&amp;title=Why+the+hell+can%E2%80%99t+Apple+fix+this+bug%3F+%E2%80%93+Snow+Leopard+Keyboard+hangs+when+changing+spaces" title="Post to StumbleUpon"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-su-big2.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://coryodaniel.com/index.php/2010/02/23/why-the-hell-cant-apple-fix-this-bug-snow-leopard-keyboard-hangs-when-changing-spaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lower ACL Permissions on Amazon S3 items with ruby</title>
		<link>http://coryodaniel.com/index.php/2010/02/11/lower-acl-permissions-on-amazon-s3-items-with-ruby/</link>
		<comments>http://coryodaniel.com/index.php/2010/02/11/lower-acl-permissions-on-amazon-s3-items-with-ruby/#comments</comments>
		<pubDate>Fri, 12 Feb 2010 01:10:21 +0000</pubDate>
		<dc:creator>Cory O'Daniel</dc:creator>
				<category><![CDATA[RubyDevelopment]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[s3]]></category>

		<guid isPermaLink="false">http://coryodaniel.com/?p=473</guid>
		<description><![CDATA[I recently had to change a bunch of permissions on some items on S3. Unfortunately the items were mixed in with items that I didn't want to change the permissions on and the file names are all kinda jumbled, so I couldn't pinpoint what I needed to change by eyeballing the file names. 
So I [...]]]></description>
			<content:encoded><![CDATA[<p>I recently had to change a bunch of permissions on some items on S3. Unfortunately the items were mixed in with items that I didn't want to change the permissions on and the file names are all kinda jumbled, so I couldn't pinpoint what I needed to change by eyeballing the file names. </p>
<p>So I wrote a little ruby method to go in and change something given a key and bucket name.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'aws/s3'</span>
&nbsp;
<span style="color:#6666ff; font-weight:bold;">AWS::S3::Base</span>.<span style="color:#9900CC;">establish_connection</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>
  <span style="color:#ff3333; font-weight:bold;">:access_key_id</span>     <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;YOUR_ACCESS_KEY&quot;</span>,
  <span style="color:#ff3333; font-weight:bold;">:secret_access_key</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;YOUR_SECRET_KEY&quot;</span>
<span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">include</span> <span style="color:#6666ff; font-weight:bold;">AWS::S3</span>
<span style="color:#9966CC; font-weight:bold;">def</span> s3_set_public_read<span style="color:#006600; font-weight:bold;">&#40;</span>key, bucket<span style="color:#006600; font-weight:bold;">&#41;</span>
  <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Processing: #{key}&quot;</span>  
&nbsp;
  policy = S3Object.<span style="color:#9900CC;">acl</span><span style="color:#006600; font-weight:bold;">&#40;</span>key, bucket<span style="color:#006600; font-weight:bold;">&#41;</span>
  policy.<span style="color:#9900CC;">grants</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#6666ff; font-weight:bold;">ACL::Grant</span>.<span style="color:#9900CC;">grant</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:public_read</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  policy.<span style="color:#9900CC;">grants</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#6666ff; font-weight:bold;">ACL::Grant</span>.<span style="color:#9900CC;">grant</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:public_read_acp</span><span style="color:#006600; font-weight:bold;">&#41;</span>
  S3Object.<span style="color:#9900CC;">acl</span><span style="color:#006600; font-weight:bold;">&#40;</span>key, bucket, policy<span style="color:#006600; font-weight:bold;">&#41;</span>      
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Now I can just run a loop of ActiveRecord objects around that method and convert them all to public read.</p>
<p>If you want a GUI tool for managing S3 stuff, I totally recommend <a href="http://s3hub.com/">S3Hub</a>. Its a really sexy tool for managing S3.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Lower+ACL+Permissions+on+Amazon+S3+items+with+ruby+http://bit.ly/aF9nC6" title="Post to Twitter"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://digg.com/submit?url=http://coryodaniel.com/index.php/2010/02/11/lower-acl-permissions-on-amazon-s3-items-with-ruby/&amp;title=Lower+ACL+Permissions+on+Amazon+S3+items+with+ruby" title="Post to Digg"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-digg-big2.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://coryodaniel.com/index.php/2010/02/11/lower-acl-permissions-on-amazon-s3-items-with-ruby/&amp;t=Lower+ACL+Permissions+on+Amazon+S3+items+with+ruby" title="Post to Facebook"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-facebook-big2.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://coryodaniel.com/index.php/2010/02/11/lower-acl-permissions-on-amazon-s3-items-with-ruby/&amp;title=Lower+ACL+Permissions+on+Amazon+S3+items+with+ruby" title="Post to Reddit"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-reddit-big2.png" alt="Post to Reddit" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://coryodaniel.com/index.php/2010/02/11/lower-acl-permissions-on-amazon-s3-items-with-ruby/&amp;title=Lower+ACL+Permissions+on+Amazon+S3+items+with+ruby" title="Post to StumbleUpon"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-su-big2.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://coryodaniel.com/index.php/2010/02/11/lower-acl-permissions-on-amazon-s3-items-with-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing MySQL on Mac OSX w/ Ports</title>
		<link>http://coryodaniel.com/index.php/2010/02/11/installing-mysql-on-mac-osx-w-ports/</link>
		<comments>http://coryodaniel.com/index.php/2010/02/11/installing-mysql-on-mac-osx-w-ports/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 19:08:31 +0000</pubDate>
		<dc:creator>Cory O'Daniel</dc:creator>
				<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[mac osx]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[ports]]></category>

		<guid isPermaLink="false">http://coryodaniel.com/?p=470</guid>
		<description><![CDATA[So, I originally installed MySQL on my new MacBook using the DMG as was alluded to in a previous post..
I rebooted my laptop the other day and for some reason all of my tables (InnoDB) where corrupted... I couldn't get them to repair. All the *.frm files were present. Even when I did a 'show [...]]]></description>
			<content:encoded><![CDATA[<p>So, I originally installed MySQL on my new MacBook using the DMG as was alluded to in a <a href="http://coryodaniel.com/index.php/2010/01/20/installing-mysql-from-dmg-on-mac-and-the-few-commands-to-make-it-work-on-the-command-line/">previous post.</a>.</p>
<p>I rebooted my laptop the other day and for some reason all of my tables (InnoDB) where corrupted... I couldn't get them to repair. All the *.frm files were present. Even when I did a 'show tables' they would show up, but whenever I issued any DML mysql responded saying the table did not exist.</p>
<p>So I decided to wipe out my MySQL install, because it just seemed funky. I decided to go the ports route, and I'm so used to the doing the bastardized old way of installing it</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> mysql5 +server +devel</pre></td></tr></table></div>

<p>Then proceeding to do about 5000 things to get it to start at boot time and have a *.sock file in the right place.</p>
<p>Then I came across <a href="http://stackoverflow.com/questions/1081231/macports-doesnt-install-org-macports-mysql5-plist-with-mysql5-server">this post</a> while looking for a LaunchD file for MySQL. A comment by Mike Richards points out that there is a hip new (working) way of installing mysql with ports:</p>
<blockquote><p>
The mysql5 +server package variant in MacPorts is obsolete, and is superseded by the mysql5-server package, which you install in addition to mysql5. This allows you to build it after the fact, instead of re-compiling the entire mysql5 package with +server.</p>
<p>I'd suggest to just remove your old mysql5 +server, and install using the following.</p>
<p>sudo port install mysql5-server<br />
That'll build both the required mysql5 and mysql5-server packages for you, and you'll have the mysql5 plist file in /Library/LaunchDaemons. Also note that you no longer need to symlink your mysqld.sock to /tmp/mysql.sock.
</p></blockquote>
<p>Thanks Mike!</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> mysql5-server</pre></td></tr></table></div>

<p>And who would of thunk it? It 'just works' (as a side note, the binary name is mysql5 incase you don't think it works when you type 'mysql').</p>
<p>Make sure you read all the output from Port. You'll need to load the LaunchD file in launchctl and either manually start MySQL the first time or just reboot and have OSX do it for you.</p>
<p>Yay. I can do some work now. </p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Installing+MySQL+on+Mac+OSX+w%2F+Ports+http://bit.ly/d7owK3" title="Post to Twitter"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://digg.com/submit?url=http://coryodaniel.com/index.php/2010/02/11/installing-mysql-on-mac-osx-w-ports/&amp;title=Installing+MySQL+on+Mac+OSX+w%2F+Ports" title="Post to Digg"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-digg-big2.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://coryodaniel.com/index.php/2010/02/11/installing-mysql-on-mac-osx-w-ports/&amp;t=Installing+MySQL+on+Mac+OSX+w%2F+Ports" title="Post to Facebook"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-facebook-big2.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://coryodaniel.com/index.php/2010/02/11/installing-mysql-on-mac-osx-w-ports/&amp;title=Installing+MySQL+on+Mac+OSX+w%2F+Ports" title="Post to Reddit"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-reddit-big2.png" alt="Post to Reddit" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://coryodaniel.com/index.php/2010/02/11/installing-mysql-on-mac-osx-w-ports/&amp;title=Installing+MySQL+on+Mac+OSX+w%2F+Ports" title="Post to StumbleUpon"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-su-big2.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://coryodaniel.com/index.php/2010/02/11/installing-mysql-on-mac-osx-w-ports/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Expiring rails fragement caches using an expires time instead of a sweeper (expires_in) &#8211; (a &#8216;duh&#8217; post)</title>
		<link>http://coryodaniel.com/index.php/2010/02/10/expiring-rails-fragement-caches-using-an-expires-time-instead-of-a-sweeper-expires_in-a-duh-post/</link>
		<comments>http://coryodaniel.com/index.php/2010/02/10/expiring-rails-fragement-caches-using-an-expires-time-instead-of-a-sweeper-expires_in-a-duh-post/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 00:50:33 +0000</pubDate>
		<dc:creator>Cory O'Daniel</dc:creator>
				<category><![CDATA[RubyDevelopment]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[cache]]></category>
		<category><![CDATA[duh]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://coryodaniel.com/?p=466</guid>
		<description><![CDATA[So, I'm setting up fragment caching for some stuff, and I honestly don't care about setting up an observer to sweep some stuff. I just want to cache this one slow fragment for like 5 minutes. I've seen these tutorials all over the web that shows people using the expires_in setting to auto-expire cache like [...]]]></description>
			<content:encoded><![CDATA[<p>So, I'm setting up fragment caching for some stuff, and I honestly don't care about setting up an observer to sweep some stuff. I just want to cache this one slow fragment for like 5 minutes. I've seen these tutorials all over the web that shows people using the expires_in setting to auto-expire cache like so:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">Rails.<span style="color:#9900CC;">cache</span>.<span style="color:#9900CC;">write</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'test_key'</span>, <span style="color:#996600;">'test_value'</span>, <span style="color:#ff3333; font-weight:bold;">:expires_in</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 5.<span style="color:#9900CC;">minutes</span><span style="color:#006600; font-weight:bold;">&#41;</span></pre></td></tr></table></div>

<p>That's great and all, but how the hell do I use it for a Page, Action or Fragment cache? Well you just pass the same :expires_in param and yay it works as long as its a mem_cache_store (although, I did see a hackaroo for file_store)</p>
<p>Even the<a href="http://guides.rubyonrails.org/caching_with_rails.html"> Rails Guide</a> on caching mentions 'expires_in' but doesn't show how to use it.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> StupidController <span style="color:#006600; font-weight:bold;">&lt;</span> ApplicationController
  caches_page <span style="color:#ff3333; font-weight:bold;">:whatever</span>, <span style="color:#ff3333; font-weight:bold;">:expires_in</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 5.<span style="color:#9900CC;">minutes</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>What really got me was when I was trying to use it with a fragment cache. I tried this and it didn't work:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">-</span> cache<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:action</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'home'</span>, <span style="color:#ff3333; font-weight:bold;">:action_suffix</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'advertisements'</span>, <span style="color:#ff3333; font-weight:bold;">:expires_in</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 10.<span style="color:#9900CC;">minutes</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span></pre></td></tr></table></div>

<p>Why? Well, the cache method takes two hashes, and if you leave off the curly braces, that expires_in ends up in the first one, which is used for the name... To roll it right do:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">-</span> cache<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#123;</span>:action <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'home'</span>, <span style="color:#ff3333; font-weight:bold;">:action_suffix</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'advertisements'</span><span style="color:#006600; font-weight:bold;">&#125;</span>, <span style="color:#ff3333; font-weight:bold;">:expires_in</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> 10.<span style="color:#9900CC;">minutes</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span></pre></td></tr></table></div>

<p>Duh, the more you know.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Expiring+rails+fragement+caches+using+an+expires+time+instead+of+a+sweeper+%28expires_in%29+%E2%80%93+%28a+%E2%80%98duh%E2%80%99+post%29+http://bit.ly/bhC1Vi" title="Post to Twitter"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://digg.com/submit?url=http://coryodaniel.com/index.php/2010/02/10/expiring-rails-fragement-caches-using-an-expires-time-instead-of-a-sweeper-expires_in-a-duh-post/&amp;title=Expiring+rails+fragement+caches+using+an+expires+time+instead+of+a+sweeper+%28expires_in%29+%E2%80%93+%28a+%E2%80%98duh%E2%80%99+post%29" title="Post to Digg"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-digg-big2.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://coryodaniel.com/index.php/2010/02/10/expiring-rails-fragement-caches-using-an-expires-time-instead-of-a-sweeper-expires_in-a-duh-post/&amp;t=Expiring+rails+fragement+caches+using+an+expires+time+instead+of+a+sweeper+%28expires_in%29+%E2%80%93+%28a+%E2%80%98duh%E2%80%99+post%29" title="Post to Facebook"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-facebook-big2.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://coryodaniel.com/index.php/2010/02/10/expiring-rails-fragement-caches-using-an-expires-time-instead-of-a-sweeper-expires_in-a-duh-post/&amp;title=Expiring+rails+fragement+caches+using+an+expires+time+instead+of+a+sweeper+%28expires_in%29+%E2%80%93+%28a+%E2%80%98duh%E2%80%99+post%29" title="Post to Reddit"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-reddit-big2.png" alt="Post to Reddit" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://coryodaniel.com/index.php/2010/02/10/expiring-rails-fragement-caches-using-an-expires-time-instead-of-a-sweeper-expires_in-a-duh-post/&amp;title=Expiring+rails+fragement+caches+using+an+expires+time+instead+of+a+sweeper+%28expires_in%29+%E2%80%93+%28a+%E2%80%98duh%E2%80%99+post%29" title="Post to StumbleUpon"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-su-big2.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://coryodaniel.com/index.php/2010/02/10/expiring-rails-fragement-caches-using-an-expires-time-instead-of-a-sweeper-expires_in-a-duh-post/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Rails rake file for compressing your Javascript with YUI</title>
		<link>http://coryodaniel.com/index.php/2010/02/10/a-rails-rake-file-for-compressing-your-javascript-with-yui/</link>
		<comments>http://coryodaniel.com/index.php/2010/02/10/a-rails-rake-file-for-compressing-your-javascript-with-yui/#comments</comments>
		<pubDate>Wed, 10 Feb 2010 18:35:29 +0000</pubDate>
		<dc:creator>Cory O'Daniel</dc:creator>
				<category><![CDATA[RubyDevelopment]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[rake]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://coryodaniel.com/?p=462</guid>
		<description><![CDATA[Here is a quick rake file I threw together to use with my Ruby YUI 2.0 (I-refuse-to-make-a-gem-
edition).
This of course should be used with the Ruby YUI Compressor I posted about the other day.
This script will tar/gzip all of your javascripts just incase something stupid happens. So you have a little safety net.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
require 'fileutils'
require 'pathname'
&#160;
namespace :js [...]]]></description>
			<content:encoded><![CDATA[<p>Here is a quick rake file I threw together to use with my Ruby YUI 2.0 (I-refuse-to-make-a-gem-<br />
edition).</p>
<p>This of course should be used with the <a href="http://coryodaniel.com/index.php/2010/02/08/ruby-yui-compressor-by-cory-v-2-0-simpler-shorter/">Ruby YUI Compressor</a> I posted about the other day.</p>
<p>This script will tar/gzip all of your javascripts just incase something stupid happens. So you have a little safety net.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'fileutils'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'pathname'</span>
&nbsp;
namespace <span style="color:#ff3333; font-weight:bold;">:js</span> <span style="color:#9966CC; font-weight:bold;">do</span>
  desc <span style="color:#006600; font-weight:bold;">&lt;&lt;-</span>INFO
Output Compressed JavaScript to STDOUT; 
  COMPRESS=ALL to compress all Javascript files that DONT contain <span style="color:#996600;">&quot;.min.&quot;</span> 
INFO
&nbsp;
  task <span style="color:#ff3333; font-weight:bold;">:yui</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    targz<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">if</span> ENV<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">'COMPRESS'</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#996600;">'ALL'</span>
      <span style="color:#CC00FF; font-weight:bold;">Dir</span><span style="color:#006600; font-weight:bold;">&#91;</span>Rails.<span style="color:#9900CC;">root</span>.<span style="color:#9900CC;">to_s</span> <span style="color:#006600; font-weight:bold;">/</span> <span style="color:#ff3333; font-weight:bold;">:public</span> <span style="color:#006600; font-weight:bold;">/</span> <span style="color:#ff3333; font-weight:bold;">:javascripts</span> <span style="color:#006600; font-weight:bold;">/</span> <span style="color:#996600;">'**/*.js'</span><span style="color:#006600; font-weight:bold;">&#93;</span>.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>javascript<span style="color:#006600; font-weight:bold;">|</span>
        <span style="color:#9966CC; font-weight:bold;">next</span> <span style="color:#9966CC; font-weight:bold;">if</span> javascript =~ <span style="color:#006600; font-weight:bold;">/</span>\.<span style="color:#9900CC;">min</span>\.<span style="color:#006600; font-weight:bold;">/</span>
&nbsp;
        compress<span style="color:#006600; font-weight:bold;">&#40;</span>javascript<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">else</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">exist</span>?<span style="color:#006600; font-weight:bold;">&#40;</span>Rails.<span style="color:#9900CC;">root</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;config/yui.yml&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        javascripts = <span style="color:#CC00FF; font-weight:bold;">YAML</span>.<span style="color:#CC0066; font-weight:bold;">load</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;config/yui.yml&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">read</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;javascripts&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
        <span style="color:#9966CC; font-weight:bold;">if</span> !javascripts.<span style="color:#9900CC;">blank</span>?
          javascripts.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>script<span style="color:#006600; font-weight:bold;">|</span> compress<span style="color:#006600; font-weight:bold;">&#40;</span>Rails.<span style="color:#9900CC;">root</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;public/javascripts&quot;</span> <span style="color:#006600; font-weight:bold;">+</span> script<span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#125;</span>
        <span style="color:#9966CC; font-weight:bold;">else</span>
          <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#CC00FF; font-weight:bold;">Exception</span>, <span style="color:#996600;">&quot;No javascript files in config/yui.yml&quot;</span> 
        <span style="color:#9966CC; font-weight:bold;">end</span>
      <span style="color:#9966CC; font-weight:bold;">else</span>
        <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#CC00FF; font-weight:bold;">Exception</span>, <span style="color:#996600;">&quot;config/yui.yml Not Found; Do rake js:generate to create one or COMPRESS=ALL to run without a config file&quot;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  desc <span style="color:#996600;">&quot;Generate YUI Compressor Config file&quot;</span>
  task <span style="color:#ff3333; font-weight:bold;">:generate</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:environment</span> <span style="color:#9966CC; font-weight:bold;">do</span>
    config_path = Rails.<span style="color:#9900CC;">root</span> <span style="color:#006600; font-weight:bold;">+</span> <span style="color:#996600;">&quot;config/yui.yml&quot;</span>
    <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>config_path, <span style="color:#996600;">&quot;w+&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>f<span style="color:#006600; font-weight:bold;">|</span>
      f.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;-</span>CONFIG
<span style="color:#006600; font-weight:bold;">---</span>
javascripts:
  <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#996600;">&quot;application.js&quot;</span>
  <span style="color:#006600; font-weight:bold;">-</span> <span style="color:#996600;">&quot;jquery.js&quot;</span>
CONFIG
      <span style="color:#CC0066; font-weight:bold;">puts</span> config_path
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> targz<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
    tgz_file = <span style="color:#996600;">&quot;#{Time.now.to_i}.javascripts.tgz&quot;</span>
    <span style="color:#996600;">`cd #{Rails.root + &quot;public&quot;}; tar -zcf #{tgz_file} javascripts/`</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Backed up assets to: #{tgz_file}&quot;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> compress<span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Compressing #{path}&quot;</span>
    file_handle = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>path<span style="color:#006600; font-weight:bold;">&#41;</span>
    compressed_output = YUI.<span style="color:#9900CC;">compress_safe</span> file_handle
    file_handle.<span style="color:#9900CC;">close</span>
&nbsp;
    <span style="color:#008000; font-style:italic;">#overwrite the file</span>
    <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span>path, <span style="color:#996600;">&quot;w+&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#006600; font-weight:bold;">|</span>file<span style="color:#006600; font-weight:bold;">|</span> file.<span style="color:#CC0066; font-weight:bold;">puts</span> compressed_output <span style="color:#006600; font-weight:bold;">&#125;</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Wanna use it?<br />
1. Drop it in your lib/tasks folder or wherever your Rakefile looks</p>
<p>You can compress 'everything' or specific files. </p>
<p>If you want to only compress specific Javascript files do:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">rake js:generate 
<span style="color: #666666; font-style: italic;"># Edit your config/yui.yml file</span>
rake js:yui</pre></td></tr></table></div>

<p>If you want to compress "everything" (It actually won't compress files that contain ".min.". You can remove the regexp's if you don't like it.)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;">rake js:yui <span style="color: #007800;">COMPRESS</span>=ALL</pre></td></tr></table></div>

<p>Yay, now your raking it in (Pun harhar) w/ your web2.0 yui compressed rails app. Woot woot.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=A+Rails+rake+file+for+compressing+your+Javascript+with+YUI+http://bit.ly/c5ZCBM" title="Post to Twitter"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://digg.com/submit?url=http://coryodaniel.com/index.php/2010/02/10/a-rails-rake-file-for-compressing-your-javascript-with-yui/&amp;title=A+Rails+rake+file+for+compressing+your+Javascript+with+YUI" title="Post to Digg"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-digg-big2.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://coryodaniel.com/index.php/2010/02/10/a-rails-rake-file-for-compressing-your-javascript-with-yui/&amp;t=A+Rails+rake+file+for+compressing+your+Javascript+with+YUI" title="Post to Facebook"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-facebook-big2.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://coryodaniel.com/index.php/2010/02/10/a-rails-rake-file-for-compressing-your-javascript-with-yui/&amp;title=A+Rails+rake+file+for+compressing+your+Javascript+with+YUI" title="Post to Reddit"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-reddit-big2.png" alt="Post to Reddit" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://coryodaniel.com/index.php/2010/02/10/a-rails-rake-file-for-compressing-your-javascript-with-yui/&amp;title=A+Rails+rake+file+for+compressing+your+Javascript+with+YUI" title="Post to StumbleUpon"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-su-big2.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://coryodaniel.com/index.php/2010/02/10/a-rails-rake-file-for-compressing-your-javascript-with-yui/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stick this in your bash</title>
		<link>http://coryodaniel.com/index.php/2010/02/08/stick-this-in-your-bash/</link>
		<comments>http://coryodaniel.com/index.php/2010/02/08/stick-this-in-your-bash/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 04:23:50 +0000</pubDate>
		<dc:creator>Cory O'Daniel</dc:creator>
				<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[prompt]]></category>

		<guid isPermaLink="false">http://coryodaniel.com/?p=449</guid>
		<description><![CDATA[This isn't a tutorial or anything. Its merely just me dropping all my bash scripts/prompt stuff here so maybe I'll get some comments/tips on cool stuff to add, and so that I can always rip it if I'm on a remote computer.
My pride and joy is that bash prompt. So much info. Its a pretty [...]]]></description>
			<content:encoded><![CDATA[<p>This isn't a tutorial or anything. Its merely just me dropping all my bash scripts/prompt stuff here so maybe I'll get some comments/tips on cool stuff to add, and so that I can always rip it if I'm on a remote computer.</p>
<p>My pride and joy is that bash prompt. So much info. Its a pretty cool bash prompt if I do say so myself (toot toot) <img src='http://coryodaniel.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /><br />
Username@Host<br />
List of IP Addresses<br />
Number of files in the directory<br />
Current Path<br />
History Command Number<br />
Git Branch (if a git repo)<br />
<a href="http://coryodaniel.com/wp-content/uploads/2010/02/bashprompt.jpg"><img src="http://coryodaniel.com/wp-content/uploads/2010/02/bashprompt.jpg" alt="Nerd-ass prompt" title="bashprompt" width="581" height="497" class="aligncenter size-full wp-image-452" /></a></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># ~/.bash_login</span>
<span style="color: #666666; font-style: italic;"># Shell Options</span>
<span style="color: #7a0874; font-weight: bold;">shopt</span> <span style="color: #660033;">-s</span> checkwinsize
<span style="color: #7a0874; font-weight: bold;">shopt</span> <span style="color: #660033;">-s</span> cdspell
&nbsp;
<span style="color: #666666; font-style: italic;"># Exports</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">EDITOR</span>=<span style="color: #ff0000;">&quot;mate -w&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">VISUAL</span>=<span style="color: #ff0000;">&quot;mate -w&quot;</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTFILESIZE</span>=<span style="color: #000000;">3000</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTCONTROL</span>=ignoredups
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">DISPLAY</span>=:<span style="color: #000000;">0.0</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">GEM_PATH</span>=<span style="color: #ff0000;">&quot;/Library/Ruby/Gems/1.8/gems&quot;</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">PATH</span>=~<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>sbin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>mysql<span style="color: #000000; font-weight: bold;">/</span>bin:~<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #000000; font-weight: bold;">/</span>Applications<span style="color: #000000; font-weight: bold;">/</span>flex_sdk_3<span style="color: #000000; font-weight: bold;">/</span>bin:<span style="color: #007800;">$PATH</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># include functions, aliases &amp; bashrc</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> ~<span style="color: #000000; font-weight: bold;">/</span>.functions <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  . ~<span style="color: #000000; font-weight: bold;">/</span>.functions;
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> ~<span style="color: #000000; font-weight: bold;">/</span>.aliases <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  . ~<span style="color: #000000; font-weight: bold;">/</span>.aliases;
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bashrc <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  . ~<span style="color: #000000; font-weight: bold;">/</span>.bashrc;
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bash_prompt <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  . ~<span style="color: #000000; font-weight: bold;">/</span>.bash_prompt;
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-f</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>bash_completion <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  .  <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>bash_completion
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #7a0874; font-weight: bold;">complete</span> <span style="color: #660033;">-C</span> ~<span style="color: #000000; font-weight: bold;">/</span>.bash_completion.d<span style="color: #000000; font-weight: bold;">/</span>rake <span style="color: #660033;">-o</span> default rake
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">date</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-x</span> <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>fortune <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
  <span style="color: #000000; font-weight: bold;">/</span>opt<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>fortune <span style="color: #660033;">-s</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># ~/.bash_prompt</span>
<span style="color: #666666; font-style: italic;"># Define a few Color's</span>
<span style="color: #007800;">BLACK</span>=<span style="color: #ff0000;">'\[\e[0;30m\]'</span>
<span style="color: #007800;">BLUE</span>=<span style="color: #ff0000;">'\[\e[0;34m\]'</span>
<span style="color: #007800;">GREEN</span>=<span style="color: #ff0000;">'\[\e[0;32m\]'</span>
<span style="color: #007800;">CYAN</span>=<span style="color: #ff0000;">'\[\e[0;36m\]'</span>
<span style="color: #007800;">RED</span>=<span style="color: #ff0000;">'\[\e[0;31m\]'</span>
<span style="color: #007800;">PURPLE</span>=<span style="color: #ff0000;">'\[\e[0;35m\]'</span>
<span style="color: #007800;">BROWN</span>=<span style="color: #ff0000;">'\[\e[0;33m\]'</span>
<span style="color: #007800;">LIGHTGRAY</span>=<span style="color: #ff0000;">'\[\e[0;37m\]'</span>
<span style="color: #007800;">DARKGRAY</span>=<span style="color: #ff0000;">'\[\e[1;30m\]'</span>
<span style="color: #007800;">LIGHTBLUE</span>=<span style="color: #ff0000;">'\[\e[1;34m\]'</span>
<span style="color: #007800;">LIGHTGREEN</span>=<span style="color: #ff0000;">'\[\e[1;32m\]'</span>
<span style="color: #007800;">LIGHTCYAN</span>=<span style="color: #ff0000;">'\[\e[1;36m\]'</span>
<span style="color: #007800;">LIGHTRED</span>=<span style="color: #ff0000;">'\[\e[1;31m\]'</span>
<span style="color: #007800;">LIGHTPURPLE</span>=<span style="color: #ff0000;">'\[\e[1;35m\]'</span>
<span style="color: #007800;">YELLOW</span>=<span style="color: #ff0000;">'\[\e[1;33m\]'</span>
<span style="color: #007800;">WHITE</span>=<span style="color: #ff0000;">'\[\e[0;37m\]'</span>
<span style="color: #007800;">NC</span>=<span style="color: #ff0000;">'\[\e[0m\]'</span>              <span style="color: #666666; font-style: italic;"># No Color</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">function</span> drpmpt <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #007800;">first_prompt_line</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$WHITE</span>(<span style="color: #007800;">$CYAN</span>\u@\h<span style="color: #007800;">$WHITE</span>)-(<span style="color: #007800;">$CYAN</span><span style="color: #007800;">$(ip)</span><span style="color: #007800;">$WHITE</span>)-&gt;&quot;</span>
  <span style="color: #007800;">second_prompt_line</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$WHITE</span>(<span style="color: #007800;">$CYAN</span><span style="color: #007800;">$(ls -1|wc -l|tr -d &quot;[:blank:]&quot;)</span> files<span style="color: #007800;">$WHITE</span>)-(<span style="color: #007800;">$CYAN</span>\w<span style="color: #007800;">$WHITE</span>)-&gt;&quot;</span>
  <span style="color: #007800;">third_prompt_line</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$WHITE</span>(<span style="color: #007800;">$GREEN</span>!\!<span style="color: #007800;">$WHITE</span>)<span style="color: #007800;">$GREEN</span><span style="color: #007800;">$(parse_git_branch)</span><span style="color: #007800;">$WHITE</span>&quot;</span>
  <span style="color: #007800;">working_prompt</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$first_prompt_line</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #007800;">$second_prompt_line</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #007800;">$third_prompt_line</span>&gt; <span style="color: #007800;">$NC</span>&quot;</span>
&nbsp;
  <span style="color: #007800;">PS1</span>=<span style="color: #007800;">$working_prompt</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #007800;">PROMPT_COMMAND</span>=drpmpt</pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># ~/.aliases</span>
<span style="color: #666666; font-style: italic;"># TO BYPASS AN ALIAS DO THE ORIGINAL COMMAND W \, ie \ls</span>
<span style="color: #666666; font-style: italic;"># Aliases</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">pastie</span>=<span style="color: #ff0000;">'sake pastie:clip'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> ..=<span style="color: #ff0000;">'cd ..'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">igem</span>=<span style="color: #ff0000;">'sudo gem install --no-rdoc --no-ri'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">c</span>=<span style="color: #ff0000;">'clear'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">dsrm</span>=<span style="color: #ff0000;">&quot;find . -type f -name .DS_Store -print0 | xargs -0 rm&quot;</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">gcpp</span>=<span style="color: #ff0000;">'dsrm; git commit .; git pull; git push'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">sha1sum</span>=<span style="color: #ff0000;">'openssl sha1'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">lgem</span>=<span style="color: #ff0000;">'gem install --no-rdoc --no-ri -i ./gems --ignore-dependencies'</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">start_wowza</span>=<span style="color: #ff0000;">'/Library/WowzaMediaServerPro/bin/startup.sh'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">stop_wowza</span>=<span style="color: #ff0000;">'/Library/WowzaMediaServerPro/bin/shutdown.sh'</span>
&nbsp;
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">hist</span>=<span style="color: #ff0000;">'history | grep $1'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;"><span style="color: #c20cb9; font-weight: bold;">ps</span></span>=<span style="color: #ff0000;">'ps aux'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">home</span>=<span style="color: #ff0000;">'cd ~'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">utgz</span>=<span style="color: #ff0000;">'tar -zxvf'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">tgz</span>=<span style="color: #ff0000;">'tar -zcvf'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">mnts</span>=<span style="color: #ff0000;">'df -h'</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Alias to multiple ls commands</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">la</span>=<span style="color: #ff0000;">'ls -Al'</span>               <span style="color: #666666; font-style: italic;"># show hidden files</span>
<span style="color: #666666; font-style: italic;">#alias ls='ls -aF ' # add colors and file type extensions</span>
<span style="color: #666666; font-style: italic;">#alias lx='ls -lXB'              # sort by extension</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">lk</span>=<span style="color: #ff0000;">'ls -lSr'</span>              <span style="color: #666666; font-style: italic;"># sort by size</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">lc</span>=<span style="color: #ff0000;">'ls -lcr'</span>          <span style="color: #666666; font-style: italic;"># sort by change time</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">lu</span>=<span style="color: #ff0000;">'ls -lur'</span>          <span style="color: #666666; font-style: italic;"># sort by access time</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">lr</span>=<span style="color: #ff0000;">'ls -lR'</span>               <span style="color: #666666; font-style: italic;"># recursive ls</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">lt</span>=<span style="color: #ff0000;">'ls -ltr'</span>              <span style="color: #666666; font-style: italic;"># sort by date</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">lm</span>=<span style="color: #ff0000;">'ls -al |more'</span>         <span style="color: #666666; font-style: italic;"># pipe through 'more'</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Alias chmod commands</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #007800;">mx</span>=<span style="color: #ff0000;">'chmod a+x'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> 000=<span style="color: #ff0000;">'chmod 000'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #000000;">644</span>=<span style="color: #ff0000;">'chmod 644'</span>
<span style="color: #7a0874; font-weight: bold;">alias</span> <span style="color: #000000;">755</span>=<span style="color: #ff0000;">'chmod 755'</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># ~/.functions</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Parse git branch</span>
parse_git_branch<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #7a0874; font-weight: bold;">&#123;</span>
  git branch <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'/^[^*]/d'</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'s/* \(.*\)/ [\1]/'</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Get assigned ip address</span>
ip<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
<span style="color: #007800;">OS</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">uname</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">case</span> <span style="color: #007800;">$OS</span> <span style="color: #000000; font-weight: bold;">in</span>
   Linux<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">IP</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ifconfig</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #ff0000;">'inet addr:'</span><span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">'127.0.0.1'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> -d: <span style="color: #660033;">-f2</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: #000000; font-weight: bold;">`;;</span>
   FreeBSD<span style="color: #000000; font-weight: bold;">|</span>OpenBSD<span style="color: #000000; font-weight: bold;">|</span>Darwin<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">IP</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ifconfig</span>  <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-E</span> <span style="color: #ff0000;">'inet.[0-9]'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">'127.0.0.1'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $2}'</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">;;</span>
   SunOS<span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">IP</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ifconfig</span> <span style="color: #660033;">-a</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> inet <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #ff0000;">'127.0.0.1'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $2} '</span><span style="color: #000000; font-weight: bold;">`</span> <span style="color: #000000; font-weight: bold;">;;</span>
   <span style="color: #000000; font-weight: bold;">*</span><span style="color: #7a0874; font-weight: bold;">&#41;</span> <span style="color: #007800;">IP</span>=<span style="color: #ff0000;">&quot;Unknown&quot;</span><span style="color: #000000; font-weight: bold;">;;</span>
<span style="color: #000000; font-weight: bold;">esac</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># Remove new lines and trailing whitespace.</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$IP</span>&quot;</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ printf &quot;%s | &quot;, $0 }'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ sub(/(\ \|\ )$/, &quot;&quot;); print}'</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">#Determine if an app is running</span>
list<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #c20cb9; font-weight: bold;">ps</span> aux <span style="color: #660033;">-m</span> <span style="color: #660033;">-r</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> $<span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span>
&nbsp;
&nbsp;
git_prompt_ip<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span><span style="color: #7a0874; font-weight: bold;">&#123;</span>
  <span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">GIT_PROMPT_IP</span>=$<span style="color: #000000;">1</span>
<span style="color: #7a0874; font-weight: bold;">&#125;</span></pre></td></tr></table></div>

<p align="left"><a class="tt" href="http://twitter.com/home/?status=Stick+this+in+your+bash+http://bit.ly/bRj5LR" title="Post to Twitter"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://digg.com/submit?url=http://coryodaniel.com/index.php/2010/02/08/stick-this-in-your-bash/&amp;title=Stick+this+in+your+bash" title="Post to Digg"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-digg-big2.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://coryodaniel.com/index.php/2010/02/08/stick-this-in-your-bash/&amp;t=Stick+this+in+your+bash" title="Post to Facebook"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-facebook-big2.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://coryodaniel.com/index.php/2010/02/08/stick-this-in-your-bash/&amp;title=Stick+this+in+your+bash" title="Post to Reddit"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-reddit-big2.png" alt="Post to Reddit" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://coryodaniel.com/index.php/2010/02/08/stick-this-in-your-bash/&amp;title=Stick+this+in+your+bash" title="Post to StumbleUpon"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-su-big2.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://coryodaniel.com/index.php/2010/02/08/stick-this-in-your-bash/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Cory&#8217;s Ruby YUI Compressor v 2.0 Simpler, shorter.</title>
		<link>http://coryodaniel.com/index.php/2010/02/08/ruby-yui-compressor-by-cory-v-2-0-simpler-shorter/</link>
		<comments>http://coryodaniel.com/index.php/2010/02/08/ruby-yui-compressor-by-cory-v-2-0-simpler-shorter/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 02:43:23 +0000</pubDate>
		<dc:creator>Cory O'Daniel</dc:creator>
				<category><![CDATA[RubyDevelopment]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[yui]]></category>

		<guid isPermaLink="false">http://coryodaniel.com/?p=445</guid>
		<description><![CDATA[So, a while ago I write a Ruby YUI Compressor Wrapper which is still available and works great (although it could use a newer jar file) as far as I know from Mandula's Blog. Some other guy also wrote one that pretty much had the same functionality as my gem. He must have hated it [...]]]></description>
			<content:encoded><![CDATA[<p>So, a while ago I write a <a href="http://github.com/coryodaniel/ruby-yui">Ruby YUI Compressor Wrapper</a> which is still available and works great (although it could use a newer jar file) as far as I know from <a href="http://blog.mandula.co.uk/js-and-css-optimisation-with-ruby-yui-and-mer">Mandula's Blog.</a> Some <a href="http://github.com/sstephenson/ruby-yui-compressor">other guy</a> also wrote one that pretty much had the same functionality as my gem. He must have hated it or something, I dunno. <a href="http://github.com/documentcloud/closure-compiler"> Even another guy</a> wrote a wrapper for Closure Compiler if thats your bag.</p>
<p>Anywho, on a new project I'm working on *I just need a inline YUI compressor* and I dont give a damn about anything else like bundling, globbing or whatever. So I ended up throwing together this little (~50 lines less comments) Ruby YUI Compressor to do my dirty work. </p>
<p>I won't make it a gem probably, because if I do someone will just make a ruby-yui-simpler-also gem and put it on digg and get a bigger following <img src='http://coryodaniel.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' />  (&lt;/sarcasm&gt;)</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'open3'</span>
<span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'stringio'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> YUI
  <span style="color:#9966CC; font-weight:bold;">include</span> Open3 
  JAR_PATH = <span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#9900CC;">dirname</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">__FILE__</span><span style="color:#006600; font-weight:bold;">&#41;</span>,<span style="color:#996600;">'yuicompressor-2.4.2.jar'</span><span style="color:#006600; font-weight:bold;">&#41;</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#0000FF; font-weight:bold;">self</span>
    <span style="color:#008000; font-style:italic;"># @param io [String|File]</span>
    <span style="color:#008000; font-style:italic;"># @param options [Hash] - See YUI.cli</span>
    <span style="color:#008000; font-style:italic;"># @returns String</span>
    <span style="color:#008000; font-style:italic;">#</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> compress<span style="color:#006600; font-weight:bold;">&#40;</span>io, options = <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:type</span><span style="color:#006600; font-weight:bold;">&#93;</span>    <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#ff3333; font-weight:bold;">:js</span>
      options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:charset</span><span style="color:#006600; font-weight:bold;">&#93;</span> <span style="color:#006600; font-weight:bold;">||</span>= <span style="color:#996600;">&quot;utf-8&quot;</span>
&nbsp;
      stdin, stdout, stderr = Open3.<span style="color:#9900CC;">popen3</span><span style="color:#006600; font-weight:bold;">&#40;</span> YUI.<span style="color:#9900CC;">cli</span><span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#41;</span>
      stdin.<span style="color:#CC0066; font-weight:bold;">puts</span> streamify<span style="color:#006600; font-weight:bold;">&#40;</span>io<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">read</span>
      stdin.<span style="color:#9900CC;">close</span>
&nbsp;
      my_stderr = stderr.<span style="color:#9900CC;">read</span>
      my_stdout = stdout.<span style="color:#9900CC;">read</span>
&nbsp;
      <span style="color:#008000; font-style:italic;"># if compression failed, just output original IO</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> my_stderr.<span style="color:#9900CC;">empty</span>?
        <span style="color:#0000FF; font-weight:bold;">return</span> my_stdout
      <span style="color:#9966CC; font-weight:bold;">else</span>
        <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#CC00FF; font-weight:bold;">Exception</span>, my_stderr
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># If any exceptions are raised, the original string will be</span>
    <span style="color:#008000; font-style:italic;">#   returned incase you are compressing stuff during a deploy</span>
    <span style="color:#008000; font-style:italic;">#   and _just_dont_care_</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> compress_safe<span style="color:#006600; font-weight:bold;">&#40;</span>io, options=<span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      YUI.<span style="color:#9900CC;">compress</span><span style="color:#006600; font-weight:bold;">&#40;</span>io, options<span style="color:#006600; font-weight:bold;">&#41;</span>
    <span style="color:#9966CC; font-weight:bold;">rescue</span> <span style="color:#CC00FF; font-weight:bold;">Exception</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> ex
      <span style="color:#CC0066; font-weight:bold;">puts</span> ex.<span style="color:#9900CC;">message</span>
      <span style="color:#0000FF; font-weight:bold;">return</span> streamify<span style="color:#006600; font-weight:bold;">&#40;</span>io<span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">read</span>      
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># Sets up the command line options</span>
    <span style="color:#008000; font-style:italic;"># @param options [Hash]</span>
    <span style="color:#008000; font-style:italic;">#   :jar_path         - [String] Path to the jar file, default &quot;./yuicompress-2.4.2.jar&quot;</span>
    <span style="color:#008000; font-style:italic;">#   :charset          - [String] default 'utf-8'</span>
    <span style="color:#008000; font-style:italic;">#   :type             - [Symbol] Options: js/css, default :js</span>
    <span style="color:#008000; font-style:italic;">#   :line_break       - [Fixnum] Column to add line break at</span>
    <span style="color:#008000; font-style:italic;">#   </span>
    <span style="color:#008000; font-style:italic;">#   if the type of compression is JS, then additional options:</span>
    <span style="color:#008000; font-style:italic;">#     :nomunge        - [Boolean] do not obfuscate</span>
    <span style="color:#008000; font-style:italic;">#     :preserve_semi  - [Boolean] preserve all semicolons</span>
    <span style="color:#008000; font-style:italic;">#     :disable_opt    - [Boolean] Disable all micro optimizations</span>
    <span style="color:#008000; font-style:italic;"># </span>
    <span style="color:#008000; font-style:italic;"># @returns String</span>
    <span style="color:#008000; font-style:italic;">#</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> cli<span style="color:#006600; font-weight:bold;">&#40;</span>options<span style="color:#006600; font-weight:bold;">&#41;</span>
      _cmd = <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;java -jar #{options[:jar_path] || JAR_PATH}&quot;</span><span style="color:#006600; font-weight:bold;">&#93;</span>
      _cmd <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;--type #{options[:type]}&quot;</span>
      _cmd <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;--charset #{options[:charset]}&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:charset</span><span style="color:#006600; font-weight:bold;">&#93;</span>
      _cmd <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;--charset #{options[:line_break]}&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:line_break</span><span style="color:#006600; font-weight:bold;">&#93;</span>
&nbsp;
      <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:type</span><span style="color:#006600; font-weight:bold;">&#93;</span> == <span style="color:#ff3333; font-weight:bold;">:js</span>  
        _cmd <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;--nomunge&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:nomunge</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        _cmd <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;--preserve-semi&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:preserve_semi</span><span style="color:#006600; font-weight:bold;">&#93;</span>
        _cmd <span style="color:#006600; font-weight:bold;">&lt;&lt;</span> <span style="color:#996600;">&quot;--disable-optimizations&quot;</span> <span style="color:#9966CC; font-weight:bold;">if</span> options<span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#ff3333; font-weight:bold;">:disable_opt</span><span style="color:#006600; font-weight:bold;">&#93;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
      _cmd.<span style="color:#9900CC;">join</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">' '</span><span style="color:#006600; font-weight:bold;">&#41;</span> 
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    <span style="color:#008000; font-style:italic;"># If a file or a string, treat it like its a stream</span>
    <span style="color:#008000; font-style:italic;">#</span>
    <span style="color:#008000; font-style:italic;"># @param string_or_stream [File|String]</span>
    <span style="color:#008000; font-style:italic;"># @return StringIO</span>
    <span style="color:#008000; font-style:italic;">#</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> streamify<span style="color:#006600; font-weight:bold;">&#40;</span>string_or_stream<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">if</span> string_or_stream.<span style="color:#9900CC;">respond_to</span>?<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:read</span><span style="color:#006600; font-weight:bold;">&#41;</span>
        string_or_stream.<span style="color:#9900CC;">rewind</span> <span style="color:#9966CC; font-weight:bold;">if</span> string_or_stream.<span style="color:#9900CC;">eof</span>?
        string_or_stream
      <span style="color:#9966CC; font-weight:bold;">else</span>
        <span style="color:#CC00FF; font-weight:bold;">StringIO</span>.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span>string_or_stream<span style="color:#006600; font-weight:bold;">&#41;</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">end</span> <span style="color:#008000; font-style:italic;">#end class &lt;&lt; self</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<p>Wanna use it?<br />
1. Copy the code above, throw it in your lib folder or where ever<br />
2. Download the <a href="http://yuilibrary.com/downloads/yuicompressor/yuicompressor-2.4.2.zip">YUI compressor</a> JAR file and put it in the same directory.<br />
3. Do something like the following...</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;">YUI.<span style="color:#9900CC;">compress</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;function weebleep(){var cool_variable= 3; return cool_variable;}&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;">#=&gt; &quot;function weebleep(){var a=3;return a};&quot;</span>
YUI.<span style="color:#9900CC;">compress</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">&quot;public/javascripts/application.js&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;">#=&gt; A bunch of compressed javascript</span>
YUI.<span style="color:#9900CC;">compress</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#CC00FF; font-weight:bold;">File</span>.<span style="color:#CC0066; font-weight:bold;">open</span><span style="color:#006600; font-weight:bold;">&#40;</span> <span style="color:#996600;">&quot;public/stylesheets/application.css&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>, <span style="color:#006600; font-weight:bold;">&#123;</span>:type <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:css</span><span style="color:#006600; font-weight:bold;">&#125;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#008000; font-style:italic;">#=&gt; Compressed stylesheet</span></pre></td></tr></table></div>

<p>Other options include:<br />
:jar_path         - [String] Path to the jar file, default "./yuicompress-2.4.2.jar"<br />
:charset          - [String] default 'utf-8'<br />
:type             - [Symbol] Options: js/css, default :js<br />
:line_break       - [Fixnum] Column to add line break at</p>
<p>if the type of compression is JS, then additional options:<br />
:nomunge        - [Boolean] do not obfuscate<br />
:preserve_semi  - [Boolean] preserve all semicolons<br />
:disable_opt    - [Boolean] Disable all micro optimizations</p>
<p>Yay have a blast. Its another compression wrapper.</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=Cory%E2%80%99s+Ruby+YUI+Compressor+v+2.0+Simpler%2C+shorter.+http://bit.ly/crye6c" title="Post to Twitter"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://digg.com/submit?url=http://coryodaniel.com/index.php/2010/02/08/ruby-yui-compressor-by-cory-v-2-0-simpler-shorter/&amp;title=Cory%E2%80%99s+Ruby+YUI+Compressor+v+2.0+Simpler%2C+shorter." title="Post to Digg"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-digg-big2.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://coryodaniel.com/index.php/2010/02/08/ruby-yui-compressor-by-cory-v-2-0-simpler-shorter/&amp;t=Cory%E2%80%99s+Ruby+YUI+Compressor+v+2.0+Simpler%2C+shorter." title="Post to Facebook"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-facebook-big2.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://coryodaniel.com/index.php/2010/02/08/ruby-yui-compressor-by-cory-v-2-0-simpler-shorter/&amp;title=Cory%E2%80%99s+Ruby+YUI+Compressor+v+2.0+Simpler%2C+shorter." title="Post to Reddit"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-reddit-big2.png" alt="Post to Reddit" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://coryodaniel.com/index.php/2010/02/08/ruby-yui-compressor-by-cory-v-2-0-simpler-shorter/&amp;title=Cory%E2%80%99s+Ruby+YUI+Compressor+v+2.0+Simpler%2C+shorter." title="Post to StumbleUpon"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-su-big2.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://coryodaniel.com/index.php/2010/02/08/ruby-yui-compressor-by-cory-v-2-0-simpler-shorter/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to close (get rid of) the Google Analytics Site Overlay</title>
		<link>http://coryodaniel.com/index.php/2010/02/04/how-to-close-get-rid-of-the-google-analytics-site-overlay/</link>
		<comments>http://coryodaniel.com/index.php/2010/02/04/how-to-close-get-rid-of-the-google-analytics-site-overlay/#comments</comments>
		<pubDate>Thu, 04 Feb 2010 23:26:22 +0000</pubDate>
		<dc:creator>Cory O'Daniel</dc:creator>
				<category><![CDATA[Random]]></category>
		<category><![CDATA[google analytics]]></category>
		<category><![CDATA[oh duh]]></category>

		<guid isPermaLink="false">http://coryodaniel.com/?p=436</guid>
		<description><![CDATA[So, the google analytics site overlay is pretty cool. It's nice to see where people click. I googled around and some people say to clear the cookies. The funny thing is there is actually a 'close' button, but you can't see it if your page's background is white. Duh, it's in the top right corner. [...]]]></description>
			<content:encoded><![CDATA[<p>So, the google analytics site overlay is pretty cool. It's nice to see where people click. I googled around and some people <a href="http://groups.google.com/group/analytics-help-basics/browse_thread/thread/60d291272825b94e?pli=1">say to clear the cookies</a>. The funny thing is there is actually a 'close' button, but you can't see it if your page's background is white. Duh, it's in the top right corner. Just click close.</p>
<p>Here it is, sneakily hidden.<br />
<div id="attachment_437" class="wp-caption aligncenter" style="width: 410px"><a href="http://coryodaniel.com/wp-content/uploads/2010/02/hidden.png"><img src="http://coryodaniel.com/wp-content/uploads/2010/02/hidden.png" alt="" title="Where the hell is the close button?" width="400" height="300" class="size-full wp-image-437" /></a><p class="wp-caption-text">Where the hell is the close button?</p></div></p>
<p>Here it is with the click-n-drag (TM) revealing tool.<br />
<div id="attachment_438" class="wp-caption aligncenter" style="width: 410px"><a href="http://coryodaniel.com/wp-content/uploads/2010/02/shown.png"><img src="http://coryodaniel.com/wp-content/uploads/2010/02/shown.png" alt="" title="Oh, magic!" width="400" height="300" class="size-full wp-image-438" /></a><p class="wp-caption-text">Oh, magic!</p></div></p>
<p>You may be saying "duh". But with a white background, its a bit tricky to find, and clearing cookies constantly is retarded (technically speaking).</p>
<p align="left"><a class="tt" href="http://twitter.com/home/?status=How+to+close+%28get+rid+of%29+the+Google+Analytics+Site+Overlay+http://bit.ly/azTzmp" title="Post to Twitter"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-twitter-big2.png" alt="Post to Twitter" /></a> <a class="tt" href="http://digg.com/submit?url=http://coryodaniel.com/index.php/2010/02/04/how-to-close-get-rid-of-the-google-analytics-site-overlay/&amp;title=How+to+close+%28get+rid+of%29+the+Google+Analytics+Site+Overlay" title="Post to Digg"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-digg-big2.png" alt="Post to Digg" /></a> <a class="tt" href="http://www.facebook.com/share.php?u=http://coryodaniel.com/index.php/2010/02/04/how-to-close-get-rid-of-the-google-analytics-site-overlay/&amp;t=How+to+close+%28get+rid+of%29+the+Google+Analytics+Site+Overlay" title="Post to Facebook"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-facebook-big2.png" alt="Post to Facebook" /></a> <a class="tt" href="http://reddit.com/submit?url=http://coryodaniel.com/index.php/2010/02/04/how-to-close-get-rid-of-the-google-analytics-site-overlay/&amp;title=How+to+close+%28get+rid+of%29+the+Google+Analytics+Site+Overlay" title="Post to Reddit"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-reddit-big2.png" alt="Post to Reddit" /></a> <a class="tt" href="http://stumbleupon.com/submit?url=http://coryodaniel.com/index.php/2010/02/04/how-to-close-get-rid-of-the-google-analytics-site-overlay/&amp;title=How+to+close+%28get+rid+of%29+the+Google+Analytics+Site+Overlay" title="Post to StumbleUpon"><img class="nothumb" src="http://coryodaniel.com/wp-content/plugins/tweet-this/icons/tt-su-big2.png" alt="Post to StumbleUpon" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://coryodaniel.com/index.php/2010/02/04/how-to-close-get-rid-of-the-google-analytics-site-overlay/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
