<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>http://awhitebox.com/</id>
  <title>awhitebox</title>
  <updated>2011-06-03T17:30:00Z</updated>
  <link rel="alternate" href="http://awhitebox.com/"/>
  <link rel="self" href="http://awhitebox.com/feed/all.xml"/>
  <author>
    <name>Ali B.</name>
    <uri>http://awhitebox.com/etc/about</uri>
  </author>
  <entry>
    <id>tag:awhitebox.com,2011-06-04:/uploading_files_to_cloudapp_from_alfred/</id>
    <title type="html">Uploading Files to CloudApp from Alfred</title>
    <published>2011-06-03T17:30:00Z</published>
    <updated>2011-06-03T17:30:00Z</updated>
    <link rel="alternate" href="http://awhitebox.com/uploading_files_to_cloudapp_from_alfred/"/>
    <content type="html">&lt;p&gt;&lt;em&gt;&lt;strong&gt;Update:&lt;/strong&gt; If you like, you can save yourself most of the configuration trouble and download the shortcut’s folder directly. I’ve put that up &lt;a href="https://github.com/dmondark/uptocloudapp" title="UpToCloudApp on Github"&gt;on github&lt;/a&gt;. The CloudApp icon is redistributed with permission.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;This one takes advantage of the new feature in &lt;a href="http://www.alfredapp.com/" title="Alfred"&gt;Alfred&lt;/a&gt; 0.9, Result Actions (Requires Powerpack). Actions can be performed on files that are selected using File Navigation or File Search. Basically they are like any other terminal shortcuts but with the ‘action’ checkbox checked, which tells Alfred to pass in the full file path as &lt;code&gt;{query}&lt;/code&gt; when used in that context.&lt;/p&gt;

&lt;p&gt;I used &lt;a href="http://aaronrussell.co.uk/" title="Aaron Russell"&gt;Aaron Russell&lt;/a&gt;’s &lt;a href="https://github.com/aaronrussell/cloudapp_api" title="aaronrussell / cloudapp_api"&gt;cloudapp api wrapper gem&lt;/a&gt;, which made it really easy to create this script which basically adds an action to upload files selected in Alfred to &lt;a href="http://www.getcloudapp.com/" title="CloudApp"&gt;CloudApp&lt;/a&gt;. I also use &lt;a href="http://appscript.sourceforge.net/rb-appscript/index.html" title="Ruby Appscript"&gt;rb-appscript&lt;/a&gt; for the Growl notification AppleScript. You will need to install both of these gems to be able to use this script:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;$ sudo gem install cloudapp_api rb-appscript
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You may or may not need to use &lt;code&gt;sudo&lt;/code&gt; depending on your setup.&lt;/p&gt;

&lt;p&gt;Either paste the script shown below in a file somewhere or download it from &lt;a href="http://cl.ly/7Izl"&gt;this link&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Make sure you edit the script to set your CloudApp email address and password.&lt;/p&gt;

&lt;p&gt;As usual, create a new shortcut in the ‘Terminal/Shell’ section in Alfred Preferences.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.flickr.com/photos/dmondark/5793713663/" title="Alfred Preferences Screenshot" rel="external" class="image"&gt;&lt;img src="http://farm4.static.flickr.com/3138/5793713663_665d8b437f.jpg" width="500" height="381" alt="Alfred Preferences Screenshot" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can use whatever you want for the Title and Description. In this particular case, I didn’t really care about the Keyword as I don’t intend to use this shortcut directly.&lt;/p&gt;

&lt;p&gt;In Command, point to the script you created/downloaded while passing the &lt;code&gt;{query}&lt;/code&gt; in which Alfred will pass the file path:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;~/bin/cloudapp_upload "{query}"
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;In addition, you can pass in  one or two option to further customise the script’s behaviour:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;-p&lt;/strong&gt; Create the drops as private.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;-m&lt;/strong&gt; Mute the notification sound the script plays after finishing the upload.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Make sure you check both ‘Quotes’ and ‘Spaces’. After saving, tick both ‘Silent’ and ‘Action’.&lt;/p&gt;

&lt;p&gt;That should be it. Now, if you navigate to a file (Fire up Alfred and start typing &lt;code&gt;/&lt;/code&gt; or &lt;code&gt;~&lt;/code&gt;), or if you locate a file using &lt;code&gt;find&lt;/code&gt;, hit CTRL to select the file and display the actions list, and you should see your brand new action at the bottom. Select it, patiently wait for the script to upload the file, and done! The URL of the file will also be copied to the clipboard straight away.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.flickr.com/photos/dmondark/5793713817/" title="Growl Notification Screenshot" rel="external" class="image image"&gt;&lt;img src="http://farm4.static.flickr.com/3320/5793713817_c58a68700f.jpg" width="500" height="307" alt="Alfred Preferences Screenshot" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here’s the script:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#!/usr/local/bin/ruby

require 'cloudapp_api'
require 'appscript'

# Set your CloudApp credentials:
EMAIL = 'your_email@example.com'
PASSWORD = 'yourpassword'

file = ARGV[0]
privacy = ARGV[1] == '-p' || ARGV[2] == '-p'
mute = ARGV[1] == '-m' || ARGV[2] == '-m'

exit if file.nil?

# Authenticate to CloudApp
client = CloudApp::Client.new
client.authenticate EMAIL, PASSWORD

# Upload file
drop = client.upload file, :private =&amp;gt; privacy

# Create a Growl notification
include Appscript
growl = app("GrowlHelperApp")
notifications = ["CloudAppUpload"]
growl.register(
  :as_application =&amp;gt; "CloudAppUpload",
  :all_notifications =&amp;gt; notifications,
  :default_notifications =&amp;gt; notifications
)
growl.notify(
  :with_name =&amp;gt; "CloudAppUpload",
  :title =&amp;gt; "CloudApp Upload Succeeded",
  :description =&amp;gt; "The file '#{drop.name}' has been sucessfully uploaded to Cloudapp: #{drop.url}",
  :application_name =&amp;gt; "CloudAppUpload",
  :icon_of_application =&amp;gt; "Alfred"
)
# Play sound
exec 'afplay /System/Library/Sounds/Glass.aiff' unless mute

# Copy file URL to clipboard
IO.popen('pbcopy', 'r+') do |clipboard|
  clipboard.puts "#{drop.url}"
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;You can respond to this article by &lt;a href="http://twitter.com/dmondark" title="@dmondark" rel="external"&gt;replying on twitter&lt;/a&gt; or &lt;a href="&amp;#109;&amp;#097;&amp;#105;&amp;#108;&amp;#116;&amp;#111;:&amp;#097;&amp;#108;&amp;#105;&amp;#064;&amp;#097;&amp;#119;&amp;#104;&amp;#105;&amp;#116;&amp;#101;&amp;#098;&amp;#111;&amp;#120;&amp;#046;&amp;#099;&amp;#111;&amp;#109;" title="Email"&gt;sending me an email&lt;/a&gt;.&lt;/p&gt;

</content>
  </entry>
  <entry>
    <id>tag:awhitebox.com,2011-06-02:/partial_templates_in_lithium/</id>
    <title type="html">Partial Templates in Lithium</title>
    <published>2011-06-02T02:40:00Z</published>
    <updated>2011-06-02T02:40:00Z</updated>
    <link rel="alternate" href="http://awhitebox.com/partial_templates_in_lithium/"/>
    <content type="html">&lt;p&gt;&lt;em&gt;&lt;strong&gt;Update:&lt;/strong&gt; I’ve put the helper explained below in a &lt;a href="https://github.com/dmondark/li3_partials" title="li3_partials"&gt;lithium plugin&lt;/a&gt; so that it can be easily reused instead of copying the helper across all of your webapps. Installation is super easy and is explained in the plugin’s README.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;When building web applications with a MVC framework, we are bound to end up with views that share common form field. For example, both ‘New Post’ and ‘Edit Post’ will both have ‘Post title’, ‘Post content’ and so forth.&lt;/p&gt;

&lt;p&gt;Most frameworks already have solutions for that. I know that Rails uses partial templates – most commonly known as &lt;a href="http://guides.rubyonrails.org/layouts_and_rendering.html#using-partials" title="Layouts and Rendering in Rails - Using Partials"&gt;partials&lt;/a&gt;. Put simply, partials are templates that can be rendered and re-rendered by views.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://lithify.me/" title="Lithium PHP Framwork"&gt;Lithium&lt;/a&gt; already has something very similar, dubbed “Elements”. So it’s already exceptionally trivial to render a template from within a lithium view.&lt;/p&gt;

&lt;p&gt;Consider the following example view, &lt;code&gt;views/posts/add.html.php&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;?=$this-&amp;gt;form-&amp;gt;create($post)?&amp;gt;
  &amp;lt;?=$this-&amp;gt;form-&amp;gt;field('title', array('type' =&amp;gt; 'text'))?&amp;gt;
  &amp;lt;?=$this-&amp;gt;form-&amp;gt;field('content', array('type' =&amp;gt; 'textarea'))?&amp;gt;
  &amp;lt;?=$this-&amp;gt;form-&amp;gt;submit('Add Post')?&amp;gt;
&amp;lt;?=$this-&amp;gt;form-&amp;gt;end()?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;We would probably have at least one other view, &lt;code&gt;views/posts/edit.html.php&lt;/code&gt; with the content of which would look very similar to the above.&lt;/p&gt;

&lt;p&gt;Say, as an example, both views share a common chunk, that is the two lines where &lt;code&gt;field&lt;/code&gt; is called. We can then, move those two lines to a separate file &lt;code&gt;views/elements/fields.html.php&lt;/code&gt;, and render it directly from within the views:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;?=$this-&amp;gt;form-&amp;gt;create($post)?&amp;gt;
  &amp;lt;?=$this-&amp;gt;view()-&amp;gt;render(array('element' =&amp;gt; 'fields'))?&amp;gt;
  &amp;lt;?=$this-&amp;gt;form-&amp;gt;submit('Add Post')?&amp;gt;
&amp;lt;?=$this-&amp;gt;form-&amp;gt;end()?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Works like a charm, but &lt;em&gt;slightly&lt;/em&gt; ugly for my taste! And it seemed to me that there was a cleaner way to render these templates, and that is to use a helper.&lt;/p&gt;

&lt;p&gt;Creating a helper in Lithium is quite easy. We simply extend the &lt;code&gt;\lithium\template\Helper&lt;/code&gt; class:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;?php

// Partial.php

namespace app\extensions\helper;

class Partial extends \lithium\template\Helper {
  public function __call($method, $args) {
    $params = empty($args)? array() : $args[0];
    return $this-&amp;gt;_context-&amp;gt;view()-&amp;gt;render(array('element'=&amp;gt; "{$method}_partial"), $params);
  }
}
?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Placing the class file above in our app’s &lt;code&gt;extensions\helper&lt;/code&gt; should do the trick. Now, we simply call the &lt;code&gt;partial&lt;/code&gt; helper from the view to render the partial:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;?=$this-&amp;gt;form-&amp;gt;create($post)?&amp;gt;
  &amp;lt;?=$this-&amp;gt;partial-&amp;gt;fields()?&amp;gt;
  &amp;lt;?=$this-&amp;gt;form-&amp;gt;submit('Add Post')?&amp;gt;
&amp;lt;?=$this-&amp;gt;form-&amp;gt;end()?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Good! You can also pass in arbitrary variables to the partial templates as an array (e.g. using &lt;code&gt;compact()&lt;/code&gt;):&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;&amp;lt;?=$this-&amp;gt;partial-&amp;gt;fields(compact('foo', 'bar'))?&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;The renderer will &lt;code&gt;extract&lt;/code&gt; that array to make the variables &lt;code&gt;$foo&lt;/code&gt; and &lt;code&gt;$bar&lt;/code&gt; available for the &lt;code&gt;fields.html.php&lt;/code&gt; template to use.&lt;/p&gt;

&lt;p&gt;More on templates and helpers in Lithium can be found &lt;a href="http://lithify.me/docs/lithium/template" title="Docs for lithium\template"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can respond to this article by &lt;a href="http://twitter.com/dmondark" title="@dmondark" rel="external"&gt;replying on twitter&lt;/a&gt; or &lt;a href="&amp;#109;&amp;#097;&amp;#105;&amp;#108;&amp;#116;&amp;#111;:&amp;#097;&amp;#108;&amp;#105;&amp;#064;&amp;#097;&amp;#119;&amp;#104;&amp;#105;&amp;#116;&amp;#101;&amp;#098;&amp;#111;&amp;#120;&amp;#046;&amp;#099;&amp;#111;&amp;#109;" title="Email"&gt;sending me an email&lt;/a&gt;.&lt;/p&gt;

</content>
  </entry>
  <entry>
    <id>tag:awhitebox.com,2011-05-30:/alfred_time_in_place/</id>
    <title type="html">Quick world time lookup using Alfred and Growl</title>
    <published>2011-05-30T02:14:00Z</published>
    <updated>2011-05-30T02:14:00Z</updated>
    <link rel="alternate" href="http://awhitebox.com/alfred_time_in_place/"/>
    <content type="html">&lt;p&gt;I’ve been an avid &lt;a href="http://www.alfredapp.com/" title="Alfred" rel="external"&gt;Alfred&lt;/a&gt; user since its early days. It’s just one of these pieces of software that you get attached to and want to use for everything. Alfred is a fast, lightweight and friendly app launcher. But it’s also much more than that. Terminal shortcuts, custom searches and clipboard snippets are probably my top used features in addition to the app launching and file browser. I’d recommend checking it out if you haven’t already. The &lt;a href="http://www.alfredapp.com/powerpack/" title="Alfred Powerpack" rel="external"&gt;powerpack&lt;/a&gt; is worth every single penny.&lt;/p&gt;

&lt;p&gt;Anna’s &lt;a href="http://alfredtips.tumblr.com/post/5764007045/the-one-in-which-you-navigate-time-zones-if" title="Anna's Alfred Hat Tips - The one in which you navigate time zone" rel="external"&gt;article&lt;/a&gt; about setting up a custom search to quickly navigate to a &lt;a href="http://www.worldtimebuddy.com/" title="Worldtime Buddy" rel="external"&gt;Worldtime Buddy&lt;/a&gt; reminded me of something I do quite often when I want to quickly tell the current time is it in any city around the world. Especially handy if you work with a team whose members are scattered all over the world. I often just ask Google. For example, searching for “time in sydney” gives you the current time in Sydney, along with the search results. Which, at that point, is basically just jargon.&lt;/p&gt;

&lt;p&gt;In Alfred you can simply use ‘google time in sydney’ which would open a new tab in your browser and basically do the above. But I wanted something even quicker and does not involve opening a new browser tab that I’d be closing 3 seconds after.&lt;/p&gt;

&lt;p&gt;Enter timeinplace, a small and simple script that hits that search page, grabs that line of text and displays it in a &lt;a href="http://growl.info/" title="Growl" rel="external"&gt;Growl&lt;/a&gt; notification.&lt;/p&gt;

&lt;p&gt;Here’s how.&lt;/p&gt;

&lt;p&gt;Download the &lt;a href="http://www.cl.ly/7CRt" title="The script"&gt;script&lt;/a&gt; and place it somewhere convenient. I often put my own scripts in &lt;code&gt;~/bin/&lt;/code&gt; which I’ve already added to my &lt;code&gt;$PATH&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;You will need to make that script executable&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;chmod +x timeinplace
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And you will also need to install the &lt;a href="http://nokogiri.org/" title="Nokogiri" rel="external"&gt;nokogiri&lt;/a&gt; and &lt;a href="http://appscript.sourceforge.net/rb-appscript/index.html" title="Ruby Appscript" rel="external"&gt;rb-appscript&lt;/a&gt; gems if you don’t have them already.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;gem install nokogiri rb-appscript
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Now open Alfred Preferences, and navigate to the ‘Terminal/Shell’ section. Use the ‘+’ button under the shortcuts list to add a new shortcut.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.flickr.com/photos/dmondark/5775628479/" title="Alfred Preferences Screenshot" rel="external" class="image"&gt;&lt;img src="http://farm6.static.flickr.com/5183/5775628479_5dc5ba4209.jpg" width="500" height="379" alt="Alfred Preferences Screenshot" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use whatever you like for ‘Title’, ‘Description’ and ‘Keyword’. The latter is what you will be using to run the script, so I recommend something short and easy. I use ‘time’ so I can type in ‘time in city’ like I’m used to.&lt;/p&gt;

&lt;p&gt;For ‘Command’ put in &lt;code&gt;timeinplace"{query}"&lt;/code&gt;, make sure ‘Quotes’ is checked and save the shortcut. Don’t forget to check the ‘Silent’ checkbox next to your shortcut in the list. This will tell Alfred not to execute the script in a visible terminal window.&lt;/p&gt;

&lt;p&gt;Tip: If you are having trouble getting the script to work in Silent mode, try using the absolute path to the script in ‘Command’ instead. i.e. &lt;code&gt;~/bin/timeinplace "{query}"&lt;/code&gt; in my case.&lt;/p&gt;

&lt;p&gt;That’s it. Fire Alfred and type in ‘time in melbourne’, a second or two to wait, and…&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.flickr.com/photos/dmondark/5776169566/" title="Growl Notification Screenshot" rel="external" class="image"&gt;&lt;img src="http://farm4.static.flickr.com/3190/5776169566_bca79dd77e.jpg" width="322" height="112" alt="Alfred Preferences Screenshot" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For those who only wanted to take a look, here’s the script&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#!/usr/local/bin/ruby

require 'open-uri'
require 'cgi'
require 'nokogiri'
require 'appscript'
include Appscript

query = ARGV[0]
exit if query.nil?

begin
  url = "http://www.google.com/search?q=time+#{CGI.escape(query)}"
  res = Nokogiri::HTML(open(url)).at("li.tpo").text
  description, title = res.split(' - ')
rescue
  title = "Cannot find time"
  description = "Cannot find timne for '#{query}'"
end

growl = app("GrowlHelperApp")
notifications = ["TimeInPlace"]
growl.register(
  :as_application =&amp;gt; "TimeInPlace",
  :all_notifications =&amp;gt; notifications,
  :default_notifications =&amp;gt; notifications
)
growl.notify(
  :with_name =&amp;gt; "TimeInPlace",
  :title =&amp;gt; title,
  :description =&amp;gt; description,
  :application_name =&amp;gt; "TimeInPlace",
  :icon_of_application =&amp;gt; "Alfred"
)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Enjoy.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update&lt;/strong&gt;: Slightly refactored the script to use the &lt;code&gt;appscript&lt;/code&gt; library instead of the ugly applescript wrapped in an uglier &lt;code&gt;system()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can respond to this article by &lt;a href="http://twitter.com/dmondark" title="@dmondark" rel="external"&gt;replying on twitter&lt;/a&gt; or &lt;a href="&amp;#109;&amp;#097;&amp;#105;&amp;#108;&amp;#116;&amp;#111;:&amp;#097;&amp;#108;&amp;#105;&amp;#064;&amp;#097;&amp;#119;&amp;#104;&amp;#105;&amp;#116;&amp;#101;&amp;#098;&amp;#111;&amp;#120;&amp;#046;&amp;#099;&amp;#111;&amp;#109;" title="Email"&gt;sending me an email&lt;/a&gt;.&lt;/p&gt;

</content>
  </entry>
  <entry>
    <id>tag:awhitebox.com,2011-03-19:/soft_launching/</id>
    <title type="html">Soft Launching</title>
    <published>2011-03-19T01:40:00Z</published>
    <updated>2011-03-19T01:40:00Z</updated>
    <link rel="alternate" href="http://awhitebox.com/soft_launching/"/>
    <content type="html">&lt;p&gt;“Just launch it already!” is, more or less, the response I got every time I talked about my plans for awhitebox.
So as you can see, I’m yielding and finally letting it loose. Expect a long write-up soon.&lt;/p&gt;

&lt;p&gt;People who know me wouldn’t hold their breaths though ;-)&lt;/p&gt;

&lt;p&gt;&lt;a href="http://www.flickr.com/photos/apelad/3964507213/" title="Laugh-Out-Loud Cats #1248 by Ape Lad, on Flickr" rel="external" class="image"&gt;&lt;img src="http://farm3.static.flickr.com/2644/3964507213_4819de77fc.jpg" width="500" height="331" alt="Laugh-Out-Loud Cats #1248" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt; – Laugh-Out-Loud Cats #1248 (&lt;a href="http://creativecommons.org/licenses/by-nc-nd/2.0/" title="Attribution-NonCommercial-NoDerivs 2.0 Generic (CC BY-NC-ND 2.0)" rel="external"&gt;by-nc-nd&lt;/a&gt;) by &lt;a href="http://www.flickr.com/photos/apelad/" title="Ape Lad's Flickr page" rel="external"&gt;Ape Lad&lt;/a&gt;.&lt;/small&gt;&lt;/p&gt;

</content>
  </entry>
</feed>
