<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Zachary Pinter</title>
 
 <link href="http://zacharypinter.com" />
 <updated>2009-06-28T14:30:28-06:00</updated>
 <id>http://zacharypinter.com</id>
 <author>
   <name>Zachary Pinter</name>
 </author>

 
 <link rel="self" href="http://feeds.feedburner.com/zacharypinter" type="application/atom+xml" /><entry>
   <title>Content Providers - Embrace the internet or die fighting it</title>
   <link href="http://zacharypinter.com//2009/06/28/content-providers-embrace-the-internet-or-die-fighting-it.html" />
   <updated>2009-06-28T00:00:00-06:00</updated>
   <id>http://zacharypinter.com//2009/06/28/content-providers-embrace-the-internet-or-die-fighting-it</id>
   <content type="html">&lt;p&gt;The recent cat-and-mouse games that Hulu has been fighting against &lt;a href='http://twitter.com/ishuluonboxee'&gt;Boxee&lt;/a&gt; and the &lt;a href='http://www.last100.com/2009/06/28/hulu-really-hates-the-tv-playstation-3-blocked/'&gt;Playstation 3&lt;/a&gt; are absolutely ridiculous. One of the reasons Hulu is so popular, even when competing against free downloads, is the convenience it offers. Without that convenience, why use it over the alternatives? If content providers try to restrict how and when their content is viewed, then customers who would otherwise willing to pay (either directly or indirectly through ads) will defect to restriction-free alternatives and feel no moral hardship for doing so. However, if there is a reasonable, legally sanctioned service that has all the features and convenience required, then what is left to decide? As long as the social norm is to pay for content, people will be internally compelled to choose the legal option.&lt;/p&gt;

&lt;p&gt;What does this mean for the television and movie industries? Well, the current generation is quite used to paying for content: they go to the movies, they rent and buy videos, and they subscribe to cable or satellite. Up until recently, these business models have remained relatively isolated since it’s fairly cumbersome and time consuming to download video content over the internet. However, that’s changing and it’s the time for content providers to change with it. Do not make the same mistakes that the music industry made. Downloading a song is now akin to driving 5 mph over the speed limit. Sure, it might be illegal, but few people think of themselves as immoral for doing so.&lt;/p&gt;

&lt;p&gt;The new motto for the entertainment industry should be “buy once, play anywhere.” If your customers are subscribing to cable or satellite, why not give them a website to view all the same content? If a computer crashes, why not let the user redownload anything they’ve already purchased? If a customer can view a show online, why shouldn’t they be able to play it on their phone and their television set? I certainly understand and appreciate the fact that the revenues from these new mediums are far lower than existing mediums. However, there’s something far greater at stake: the ethics of the upcoming generation. Don’t let it become a question of features. Keep the focus on morality and ensure a strong customer base for generations to come.&lt;/p&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’ve been looking to either switch to Ubuntu (sadly, I can’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’s easy to remember which key combination to use.&lt;/p&gt;

&lt;p&gt;I’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’s public folder to share quick screenshots. This is a fairly tedious process, but it’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’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’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’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’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’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’t actually seen the device, but given &lt;a href='http://www.foxitsoftware.com/pdf/rd_intro.php'&gt;Foxit’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’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’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’ve been a Libertarian pretty much since I’ve been able to vote. I’m for small government, free markets, and just about every personal/social liberty that doesn’t infringe on my own. However, I don’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 “optimal substructure.” 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’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’s not a stretch to say there are problems with free market capitalism in the “real” 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, “A government big enough to give you everything you want is a government big enough to take from you everything you have.” 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’ve seen repeatedly, lack of competition within government makes for sloth and waste.&lt;/p&gt;

&lt;p&gt;So, in closing, I’m a Libertarian because given the choice of government problems versus free market problems, I choose the free market. It’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 “text editor.” 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’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’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’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 “programs”&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’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’t rely on the mouse&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, let’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’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;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;/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;span class='nt'&gt;&lt;mx:List&lt;/span&gt; 
   &lt;span class='na'&gt;width=&lt;/span&gt;&lt;span class='s'&gt;"100%"&lt;/span&gt; &lt;span class='na'&gt;height=&lt;/span&gt;&lt;span class='s'&gt;"100%"&lt;/span&gt; 
   &lt;span class='na'&gt;dataProvider=&lt;/span&gt;&lt;span class='s'&gt;"{users}"&lt;/span&gt; 
   &lt;span class='na'&gt;selectable=&lt;/span&gt;&lt;span class='s'&gt;"false"&lt;/span&gt; 
   &lt;span class='na'&gt;itemRenderer=&lt;/span&gt;&lt;span class='s'&gt;"{new ArgumentsToRendererFactory({group:this.radioGroup},UserRenderer)}"&lt;/span&gt; 
&lt;span class='nt'&gt;/&gt;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;
&lt;p&gt;In the above example, I’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;span class='nb'&gt;require&lt;/span&gt; &lt;span class='s1'&gt;'fileutils'&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;"./**/*_rev*.indd"&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;"_rev"&lt;/span&gt;&lt;span class='p'&gt;,&lt;/span&gt;&lt;span class='s2'&gt;""&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;"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;"&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&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’ve ever searched for how to do a 301 redirect in Rails, you’ve probably seen this code:&lt;/p&gt;
&lt;div class='highlight'&gt;&lt;pre&gt;&lt;span class='n'&gt;headers&lt;/span&gt;&lt;span class='o'&gt;[&lt;/span&gt;&lt;span class='s2'&gt;"Status"&lt;/span&gt;&lt;span class='o'&gt;]&lt;/span&gt; &lt;span class='o'&gt;=&lt;/span&gt; &lt;span class='s2'&gt;"301 Moved Permanently"&lt;/span&gt;
&lt;span class='n'&gt;redirect_to&lt;/span&gt; &lt;span class='s2'&gt;"http://www.domain.com/"&lt;/span&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;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;=&gt;&lt;/span&gt; &lt;span class='s2'&gt;"http://www.domain.com/"&lt;/span&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;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;=&gt;&lt;/span&gt; &lt;span class='n'&gt;url&lt;/span&gt;
&lt;span class='k'&gt;end&lt;/span&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;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;"My really long message..."&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;"My second really long message..."&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;/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;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;/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;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;"My really long message..."&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;"My second really long message..."&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;/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;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;", "&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;/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;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;/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;span class='nx'&gt;obj&lt;/span&gt;&lt;span class='p'&gt;[&lt;/span&gt;&lt;span class='s1'&gt;'key'&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='c'&gt;//key exists&lt;/span&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;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;'key'&lt;/span&gt;&lt;span class='p'&gt;]&lt;/span&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’ve introduced a few friends/classmates/coworkers to Ruby and Rails lately, and many of them have since approached me and asked “what is that colon thing in ruby?” So, I’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 “bob” 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’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;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;/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&lt;em&gt;REL&lt;/em&gt;OP&lt;em&gt;GREATER&lt;/em&gt;EQUAL into a cstring. With symbols, it’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;span class='p'&gt;{&lt;/span&gt;&lt;span class='ss'&gt;:name&lt;/span&gt; &lt;span class='o'&gt;=&gt;&lt;/span&gt; &lt;span class='s2'&gt;"Zachary"&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;=&gt;&lt;/span&gt; &lt;span class='s2'&gt;"Programmer"&lt;/span&gt;&lt;span class='p'&gt;}&lt;/span&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 “Zachary” and “Programmer”. 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’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 (”+”) 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 ”+” 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’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’s to the tradeoff made by choosing String/Symbol (Ruby) over StringBuffer/String (Java). Additionally, the unique nature of symbols has it’s own benefits when it comes to flags that were traditionally set with numerical constants.&lt;/p&gt;</content>
 </entry>
 
 
</feed>
