<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0"><channel><description>Martin Schürrer’s Blog. My new blog is featurebranch.com</description><title>Casual Thoughts</title><generator>Tumblr (3.0; @casualthoughts)</generator><link>http://blog.schuerrer.org/</link><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/martinschuerrer" /><feedburner:info uri="martinschuerrer" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://tumblr.superfeedr.com/" /><item><title>Solving "bash: grep: command not found" on OS X</title><description>&lt;p&gt;&lt;strong&gt;I’ve moved my blog to a new domain, you can find this post at &lt;a href="http://featurebranch.com/2011/solving-bash-grep-command-not-found-on-os-x/"&gt;featurebranch.com&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;pre&gt;$ some script | grep something
bash: grep: command not found&lt;/pre&gt;
&lt;p&gt;If you are using a Mac with a German (or French, see below) keyboard layout and your typing is as sloppy as mine, chances are you are familiar with this error. You probably also know that deleting the space before &lt;em&gt;grep&lt;/em&gt; fixes it. Why is this?&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Option 7&lt;/em&gt; corresponds to the &lt;em&gt;|&lt;/em&gt; character. &lt;em&gt;Option Space&lt;/em&gt; corresponds to the &lt;em&gt;non breaking space&lt;/em&gt; which looks just like the regular space but is - as far as the shell is concerned - totally different. And obviously there’s no ‘&lt;em&gt;&amp;nbsp;&lt;/em&gt;grep’ command on your system. And if you still hold down Option while pressing space… Guess what will happen… Now how do we fix it?&lt;/p&gt;
&lt;p&gt;Check out the documentation on &lt;a href="http://www.erasetotheleft.com/post/mac-os-x-key-bindings/"&gt;Mac OS X Key Bindings&lt;/a&gt; or simply make your ~/Library/KeyBindings/DefaultKeyBinding.dict file look like this (if it doesn’t exist create it, if there are already bindings in it just add the one from below)&lt;/p&gt;
&lt;pre&gt;{
  "~ " = ("insertText:", " ");
}&lt;/pre&gt;
&lt;p&gt;What does this do? Every time you press &lt;em&gt;Option Space&lt;/em&gt; instead of inserting a non breaking space OS X now inserts a regular space. Problem fixed.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Update:&lt;/strong&gt; Thanks to Julien Palmas for pointing out that this also applies to French keyboad layouts: &lt;br/&gt; for french keyboards, the non breaking space is option+shift+space, and the “|” character is option+shift+L. So fast typing often leads to the same error&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/martinschuerrer/~4/B3NAfuEe52U" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/martinschuerrer/~3/B3NAfuEe52U/610487226</link><guid isPermaLink="false">http://blog.schuerrer.org/post/610487226</guid><pubDate>Tue, 18 May 2010 19:02:00 +0200</pubDate><category>osx</category><category>mac</category><feedburner:origLink>http://blog.schuerrer.org/post/610487226</feedburner:origLink></item><item><title>File upload progress with Rails and nginx</title><description>&lt;p&gt;At &lt;a href="http://www.letsannotate.com"&gt;letsannotate.com&lt;/a&gt; users upload .pdf files and we convert them to images so that they work on every device. We wanted to show our users not only how far their upload had progressed, we also wanted to inform them about the status of the .pdf conversion.&lt;/p&gt;
&lt;p&gt;We use Rails on nginx via Passenger, but there are solutions for both &lt;a href="http://github.com/drogus/apache-upload-progress-module"&gt;Apache&lt;/a&gt; and &lt;a href="http://upload.lighttpd.net/"&gt;lighttpd&lt;/a&gt;.&lt;/p&gt;
&lt;h2&gt;nginx&lt;/h2&gt;
&lt;p&gt;First step: Install and configure nginx’s &lt;a href="http://wiki.nginx.org/NginxHttpUploadProgressModule"&gt;upload progress module&lt;/a&gt;.&lt;/p&gt;
&lt;script src="http://gist.github.com/389951.js?file=nginx.conf"&gt;&lt;/script&gt;&lt;h2&gt;Rails&lt;/h2&gt;
&lt;p&gt;Now we need to update our Rails controllers and views.&lt;/p&gt;
&lt;p&gt;We use &lt;a title="Assaf Arkin" href="http://labnotes.org/"&gt;assaf&lt;/a&gt;’s great &lt;a href="http://github.com/assaf/uuid"&gt;uuid gem&lt;/a&gt; to generate different identifiers for each upload.&lt;/p&gt;
&lt;pre class="brush: rails"&gt;  def new
    @document = Document.new
    @uuid = UUID.generate :compact
  end
&lt;/pre&gt;
&lt;p&gt;When creating our form we use the hidden_field ‘progress_token’ to pass the job’s uuid back to the server. Now once the user clicks on submit some browsers will block intermittent AJAX requests. To work around that we need an iframe (&lt;code&gt;:target =&gt; "uploadframe")&lt;/code&gt;&lt;/p&gt;
&lt;pre class="brush: html"&gt;&lt;% form_for(@document, :url =&gt; "/documents/?X-Progress-ID=#{@uuid}", :html =&gt; {:multipart =&gt; true, :target =&gt; "uploadframe", :onsubmit =&gt; "startUpload();"}) do |f| %&gt;
    &lt;%= f.hidden_field 'progress_token', :value =&gt; @uuid %&gt;
    &lt;%= f.file_field :pdf_file %&gt;
    &lt;%= f.submit 'Upload' %&gt;
&lt;% end %&gt;

&lt;div id="progress" style="width: 400px; background-color: silver;"&gt;
    &lt;div id="progressbar" style="width: 1px; height: 10px; background-color: black;"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div id="message"&gt;&lt;/div&gt;
&lt;iframe id="uploadframe" name="uploadframe" width="100%" height="100%" frameborder="0" border="0" src="about:blank"&gt;&lt;/iframe&gt;
&lt;/pre&gt;
&lt;h2&gt;Javascript&lt;/h2&gt;
&lt;p&gt;During the upload we query nginx every second how far along our file upload is. Once our file has been transfered completely we start querying our application how far the post-processing has come along.&lt;/p&gt;
&lt;p&gt;You can find this code - which is a modified version of the &lt;a href="http://wiki.nginx.org/NginxHttpUploadProgressModule#Usage"&gt;nginx example&lt;/a&gt; at &lt;a href="http://gist.github.com/389951#file_new.erb.html"&gt;this gist&lt;/a&gt; where you’ll also find expanded example code.&lt;/p&gt;
&lt;p&gt;Now once the upload and post-processing has finished we need a way to redirect not only the iframe but also its parent. We’ll need to use a &lt;a href="http://av5.com/docs/changing-parent-window-s-url-from-iframe-content.html"&gt;hack&lt;/a&gt; since  &lt;code&gt;parent.document.location&lt;/code&gt; is read only.&lt;/p&gt;
&lt;pre class="brush: html"&gt;&lt;!-- iframe --&gt;
&lt;script&gt;parent.changeParentUrl('&lt;%= new_url %&gt;');&lt;/script&gt;
&lt;/pre&gt;
&lt;pre class="brush: js"&gt;// parent frame
function changeParentUrl(url) { document.location = url; }
&lt;/pre&gt;
&lt;h2&gt;Enter redis&lt;/h2&gt;
&lt;p&gt;One thing’s left: While Rails (or a Resque/delayed_job worker) post-processes our document we have no way to get at its status. Redis to the rescue. We’ll simply update a key (e.g. &lt;code&gt;pdf_progress:1234&lt;/code&gt;) every time the document’s status changes.&lt;/p&gt;
&lt;script src="http://gist.github.com/389951.js?file=document.rb"&gt;&lt;/script&gt;&lt;p&gt;I hope this explains in detail how to create a seamless experience for file uploads. If there’s anything you’d like to know or if you believe I should create a complete example app, just leave a comment.&lt;/p&gt;&lt;img src="http://feeds.feedburner.com/~r/martinschuerrer/~4/c9jtrGEXybI" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/martinschuerrer/~3/c9jtrGEXybI/571570048</link><guid isPermaLink="false">http://blog.schuerrer.org/post/571570048</guid><pubDate>Tue, 04 May 2010 22:22:00 +0200</pubDate><feedburner:origLink>http://blog.schuerrer.org/post/571570048</feedburner:origLink></item><item><title>GWT Hosted Mode on 64 Bit Ubuntu</title><description>&lt;p&gt;&lt;span&gt;&lt;strong&gt;As far as I know this still works (for GWT 1.7) but has become obsolete with the release of GWT 2.0!&lt;/strong&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Here’s how I got GWT 1.7 Hosted Mode to work on my 64 bit Ubuntu Karmic Koala 9.10 laptop. These instructions should also work on Jaunty (9.04)&lt;/p&gt;
&lt;ol&gt;&lt;li&gt;Install ia32-sun-java6-bin:&lt;br/&gt;&lt;pre&gt;sudo apt-get install ia32-sun-java6-bin&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;Make sure the default Java installation remains the 64 bit one&lt;br/&gt;&lt;pre&gt;sudo update-java-alternatives --set java-6-sun&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;Download libstdc++5 for IA32 from Jaunty repos: &lt;a href="http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-3.3/libstdc++5_3.3.6-17ubuntu1_i386.deb"&gt;http://archive.ubuntu.com/ubuntu/pool/universe/g/gcc-3.3/libstdc++5_3.3.6-17ubuntu1_i386.deb&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Extract the libstdc++.so.5 file&lt;br/&gt;&lt;pre&gt;dpkg-deb --fsys-tarfile libstdc++5_3.3.6-17ubuntu1_i386.deb  | tar -O --extract './usr/lib/libstdc++.so.5.0.7' &gt; libstdc++.so.5&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;Move the extracted file to /usr/lib32&lt;br/&gt;&lt;pre&gt;sudo mv libstdc++.so.5 /usr/lib32&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;Run&lt;br/&gt;&lt;pre&gt;sudo ldconfig&lt;/pre&gt;
&lt;/li&gt;
&lt;li&gt;Start GWT:&lt;br/&gt;&lt;pre&gt;JAVA_HOME=/usr/lib/jvm/ia32-java-6-sun mvn gwt:run&lt;/pre&gt;
&lt;/li&gt;
&lt;/ol&gt;&lt;img src="http://feeds.feedburner.com/~r/martinschuerrer/~4/miU82Z6fmt4" height="1" width="1"/&gt;</description><link>http://feedproxy.google.com/~r/martinschuerrer/~3/miU82Z6fmt4/573056783</link><guid isPermaLink="false">http://blog.schuerrer.org/post/573056783</guid><pubDate>Sat, 26 Sep 2009 10:22:00 +0200</pubDate><feedburner:origLink>http://blog.schuerrer.org/post/573056783</feedburner:origLink></item></channel></rss>

