<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Zachary Pinter</title>
 <link href="http://zacharypinter.com/atom.xml" rel="self"/>
 <link href="http://zacharypinter.com"/>
 <updated>2011-06-19T10:29:08-06:00</updated>
 <id>http://zacharypinter.com</id>
 <author>
   <name>Zachary Pinter</name>
 </author>

 
 <entry>
   <title>RailsConf 2011 Recap</title>
   <link href="http://zacharypinter.com//2011/05/21/railsconf-2011-recap.html"/>
   <updated>2011-05-21T00:00:00-06:00</updated>
   <id>http://zacharypinter.com//2011/05/21/railsconf-2011-recap</id>
   <content type="html">&lt;p&gt;RailsConf 2011 took place in Baltimore last week and I had the luck to not only attend but &lt;a href='http://zacharypinter.com/2011/05/21/railsconf-2011-rails-on-hbase.html'&gt;speak at the conference&lt;/a&gt;. It was my first time attending a RailsConf, and I was thoroughly impressed with the number of great talks, great after-parties, and how well-organized the conference was. Here&amp;#8217;s the recap:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href='http://en.oreilly.com/rails2011/public/schedule/detail/18656'&gt;Rails Best Practices&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Gregg Pollack and crew from Envy Labs opened up one of their &lt;a href='http://codeschool.com'&gt;codeschool.com&lt;/a&gt; courses and walked the audience through it. Each section was coupled with a video of a classic arcade game where the sound effects were replaced by hilarious vocalizations. Even if the games were only loosely related to the topic, it was a great example of capturing the audience&amp;#8217;s attention.&lt;/p&gt;

&lt;p&gt;The course had a healthy dose of game mechanics (a points system with hints that docked your score) and that ended up being a lot of fun. Time will tell whether learning this way sticks better than skimming blog posts.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;a href='http://igniterailsconf.com/'&gt;Ignite RailsConf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Ignite ended up being a packed house with lots of great presentations. Some favorites included &amp;#8220;How to create awesome Screencasts&amp;#8221; and &amp;#8220;20 Awesome Gems&amp;#8221;&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;a href='http://en.oreilly.com/rails2011/public/schedule/detail/20380'&gt;Cloud Foundry - The Rails Developer&amp;#8217;s Perspective&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Some developers seem to shy away from sponsored talks, but I really enjoyed this one. In particular, I&amp;#8217;m interested in using Cloud Foundry as an alternative to Chef for setting up single-machine Linode instances, which I think could prove a useful middleground between rolling-your-own and the price of Heroku. The project is young, but this is definitely one to watch.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;a href='http://en.oreilly.com/rails2011/public/schedule/detail/19456'&gt;20 Productivity Tips: You Can Be 15 Percent More Productive&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I met Hirotsugu Asari in the speaker lounge and he struck me as a really talented developer and genuinely nice person. His talk ended up going pretty deep into mathematical formulas, though I loved his summation: &amp;#8220;Productivity = Number of successful Pomodori while working towards a SMART goal in a given time period&amp;#8221;. Oh, and did I mention he has an &lt;a href='http://en.wikipedia.org/wiki/Erd%C5%91s_number'&gt;Erdős number&lt;/a&gt; of 2 ?!&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;a href='http://en.oreilly.com/rails2011/public/schedule/detail/19527'&gt;Why you should never use an ORM&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Having played around with MongoMapper in the past, I was looking forward to John Nunemaker&amp;#8217;s talk. The title was meant to be a little inflammatory, but it contained a lot of great points. There&amp;#8217;s definitely value in understanding all the magic that an ORM is doing for you. Also, there&amp;#8217;s a lot of cost and hidden complexity when trying to retro-fit an existing ORM on top of something that doesn&amp;#8217;t really fit.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;a href='http://en.oreilly.com/rails2011/public/schedule/detail/19359'&gt;The Holy Grail of Databases&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This was one of my favorite talks at the conference. There&amp;#8217;s something to be said for speakers that talk fast and pack a lot of material in a 50 minute presentation. Eric Redmond gave a great overview of the datastore landscape and how the various datastores compare to each other, complete with sample code. Also, his seamless integration of pre-recorded coding demos had many of us wondering if he was live coding while talking! The presentation left me wanting to learn more and I can&amp;#8217;t wait to grab a copy of his upcoming book, &lt;a href='http://www.sevenweeks.org/'&gt;Seven Databases in Seven Weeks&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;a href='http://en.oreilly.com/rails2011/public/schedule/detail/19701'&gt;Lessons Learned Keynote&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I&amp;#8217;ve been looking to implement a Continuous Deployment infrastructure ever since hearing Eric Reis speak about his setup at IMVU. However, working in the client services industry makes it a difficult sell to clients. This means that I only have side-projects to try it out on. I was happy to get the chance to &lt;a href='http://youtu.be/IVBVZGfzkVM?t=31m55s'&gt;ask Eric about bootstrapping continuous deployment with a small userbase&lt;/a&gt; (which makes it difficult to A/B test). While his response was not what I expected, it was a good reframing of the issue. He pointed out that having a &amp;#8220;pathetically small number of customers&amp;#8221; is actually an advantage since you can get to know your customers without the need for statistics. Side note: I can&amp;#8217;t stand how my voice sounds when recorded.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;a href='http://en.oreilly.com/rails2011/public/schedule/detail/19674'&gt;Stateful, Scalable Servers with EventMachine and Rails&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;With all the node.js rage, it was nice to see the Ruby approach with EventMachine. You certainly have to be more careful not to make a call that blocks the event loop, but I think Ruby still wins when it comes to clean and readable code. A good example David Troy gave in this presentation was a POP server that implemented its commands as method calls, making it easy to add new commands without having to explicitly define a mapping.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;a href='http://en.oreilly.com/rails2011/public/schedule/detail/17861'&gt;Deploying with Bundler&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Though I&amp;#8217;ve been using the basic features of Bundler for some time, I appreciated this broad overview of the tool and the problems it is solving. Happily, I don&amp;#8217;t need to deploy to servers that block internet connections, but it&amp;#8217;s good to know they&amp;#8217;re thinking about that stuff if the need ever arises.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;a href='http://en.oreilly.com/rails2011/public/schedule/detail/18378'&gt;Solving Performance Problems with Horizontal Scale (The Worker Pattern)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I met Ryan Smith at the Heroku booth and was looking forward to his talk. It was interesting to see the pattern he was advocating (loading a busy message in a div then polling the server until the operation is done). This pattern is quite common in Flex Apps, and I was pleased to see a straight-forward Rails-based implementation. Also, I liked his point about checking the HTTP status codes before rolling your own solution. Only downside: it was scheduled at the same time as the lightning talks, which had rave reviews.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;a href='http://en.oreilly.com/rails2011/public/schedule/detail/18591'&gt;50 in 50&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Programming meets poetry. This has to be one of the strangest talks I&amp;#8217;ve ever attended. That said, the Shakespeare videos were hilarious. I recommend watching &lt;a href='http://youtu.be/Nii1n8PYLrc'&gt;the video&lt;/a&gt;, preferably with your favorite alcoholic beverage.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;a href='http://en.oreilly.com/rails2011/public/schedule/detail/18047'&gt;Building Rails Apps for the Rich Client&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This was another one of my favorite talks from the conference. Yehuda gave a great presentation on the strengths of Rails over Sinatra/Rack/RollYourOwn when it comes to developing REST APIs. I tend to think Sinatra fits best for single-screen-of-code apps, and this talk further cemented the idea.&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;&lt;a href='http://en.oreilly.com/rails2011/public/schedule/detail/19572'&gt;Cutting your own RubyGems&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Sadly, I&amp;#8217;ve been more of a gem consumer than creator. After hearing this talk, there&amp;#8217;s no reason not to wrap your common code in a gem. They&amp;#8217;ve really streamlined the process. Main takeaway: visit &lt;a href='http://guides.rubygems.org/'&gt;http://guides.rubygems.org/&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;</content>
 </entry>
 
 <entry>
   <title>RailsConf 2011 - Rails on HBase</title>
   <link href="http://zacharypinter.com//2011/05/21/railsconf-2011-rails-on-hbase.html"/>
   <updated>2011-05-21T00:00:00-06:00</updated>
   <id>http://zacharypinter.com//2011/05/21/railsconf-2011-rails-on-hbase</id>
   <content type="html">&lt;p&gt;I was happy to give a &lt;a href='http://en.oreilly.com/rails2011/public/schedule/detail/17886'&gt;presentation at RailsConf 2011&lt;/a&gt; with &lt;a href='http://twitter.com/thillerson'&gt;Tony Hillerson&lt;/a&gt; titled &amp;#8220;Rails on HBase&amp;#8221;. We gave the talk from the position of a Rails developer interested in knowing if HBase might be a good fit for their app. The main takeaway was that unless you&amp;#8217;re hitting the limits of your relational database, the costs of HBase will likely outweight the benefits. For more details, take a look at the slides below:&lt;/p&gt;
&lt;div id='__ss_8021199' style='width:425px'&gt; &lt;strong style='display:block;margin:12px 0 4px'&gt;&lt;a href='http://www.slideshare.net/thillerson/rails-on-hbase' title='Rails on HBase'&gt;Rails on HBase&lt;/a&gt;&lt;/strong&gt; &lt;iframe marginheight='0' scrolling='no' src='http://www.slideshare.net/slideshow/embed_code/8021199' marginwidth='0' frameborder='0' height='355' width='425' /&gt; &lt;div style='padding:5px 0 12px'&gt; View more &lt;a href='http://www.slideshare.net/'&gt;presentations&lt;/a&gt; from &lt;a href='http://www.slideshare.net/thillerson'&gt;Tony Hillerson&lt;/a&gt; &lt;/div&gt; &lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Keyboard-driven Window Management in OS X</title>
   <link href="http://zacharypinter.com//2009/06/15/keyboard-driven-window-management-in-osx.html"/>
   <updated>2009-06-15T00:00:00-06:00</updated>
   <id>http://zacharypinter.com//2009/06/15/keyboard-driven-window-management-in-osx</id>
   <content type="html">&lt;p&gt;Ever since reading about &lt;a href='http://en.wikipedia.org/wiki/Tiling_window_manager'&gt;Tiling Window Managers&lt;/a&gt; in Linux, I&amp;#8217;ve been looking to either switch to Ubuntu (sadly, I can&amp;#8217;t get it to support my cinema display) or achieve a similar effect on OS X.&lt;/p&gt;

&lt;p&gt;I posted a &lt;a href='http://stackoverflow.com/questions/276760/tiling-window-manager-for-os-x'&gt;question&lt;/a&gt; to &lt;a href='http://stackoverflow.com'&gt;StackOverflow&lt;/a&gt;, which eventually led me to &lt;a href='http://www.irradiatedsoftware.com/sizeup/'&gt;SizeUp&lt;/a&gt;. Initially, SizeUp did not support moving windows between monitors, though that has since been addressed. I found that the default key bindings interfered with Emacs and other applications, so I have mine setup as follows:&lt;/p&gt;

&lt;p&gt;&lt;img src='/images/sizeup_keybindings.png' alt='Zachary Pinters SizeUp Key bindings' /&gt;&lt;/p&gt;

&lt;p&gt;The setup is quite intuitive, as I simply hold down Command + Option along with one of the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;| y | u | i | o | p |
    | j | k | l |
    | m | , | . |&lt;/code&gt;&lt;/pre&gt;

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;y&lt;/em&gt; moves the window to the left screen&lt;/li&gt;

&lt;li&gt;&lt;em&gt;p&lt;/em&gt; moves the window to the right screen&lt;/li&gt;

&lt;li&gt;&lt;em&gt;k&lt;/em&gt; centers and maximizes the window (true maximize, not the crappy Apple maximize)&lt;/li&gt;

&lt;li&gt;&lt;em&gt;i&lt;/em&gt;, and &lt;em&gt;,&lt;/em&gt; move the window to the top or bottom half of the screen&lt;/li&gt;

&lt;li&gt;&lt;em&gt;j&lt;/em&gt;, and &lt;em&gt;l&lt;/em&gt; move the window to the left or right half of the screen&lt;/li&gt;

&lt;li&gt;&lt;em&gt;u&lt;/em&gt;, &lt;em&gt;o&lt;/em&gt;, &lt;em&gt;m&lt;/em&gt;, and &lt;em&gt;.&lt;/em&gt; move the window to the corners of the screen&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;By matching the commands to the qwerty layout, it&amp;#8217;s easy to remember which key combination to use.&lt;/p&gt;

&lt;p&gt;I&amp;#8217;m not a fan of Command+Tab for application switching (I usually have a lot of applications to choose from). Instead, I use Quicksilver/Google Quick Search to type the first few letters of the application I want to switch to. From there, I use Command + ~ to switch between the windows of the application.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Easy screenshot sharing with Dropbox and Hazel</title>
   <link href="http://zacharypinter.com//2009/05/01/easy-screenshot-sharing-with-dropbox-and-hazel.html"/>
   <updated>2009-05-01T00:00:00-06:00</updated>
   <id>http://zacharypinter.com//2009/05/01/easy-screenshot-sharing-with-dropbox-and-hazel</id>
   <content type="html">&lt;p&gt;I often find myself using Dropbox&amp;#8217;s public folder to share quick screenshots. This is a fairly tedious process, but it&amp;#8217;s better than dealing with IM/firewall/vpn issues. To streamline things a bit, I recently setup a Hazel rule that automatically moves screenshots to Dropbox and copies the link to my clipboard.&lt;/p&gt;

&lt;p&gt;To set this up for yourself, first add the Desktop folder to Hazel:&lt;/p&gt;

&lt;p&gt;&lt;img src='/images/hazel_folder.png' alt='Hazel Folder Setup' /&gt;&lt;/p&gt;

&lt;p&gt;Then, setup the rule as follows:&lt;/p&gt;

&lt;p&gt;&lt;img src='/images/hazel_rule.png' alt='Hazel Dropbox Rule' /&gt;&lt;/p&gt;

&lt;p&gt;Now, you can simply press Command+Shift+4 to take screenshots and Command+V to paste the links.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Technical Content on the eSlick Reader</title>
   <link href="http://zacharypinter.com//2009/03/01/technical-content-on-the-eslick-reader.html"/>
   <updated>2009-03-01T00:00:00-07:00</updated>
   <id>http://zacharypinter.com//2009/03/01/technical-content-on-the-eslick-reader</id>
   <content type="html">&lt;p&gt;A while back Dave Thomas wrote about the state of &lt;a href='http://pragdave.blogs.pragprog.com/pragdave/2008/07/help-us-decide.html'&gt;technical content and ebooks&lt;/a&gt;. He provided several screenshots of a sample book on the Kindle. Sadly, the device didn&amp;#8217;t hold up too well and it looks like &lt;a href='http://www.amazon.com/dp/B00154JDAI?tag=zereader-20'&gt;version 2&lt;/a&gt; isn&amp;#8217;t much better.&lt;/p&gt;

&lt;p&gt;The problem, at least for me, is that most of the content I would like to read on an E Ink device is in PDF format. The Kindle doesn&amp;#8217;t natively support the display of PDFs. Instead, you have to first go through their conversion process which can clip and distort the information you&amp;#8217;re trying to see. Other devices, like the &lt;a href='http://www.amazon.com/dp/B000WPXQ2M?tag=zereader-20'&gt;Sony eReader&lt;/a&gt;, can read PDFs natively. However, the software doesn&amp;#8217;t seem to be &lt;a href='http://thinkwrap.wordpress.com/2007/01/03/sony-ereader-first-impression/'&gt;getting much praise&lt;/a&gt;. &lt;a href='http://www.irextechnologies.com/products/iliad'&gt;The Iliad eReader&lt;/a&gt; seems to have much better support, but it comes at a steep price of $700.&lt;/p&gt;

&lt;p&gt;The &lt;a href='http://www.foxitsoftware.com/ebook/'&gt;eSlick Reader&lt;/a&gt;, on the other hand, was made for displaying PDFs. I haven&amp;#8217;t actually seen the device, but given &lt;a href='http://www.foxitsoftware.com/pdf/rd_intro.php'&gt;Foxit&amp;#8217;s track record&lt;/a&gt; I have high hopes. As such, I recently emailed their support and asked them to provide some pictures of &lt;a href='http://media.pragprog.com/mobi_example/form_input_controls.pdf'&gt;the same PDF&lt;/a&gt; that Dave Thomas tested with the Kindle:&lt;/p&gt;

&lt;p&gt;&lt;a href='/images/eslick/2-1.jpg'&gt;&lt;img src='/images/eslick/2-1_tn.jpg' alt='eSlick 1' /&gt;&lt;/a&gt; &lt;a href='/images/eslick/3-1.jpg'&gt;&lt;img src='/images/eslick/3-1_tn.jpg' alt='eSlick 2' /&gt;&lt;/a&gt; &lt;a href='/images/eslick/4-1.jpg'&gt;&lt;img src='/images/eslick/4-1_tn.jpg' alt='eSlick 3' /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href='/images/eslick/5-1.jpg'&gt;&lt;img src='/images/eslick/5-1_tn.jpg' alt='eSlick 4' /&gt;&lt;/a&gt; &lt;a href='/images/eslick/5-2.jpg'&gt;&lt;img src='/images/eslick/5-2_tn.jpg' alt='eSlick 5' /&gt;&lt;/a&gt; &lt;a href='/images/eslick/5-3.jpg'&gt;&lt;img src='/images/eslick/5-3_tn.jpg' alt='eSlick 6' /&gt;&lt;/a&gt; &lt;a href='/images/eslick/5-4.jpg'&gt;&lt;img src='/images/eslick/5-4_tn.jpg' alt='eSlick 7' /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, the device handles the document well. The source code doesn&amp;#8217;t get clipped, the small text is readable, and the images look pretty decent. Now, there are some disadvantages. The device is quite basic. It doesn&amp;#8217;t have any wireless support and the MP3 player seems like more of a gimmic than a useful addition. However, for $259 the eSlick looks like one of the best options out there for reading technical PDFs away from the computer.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Greedy Algorithms and Politics</title>
   <link href="http://zacharypinter.com//2009/01/21/greedy-algorithms-and-politics.html"/>
   <updated>2009-01-21T00:00:00-07:00</updated>
   <id>http://zacharypinter.com//2009/01/21/greedy-algorithms-and-politics</id>
   <content type="html">&lt;p&gt;I&amp;#8217;ve been a Libertarian pretty much since I&amp;#8217;ve been able to vote. I&amp;#8217;m for small government, free markets, and just about every personal/social liberty that doesn&amp;#8217;t infringe on my own. However, I don&amp;#8217;t kid myself that free market capitalism is without flaws.&lt;/p&gt;

&lt;p&gt;At the core of free market capitalism is the idea that the market, with individuals and corporations all acting in their own best interests, will find far more optimal solutions to problems than any type of grand oversight. Furthermore, attempts to interfere with highly complex markets will usually have unintended or unforeseen side effects. While I believe this generalization to be largely true, I am reminded of a certain type of algorithm from Computer Science: &lt;a href='http://en.wikipedia.org/wiki/Greedy_algorithm'&gt;The Greedy Algorithm&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Greedy algorithms are generally easy to understand, easy to parallelize, and (relatively) quick to execute. They might not always find the optimal solution to a given problem, but for many classes of problems they are the easiest way to find a close approximation. Tasks well-suited to greedy algorithms are those with an &amp;#8220;optimal substructure.&amp;#8221; By optimal substructure, I mean tasks that can be broken down into subcomponents where the best solutions for each subcomponent can be combined to produce the best solution for the whole. In many ways, capitalism has an optimal substructure: At each level, the incentive of wealth can drive people to create more of it. This, in turn, makes for a wealthier society, which provides more opportunity for others to create wealth. It&amp;#8217;s a feedback loop which results in wealthier people, wealthier corporations, and wealthier countries.&lt;/p&gt;

&lt;p&gt;However, there are problems for which a greedy algorithm is not a good fit. Consider a chess game: the capture of a queen might locally (for this move) seem like the best choice, but it could result in ultimately loosing the game. Or, consider the differences between the &lt;a href='http://en.wikipedia.org/wiki/Elevator_algorithm'&gt;Elevator algorithm&lt;/a&gt; and the &lt;a href='http://en.wikipedia.org/wiki/Shortest_seek_first'&gt;Shortest seek first algorithm&lt;/a&gt;. If the elevators in our buildings used shortest seek first (a greedy algorithm), then the average response time overall might very well go down, yet it would be at the expense of ignoring some floors for minutes or even hours during busy times.&lt;/p&gt;

&lt;p&gt;If we can admit that there are problems with greedy algorithms in the computer science world, then it&amp;#8217;s not a stretch to say there are problems with free market capitalism in the &amp;#8220;real&amp;#8221; world. The question is, what is the alternative?&lt;/p&gt;

&lt;p&gt;For many, the obvious answer is government. However, government is a double-edged sword. For as much power as a government has to do good, it also has the same power to do bad. As Gerald Ford once said, &amp;#8220;A government big enough to give you everything you want is a government big enough to take from you everything you have.&amp;#8221; The founding fathers of the United States were well aware of this, which is why they tried to limit government. However, even if you could assume a benevolent government, you still have the problem of efficiency. As we&amp;#8217;ve seen repeatedly, lack of competition within government makes for sloth and waste.&lt;/p&gt;

&lt;p&gt;So, in closing, I&amp;#8217;m a Libertarian because given the choice of government problems versus free market problems, I choose the free market. It&amp;#8217;s not that I think free market capitalism is perfect, or even fair. It leaves a lot to be desired. However, I find that keeping the market in check with an even larger government is a much scarier proposition.&lt;/p&gt;

&lt;p&gt;Perhaps, given this new era of technology and communication a new type of societal structure could emerge that addresses both the short-sightedness of markets as well as the sloth and size of government. Over the next few weeks I plan to speculate on the qualities such a society might have. Stay tuned!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Emacs - Great Operating System, Decent Editor</title>
   <link href="http://zacharypinter.com//2009/01/14/emacs-great-operating-system-decent-editor.html"/>
   <updated>2009-01-14T00:00:00-07:00</updated>
   <id>http://zacharypinter.com//2009/01/14/emacs-great-operating-system-decent-editor</id>
   <content type="html">&lt;p&gt;There have been plenty of jokes made about how Emacs is more of an OS than a text editor. Over the years, the highly extensible nature of Emacs (through elisp) has led to a crazy amount of software being developed for this &amp;#8220;text editor.&amp;#8221; But why is that? Why in the world would somebody want a text editor &lt;em&gt;slash&lt;/em&gt; irc chatter &lt;em&gt;slash&lt;/em&gt; file manager &lt;em&gt;slash&lt;/em&gt; email application?&lt;/p&gt;

&lt;p&gt;It is my belief that the value of Emacs lies not in its ability to edit text (for which it does a pretty good job), but in how it has become the defacto framework for keyboard-based applications. You see, there&amp;#8217;s a certain category of person that strives to optimize the mundane or common operations of their life. Programmers are especially prone to this. Languages like Ruby and Python allow one to easily write scripts that blaze through otherwise tedious problems, &lt;a href='/2008/08/20/everyday-ruby-scripting-renaming-files.html'&gt;like renaming files&lt;/a&gt;. And then there&amp;#8217;s the command line: For many tasks, such as file manipulation and ftp, far more intuitive graphical interfaces exist. However, one cannot help but love the extra time gained by using the command line equivalent.&lt;/p&gt;

&lt;p&gt;Sadly, graphical applications tend to lack the speed (measured in user-productivity) of their text-based equivalents. Making an application keyboard-driven, if even possible, requires a large amount of effort with modern application frameworks. That&amp;#8217;s where the beauty of Emacs comes in. Emacs is one of the few frameworks centered around keyboard navigation, primarily due to its legacy as a terminal-based text editor.&lt;/p&gt;

&lt;p&gt;So, what are the strengths of Emacs for text-based applications?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Common metaphors (buffers, frames, windows, navigation, marking text)&lt;/li&gt;

&lt;li&gt;Powerful scripting language&lt;/li&gt;

&lt;li&gt;Ability to easily move data between buffers and &amp;#8220;programs&amp;#8221;&lt;/li&gt;

&lt;li&gt;Ability to link to other buffers/files that are handled by other scripts/plugins&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And the weaknesses?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Non-intuitive key-bindings&lt;/li&gt;

&lt;li&gt;Carpal tunnel-inducing keystrokes&lt;/li&gt;

&lt;li&gt;Limited graphics/drawing capability&lt;/li&gt;

&lt;li&gt;High learning curve&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Looking at Emacs from this perspective has sparked an idea. Why not make a framework specifically for keyboard-driven applications? It need not be a full-fledged text editor, but it could easily have several uses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Thor/rake/capistrano interface&lt;/li&gt;

&lt;li&gt;Twitter client&lt;/li&gt;

&lt;li&gt;Blog editor&lt;/li&gt;

&lt;li&gt;Feed Reader&lt;/li&gt;

&lt;li&gt;Git interface&lt;/li&gt;

&lt;li&gt;IM/IRC Client&lt;/li&gt;

&lt;li&gt;File manager&lt;/li&gt;

&lt;li&gt;GTD/Task manager&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now, such a project should have some high-level goals:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Easy on the wrists and fingers&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Perhaps vim-like modes&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Easy to learn and learns from you&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Focus on quicksilver-style auto-completions for most operations&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Easy to develop for&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use a common scripting language (ruby, python, javascript?)&lt;/li&gt;

&lt;li&gt;Easy rendering (perhaps webkit minus the form components?)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And the bonus features:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;High Stability&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Isolated processes&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;No single plugin/script takes down the application&lt;/p&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Local or remote apps&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Websites could expose a markup/api that&amp;#8217;s compatible with the framework&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;

&lt;li&gt;
&lt;p&gt;Accessibility&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In theory, this would be easier with an app that doesn&amp;#8217;t rely on the mouse&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, let&amp;#8217;s create a framework for keyboard-driven applications. Make it easy to learn, easy to develop for, and with an eye towards end-user efficiency. What do you say?&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Passing arguments to Item Renderers</title>
   <link href="http://zacharypinter.com//2008/11/27/passing-arguments-to-item-renderers.html"/>
   <updated>2008-11-27T00:00:00-07:00</updated>
   <id>http://zacharypinter.com//2008/11/27/passing-arguments-to-item-renderers</id>
   <content type="html">&lt;p&gt;When trying to create general-purpose item renderers in Flex, one of the first things I ran into was passing arguments. Passing arguments allows you to use the same item renderer in different ways.&lt;/p&gt;

&lt;p&gt;The best solution I&amp;#8217;ve been able to come up with is to create my own factory class:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='actionscript'&gt;&lt;span class='kd'&gt;package&lt;/span&gt; &lt;span class='nx'&gt;com&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;zacharypinter&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;util&lt;/span&gt;
&lt;span class='p'&gt;{&lt;/span&gt;
   &lt;span class='kd'&gt;import&lt;/span&gt; &lt;span class='nx'&gt;flash&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;utils&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nb'&gt;Dictionary&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt;
   
   &lt;span class='kd'&gt;import&lt;/span&gt; &lt;span class='nx'&gt;mx&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;core&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;IFactory&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt;

   &lt;span class='kd'&gt;public&lt;/span&gt; &lt;span class='kd'&gt;class&lt;/span&gt; &lt;span class='nx'&gt;ArgumentsToRendererFactory&lt;/span&gt; &lt;span class='kd'&gt;implements&lt;/span&gt; &lt;span class='nx'&gt;IFactory&lt;/span&gt;
   &lt;span class='p'&gt;{&lt;/span&gt;
      &lt;span class='kd'&gt;private&lt;/span&gt; &lt;span class='k'&gt;var&lt;/span&gt; &lt;span class='nx'&gt;klass&lt;/span&gt;&lt;span class='o'&gt;:&lt;/span&gt;&lt;span class='nb'&gt;Class&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt;
      &lt;span class='kd'&gt;private&lt;/span&gt; &lt;span class='k'&gt;var&lt;/span&gt; &lt;span class='nx'&gt;args&lt;/span&gt;&lt;span class='o'&gt;:*;&lt;/span&gt;
      
      &lt;span class='kd'&gt;public&lt;/span&gt; &lt;span class='kd'&gt;function&lt;/span&gt; &lt;span class='nx'&gt;ArgumentsToRendererFactory&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nx'&gt;args&lt;/span&gt;&lt;span class='o'&gt;:*,&lt;/span&gt;&lt;span class='nx'&gt;klass&lt;/span&gt;&lt;span class='o'&gt;:&lt;/span&gt;&lt;span class='nb'&gt;Class&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
         &lt;span class='k'&gt;this&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;args&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='nx'&gt;args&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt;
         &lt;span class='k'&gt;this&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;klass&lt;/span&gt;&lt;span class='o'&gt;=&lt;/span&gt;&lt;span class='nx'&gt;klass&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt;
      &lt;span class='p'&gt;}&lt;/span&gt;
      
      &lt;span class='kd'&gt;public&lt;/span&gt; &lt;span class='kd'&gt;function&lt;/span&gt; &lt;span class='nx'&gt;newInstance&lt;/span&gt;&lt;span class='p'&gt;()&lt;/span&gt;&lt;span class='o'&gt;:*&lt;/span&gt;
      &lt;span class='p'&gt;{&lt;/span&gt;
         &lt;span class='k'&gt;var&lt;/span&gt; &lt;span class='nx'&gt;instance&lt;/span&gt;&lt;span class='o'&gt;:&lt;/span&gt;&lt;span class='nb'&gt;Object&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='nx'&gt;klass&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt;
         

         &lt;span class='k'&gt;for&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='k'&gt;var&lt;/span&gt; &lt;span class='nx'&gt;key&lt;/span&gt;&lt;span class='o'&gt;:&lt;/span&gt;&lt;span class='nb'&gt;String&lt;/span&gt; &lt;span class='k'&gt;in&lt;/span&gt; &lt;span class='nx'&gt;args&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
            &lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nx'&gt;instance&lt;/span&gt;&lt;span class='p'&gt;.&lt;/span&gt;&lt;span class='nx'&gt;hasOwnProperty&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nx'&gt;key&lt;/span&gt;&lt;span class='p'&gt;))&lt;/span&gt; &lt;span class='p'&gt;{&lt;/span&gt;
               &lt;span class='nx'&gt;instance&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='nx'&gt;key&lt;/span&gt;&lt;span class='p'&gt;]&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='nx'&gt;args&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='nx'&gt;key&lt;/span&gt;&lt;span class='p'&gt;];&lt;/span&gt;
            &lt;span class='p'&gt;}&lt;/span&gt;
         &lt;span class='p'&gt;}&lt;/span&gt;
         
         &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='nx'&gt;instance&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt;   
      &lt;span class='p'&gt;}&lt;/span&gt;
      
   &lt;span class='p'&gt;}&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To use it, you can write something like this:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='xml'&gt;&lt;span class='nt'&gt;&amp;lt;mx:List&lt;/span&gt; 
   &lt;span class='na'&gt;width=&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;100%&amp;quot;&lt;/span&gt; &lt;span class='na'&gt;height=&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;100%&amp;quot;&lt;/span&gt; 
   &lt;span class='na'&gt;dataProvider=&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;{users}&amp;quot;&lt;/span&gt; 
   &lt;span class='na'&gt;selectable=&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;false&amp;quot;&lt;/span&gt; 
   &lt;span class='na'&gt;itemRenderer=&lt;/span&gt;&lt;span class='s'&gt;&amp;quot;{new ArgumentsToRendererFactory({group:this.radioGroup},UserRenderer)}&amp;quot;&lt;/span&gt; 
&lt;span class='nt'&gt;/&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In the above example, I&amp;#8217;m using the ArgumentsToRendererFactory to pass a radio group to every item renderer. This lets me use radio buttons inside a list component.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Everyday Ruby Scripting - Renaming Files</title>
   <link href="http://zacharypinter.com//2008/08/20/everyday-ruby-scripting-renaming-files.html"/>
   <updated>2008-08-20T00:00:00-06:00</updated>
   <id>http://zacharypinter.com//2008/08/20/everyday-ruby-scripting-renaming-files</id>
   <content type="html">&lt;p&gt;I recently had the need to replace around 50 files. However, the new files did not have the same name as the old files.&lt;/p&gt;

&lt;p&gt;The old files had names like: AD5001.indd AD5002.indd AD5003.indd&lt;/p&gt;

&lt;p&gt;and the new files had names like: AD5001_rev.indd AD5002_rev.indd AD5003_rev.indd&lt;/p&gt;

&lt;p&gt;The solution was a quick ruby script:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='nb'&gt;require&lt;/span&gt; &lt;span class='s1'&gt;&amp;#39;fileutils&amp;#39;&lt;/span&gt;
&lt;span class='n'&gt;rev_files&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='no'&gt;Dir&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;glob&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;./**/*_rev*.indd&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
    
&lt;span class='n'&gt;rev_files&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;each&lt;/span&gt; &lt;span class='k'&gt;do&lt;/span&gt; &lt;span class='o'&gt;|&lt;/span&gt;&lt;span class='n'&gt;rf&lt;/span&gt;&lt;span class='o'&gt;|&lt;/span&gt;
  &lt;span class='n'&gt;orig_file&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;rf&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;gsub&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;_rev&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
  &lt;span class='no'&gt;FileUtils&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;rm&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;orig_file&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
  &lt;span class='no'&gt;FileUtils&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;mv&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;rf&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='n'&gt;orig_file&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
  &lt;span class='nb'&gt;puts&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;Replaced &lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;orig_file&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt; with &lt;/span&gt;&lt;span class='si'&gt;#{&lt;/span&gt;&lt;span class='n'&gt;rf&lt;/span&gt;&lt;span class='si'&gt;}&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Originally, I was going to use some combination of Emacs and find-dired, but ultimately this proved simpler.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>301 Redirects in Rails</title>
   <link href="http://zacharypinter.com//2008/07/25/301-redirects-in-rails.html"/>
   <updated>2008-07-25T00:00:00-06:00</updated>
   <id>http://zacharypinter.com//2008/07/25/301-redirects-in-rails</id>
   <content type="html">&lt;p&gt;If you&amp;#8217;ve ever searched for how to do a 301 redirect in Rails, you&amp;#8217;ve probably seen this code:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='n'&gt;headers&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='s2'&gt;&amp;quot;Status&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;301 Moved Permanently&amp;quot;&lt;/span&gt;
&lt;span class='n'&gt;redirect_to&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;http://www.domain.com/&amp;quot;&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;However, after doing some testing (thanks &lt;a href='http://rspec.info'&gt;rspec&lt;/a&gt;!), I found that the above snippet does not work. Instead, it sends a 302 temporary redirect, which, of course, has an entirely different meaning for the search engines visiting your site.&lt;/p&gt;

&lt;p&gt;Apparently, somewhere along the way, Rails stopped honoring the explicit Status header when using &lt;code&gt;redirect_to&lt;/code&gt;. To achieve the correct result, you must now use:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='n'&gt;head&lt;/span&gt; &lt;span class='ss'&gt;:moved_permanently&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:location&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;http://www.domain.com/&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To make things nicer, I added the following function to my application.rb file:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='k'&gt;def&lt;/span&gt; &lt;span class='nf'&gt;perm_redirect_to&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;options&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
   &lt;span class='n'&gt;url&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='k'&gt;case&lt;/span&gt; &lt;span class='n'&gt;options&lt;/span&gt;
         &lt;span class='k'&gt;when&lt;/span&gt; &lt;span class='nb'&gt;String&lt;/span&gt;
           &lt;span class='n'&gt;options&lt;/span&gt;
         &lt;span class='k'&gt;else&lt;/span&gt;
           &lt;span class='n'&gt;url_for&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='n'&gt;options&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
        &lt;span class='n'&gt;e&lt;/span&gt; &lt;span class='k'&gt;end&lt;/span&gt;
   &lt;span class='n'&gt;head&lt;/span&gt; &lt;span class='ss'&gt;:moved_permanently&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt; &lt;span class='ss'&gt;:location&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='n'&gt;url&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
 <entry>
   <title>Weak References with Dictionaries in Actionscript</title>
   <link href="http://zacharypinter.com//2007/10/11/weak-references-with-dictionaries-in-actionscript.html"/>
   <updated>2007-10-11T00:00:00-06:00</updated>
   <id>http://zacharypinter.com//2007/10/11/weak-references-with-dictionaries-in-actionscript</id>
   <content type="html">&lt;p&gt;Actionscript dictionaries are a great tool for dealing with memory management because you can use them to create weak references to objects. This means that the object automatically goes away upon garbage collection if the only reference to it is in the Dictionary.&lt;/p&gt;

&lt;p&gt;To use a dictionary in this manner, simply pass true to the constructor. However, one should note that this &lt;em&gt;only&lt;/em&gt; makes the keys of the Dictionary weak.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='actionscript3'&gt;&lt;span class='kd'&gt;class&lt;/span&gt; &lt;span class='n'&gt;MyObject&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
  &lt;span class='kd'&gt;public&lt;/span&gt; &lt;span class='kd'&gt;var&lt;/span&gt; &lt;span class='n'&gt;message&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;String&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt;
&lt;span class='o'&gt;}&lt;/span&gt;

&lt;span class='kd'&gt;var&lt;/span&gt; &lt;span class='n'&gt;dict&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;Dictionary&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='kt'&gt;Dictionary&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='kc'&gt;true&lt;/span&gt;&lt;span class='o'&gt;);&lt;/span&gt;
&lt;span class='kd'&gt;var&lt;/span&gt; &lt;span class='n'&gt;obj1&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;MyObject&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='kt'&gt;MyObject&lt;/span&gt;&lt;span class='o'&gt;();&lt;/span&gt;
    
&lt;span class='n'&gt;obj1&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='na'&gt;message&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;My really long message...&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt;
&lt;span class='kd'&gt;var&lt;/span&gt; &lt;span class='n'&gt;obj2&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;MyObject&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='kt'&gt;MyObject&lt;/span&gt;&lt;span class='o'&gt;();&lt;/span&gt;
&lt;span class='n'&gt;obj2&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='na'&gt;message&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;My second really long message...&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt;

&lt;span class='n'&gt;dict&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='n'&gt;obj1&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='kc'&gt;true&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt; &lt;span class='c1'&gt;// obj1 is weakly referenced&lt;/span&gt;
&lt;span class='n'&gt;dict&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;2&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='n'&gt;obj2&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt; &lt;span class='c1'&gt;// obj2 is strongly referenced&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;If the only reference to an object is the &lt;em&gt;key&lt;/em&gt; of a weakly referenced dictionary, the object will not persist after garbage collection. However, if the only reference to an object is the &lt;em&gt;value&lt;/em&gt; of a key in a weakly referenced dictionary, the reference is considered strong and will force the object to persist after garbage collection.&lt;/p&gt;

&lt;p&gt;So, what do you do if you want to store a dictionary of weakly referenced objects, but key them off of a meaningful value (such as an item id) rather than their reference id?&lt;/p&gt;

&lt;p&gt;The answer is to use a simple WeakReference class &lt;a href='http://www.bigroom.co.uk/blog/create-your-own-weak-references-in-actionscript-3'&gt;source&lt;/a&gt;:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='actionscript3'&gt;&lt;span class='kd'&gt;class&lt;/span&gt; &lt;span class='n'&gt;WeakRef&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
  &lt;span class='kd'&gt;private&lt;/span&gt; &lt;span class='kd'&gt;var&lt;/span&gt; &lt;span class='n'&gt;dic&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;Dictionary&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt;
		
  &lt;span class='kd'&gt;public&lt;/span&gt; &lt;span class='kd'&gt;function &lt;/span&gt;&lt;span class='nf'&gt;WeakRef&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;obj&lt;/span&gt;&lt;span class='o'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;*&lt;/span&gt;&lt;span class='o'&gt;):&lt;/span&gt;&lt;span class='kt'&gt;void&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
    &lt;span class='n'&gt;dic&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='kt'&gt;Dictionary&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt; &lt;span class='kc'&gt;true&lt;/span&gt; &lt;span class='o'&gt;);&lt;/span&gt;
    &lt;span class='n'&gt;dic&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='n'&gt;obj&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt;
  &lt;span class='o'&gt;}&lt;/span&gt;
		
  &lt;span class='kd'&gt;public&lt;/span&gt; &lt;span class='kd'&gt;function &lt;/span&gt;&lt;span class='nf'&gt;get&lt;/span&gt;&lt;span class='o'&gt;():&lt;/span&gt;&lt;span class='kt'&gt;*&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
    &lt;span class='k'&gt;for&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt; &lt;span class='n'&gt;var&lt;/span&gt; &lt;span class='n'&gt;item&lt;/span&gt;&lt;span class='o'&gt;:*&lt;/span&gt; &lt;span class='k'&gt;in&lt;/span&gt; &lt;span class='n'&gt;dic&lt;/span&gt; &lt;span class='o'&gt;)&lt;/span&gt; &lt;span class='o'&gt;{&lt;/span&gt;
      &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='n'&gt;item&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt;
    &lt;span class='o'&gt;}&lt;/span&gt;
    &lt;span class='k'&gt;return&lt;/span&gt; &lt;span class='kc'&gt;null&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt;
  &lt;span class='o'&gt;}&lt;/span&gt;
&lt;span class='o'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;From here, you can do the following:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='actionscript3'&gt;&lt;span class='kd'&gt;var&lt;/span&gt; &lt;span class='n'&gt;dict&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;Dictionary&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='kt'&gt;Dictionary&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='kc'&gt;true&lt;/span&gt;&lt;span class='o'&gt;);&lt;/span&gt;
&lt;span class='kd'&gt;var&lt;/span&gt; &lt;span class='n'&gt;obj1&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;MyObject&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='kt'&gt;MyObject&lt;/span&gt;&lt;span class='o'&gt;();&lt;/span&gt;

&lt;span class='n'&gt;obj1&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='na'&gt;message&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;My really long message...&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt;
&lt;span class='kd'&gt;var&lt;/span&gt; &lt;span class='n'&gt;obj2&lt;/span&gt;&lt;span class='p'&gt;:&lt;/span&gt;&lt;span class='kt'&gt;MyObject&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='kt'&gt;MyObject&lt;/span&gt;&lt;span class='o'&gt;();&lt;/span&gt;
&lt;span class='n'&gt;obj2&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='na'&gt;message&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;My second really long message...&amp;quot;&lt;/span&gt;&lt;span class='o'&gt;;&lt;/span&gt;

&lt;span class='n'&gt;dict&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;1&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='kt'&gt;WeakReference&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;obj1&lt;/span&gt;&lt;span class='o'&gt;);&lt;/span&gt; &lt;span class='c1'&gt;//weakly referenced value&lt;/span&gt;
&lt;span class='n'&gt;dict&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='mi'&gt;2&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='k'&gt;new&lt;/span&gt; &lt;span class='kt'&gt;WeakReference&lt;/span&gt;&lt;span class='o'&gt;(&lt;/span&gt;&lt;span class='n'&gt;obj2&lt;/span&gt;&lt;span class='o'&gt;);&lt;/span&gt; &lt;span class='c1'&gt;//weakly referenced value&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now, you can key based off of a meaningful value, and still get all the benefits of weak references.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Actionscript Hash</title>
   <link href="http://zacharypinter.com//2007/10/09/actionscript-hash.html"/>
   <updated>2007-10-09T00:00:00-06:00</updated>
   <id>http://zacharypinter.com//2007/10/09/actionscript-hash</id>
   <content type="html">&lt;p&gt;On the surface, the Dictionary object in Actionscript seems quite limited compared to the Hash and HashMap libraries of other languages. However, the functionality you would expect is still there, it’s just obscure.&lt;/p&gt;

&lt;p&gt;For example, to loop through all keys in a Dictionary:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='actionscript'&gt;&lt;span class='k'&gt;for&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='k'&gt;var&lt;/span&gt; &lt;span class='nx'&gt;key&lt;/span&gt;&lt;span class='o'&gt;:&lt;/span&gt;&lt;span class='nb'&gt;Object&lt;/span&gt; &lt;span class='k'&gt;in&lt;/span&gt; &lt;span class='nx'&gt;groupMap&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
&lt;span class='p'&gt;{&lt;/span&gt;
   &lt;span class='nf'&gt;trace&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nx'&gt;key&lt;/span&gt; &lt;span class='o'&gt;+&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;, &amp;quot;&lt;/span&gt; &lt;span class='o'&gt;+&lt;/span&gt; &lt;span class='nx'&gt;groupMap&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='nx'&gt;key&lt;/span&gt;&lt;span class='p'&gt;]);&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To loop through all values in a Dictionary:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='actionscript'&gt;&lt;span class='k'&gt;for&lt;/span&gt; &lt;span class='k'&gt;each&lt;/span&gt; &lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='k'&gt;var&lt;/span&gt; &lt;span class='nx'&gt;item&lt;/span&gt;&lt;span class='o'&gt;:&lt;/span&gt;&lt;span class='nb'&gt;Object&lt;/span&gt; &lt;span class='k'&gt;in&lt;/span&gt; &lt;span class='nx'&gt;groupMap&lt;/span&gt;&lt;span class='p'&gt;)&lt;/span&gt;
&lt;span class='p'&gt;{&lt;/span&gt;
   &lt;span class='nf'&gt;trace&lt;/span&gt;&lt;span class='p'&gt;(&lt;/span&gt;&lt;span class='nx'&gt;item&lt;/span&gt;&lt;span class='p'&gt;);&lt;/span&gt;
&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To check if a key exists (in a way that’s distinguishes from a key whose value could be null):&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='actionscript'&gt;&lt;span class='nx'&gt;obj&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='s1'&gt;&amp;#39;key&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;]&lt;/span&gt; &lt;span class='o'&gt;===&lt;/span&gt; &lt;span class='kc'&gt;undefined&lt;/span&gt;  &lt;span class='c1'&gt;//key exists&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To remove a key/value pair from a Dictionary:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='actionscript'&gt;&lt;span class='nx'&gt;delete&lt;/span&gt; &lt;span class='nx'&gt;obj&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='s1'&gt;&amp;#39;key&amp;#39;&lt;/span&gt;&lt;span class='p'&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;All of the above code will also work for a regular object treated like a hash.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>What are Ruby Symbols?</title>
   <link href="http://zacharypinter.com//2005/12/12/what-are-ruby-symbols.html"/>
   <updated>2005-12-12T00:00:00-07:00</updated>
   <id>http://zacharypinter.com//2005/12/12/what-are-ruby-symbols</id>
   <content type="html">&lt;p&gt;I&amp;#8217;ve introduced a few friends/classmates/coworkers to Ruby and Rails lately, and many of them have since approached me and asked &amp;#8220;what is that colon thing in ruby?&amp;#8221; So, I&amp;#8217;ve decided to explain Ruby symbols as I know them.&lt;/p&gt;

&lt;p&gt;Symbols are essentially small, automatically created global read-only objects that have a unique numerical value associated with them and are accessed through the &lt;code&gt;:[name]&lt;/code&gt; syntax. Any time you use a named symbol (such as &lt;code&gt;:bob&lt;/code&gt;), you are really telling Ruby to find the object associated with the name &amp;#8220;bob&amp;#8221; in the global table of symbols. Therefore, &lt;code&gt;:bob&lt;/code&gt; in one class returns exactly the same object that &lt;code&gt;:bob&lt;/code&gt; returns in another class.&lt;/p&gt;

&lt;p&gt;The numerical value associated with a symbol object is generated for you behind the scenes. You don&amp;#8217;t really care what it is, you just care that it is unique among all other symbols.&lt;/p&gt;

&lt;p&gt;This nature of symbol objects creates some very useful applications. For one, you can use a symbol as a named constant whose value you do not care about. For instance, you might have a C library with tons of interesting constants like &lt;code&gt;AR_REL_OP_GREATER_EQUAL = 3&lt;/code&gt; For the sake of C programming, that constant has to have a value. However, if all you really care about is whether or not something is flagged as &lt;code&gt;AR_REL_OP_GREATER_EQUAL&lt;/code&gt;, then the actual value is practically meaningless. In such a case with Ruby, you could use symbols to write code like&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='k'&gt;if&lt;/span&gt; &lt;span class='n'&gt;x&lt;/span&gt;&lt;span class='o'&gt;.&lt;/span&gt;&lt;span class='n'&gt;operation&lt;/span&gt; &lt;span class='o'&gt;==&lt;/span&gt; &lt;span class='ss'&gt;:greater_equal&lt;/span&gt;
   &lt;span class='c1'&gt;#...&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can check whether or not a value equals &lt;code&gt;:greater_equal&lt;/code&gt; without ever having to select a numerical value for &lt;code&gt;:greater_equal&lt;/code&gt;. As an added bonus, you can call &lt;code&gt;:greater_equal.to_s&lt;/code&gt; and get a full-blown String object out of the name of the Symbol. Now, that might not seem like a big deal just now, but think about converting AR_REL_OP_GREATER_EQUAL into a cstring. With symbols, it&amp;#8217;s a piece of cake, and there are plenty of times when finding the actual name of a constant is useful, especially when it comes to debugging.&lt;/p&gt;

&lt;p&gt;Since the actual object that is referenced by a symbol is global and unchangeable, it makes a perfect candidate for use as a key in a hash table. That is why you always see syntax such as:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;code class='ruby'&gt;&lt;span class='p'&gt;{&lt;/span&gt;&lt;span class='ss'&gt;:name&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;Zachary&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='ss'&gt;:job&lt;/span&gt; &lt;span class='o'&gt;=&amp;gt;&lt;/span&gt; &lt;span class='s2'&gt;&amp;quot;Programmer&amp;quot;&lt;/span&gt;&lt;span class='p'&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The above code is short-hand syntax for creating a Hash object with the keys &lt;code&gt;:name&lt;/code&gt; and &lt;code&gt;:job&lt;/code&gt; mapped to the values &amp;#8220;Zachary&amp;#8221; and &amp;#8220;Programmer&amp;#8221;. Yes, one can always use String objects as keys in a Hash, but in Ruby, a String object is changeable (mutable). For example, you can call gsub! on a String and replace the contents of the object. Doing so would change the value that the String would hash to, and corrupt any Hash table that String was used as a key in.&lt;/p&gt;

&lt;p&gt;If you&amp;#8217;re a Java programmer, you should note this very important difference between a Ruby String and a Java String. In Java, String objects are unchangeable (immutable) and StringBuffers are changeable (mutable). In Ruby, Symbol objects are unchangeable and String objects are changeable. When you call concat (&amp;#8221;+&amp;#8221;) or replace on a Java String, you are actualy creating a brand new String object (instead of making changes to the current one). This is precisely why Java programmers are told to use a StringBuffer class instead of the &amp;#8221;+&amp;#8221; sign to concatenate several strings. In Ruby, no concern is paid to concatenation, since the core String class is mutable. Similarly, in Java, it is common to use a String object as a key in a HashMap. In Ruby, that&amp;#8217;s frowned upon since a lot of things could go wrong if that String object were changed (as explained above).&lt;/p&gt;

&lt;p&gt;Symbols may seem awkward at first because they are not common among other programming languages. However, there are many pro&amp;#8217;s to the tradeoff made by choosing String/Symbol (Ruby) over StringBuffer/String (Java). Additionally, the unique nature of symbols has it&amp;#8217;s own benefits when it comes to flags that were traditionally set with numerical constants.&lt;/p&gt;</content>
 </entry>
 
 
</feed>