{"id":198,"date":"2010-09-25T01:13:09","date_gmt":"2010-09-25T04:13:09","guid":{"rendered":"http:\/\/wahlers.com.br\/claus\/blog\/?p=198"},"modified":"2010-09-30T15:47:44","modified_gmt":"2010-09-30T18:47:44","slug":"my-silly-gist-collection","status":"publish","type":"post","link":"http:\/\/wahlers.com.br\/claus\/blog\/my-silly-gist-collection\/","title":{"rendered":"My Silly Gist Collection"},"content":{"rendered":"<p>I&#8217;ve been quite busy lately on both client and personal projects (can&#8217;t talk about the former, other than it being a big ass Flex 4 enterprise application i&#8217;ve been working on for the fine folks at Powerflasher; and it&#8217;s too early to talk about the latter.. stay tuned).<\/p>\n<p>In the last few weeks i silently released random little experiments on Gist &#8211; mostly fallout from personal projects of mine. Nothing super impressive, all pretty rough, but i thought some of you might be interested.<\/p>\n<p><!--more--><\/p>\n<p>So here it is, my silly Gist collection.<\/p>\n<p><strong>1. Show the compile date of a SWF<\/strong><\/p>\n<p>You are developing a Flex application. You frequently publish the application to a staging server for QA to test. You want to ensure that QA always tests the latest version of your application, because aggressive cache settings in browser or proxy servers may result in QA seeing outdated, cached SWFs.<\/p>\n<p>To make sure that QA looks at the latest version of the SWF, you can have the SWF inspect itself and search for a <code>ProductInfo<\/code> tag, which contains the compile date (<code>ProductInfo<\/code> is an undocumented SWF tag, i explain it in more detail <a href=\"http:\/\/wahlers.com.br\/claus\/blog\/undocumented-swf-tags-written-by-mxmlc\/\">here<\/a>). You can then have your Flex application display this date in order to be able to verify that QA sees the latest version.<\/p>\n<p>Here&#8217;s how to do that:<\/p>\n<p><a href=\"http:\/\/gist.github.com\/594367\">http:\/\/gist.github.com\/594367<\/a><\/p>\n<p><strong>2. Bin Packer<\/strong><\/p>\n<p>For a project i am working on, i needed an algorithm to fit as many randomly sized rectangles as possible into a given, larger rectangle (the bin). Turned out, there are a lot of different approaches out there (unfortunately none of the more elaborate ones is much better than O(argh) &#8211; the more rectangles you try to fit, the slower the algorithms get).<\/p>\n<p>I found one resource particularly helpful: <a href=\"http:\/\/clb.demon.fi\/\">clb.demon.fi<\/a> explains some selected Bin Packer algorithms in great detail, and provides many links to others. They also provide a <a href=\"http:\/\/clb.demon.fi\/projects\/even-more-rectangle-bin-packing\">C implementation<\/a> for a bunch of algorithms.<\/p>\n<p>I ported their Max Rect Bin Packer implementation to ActionScript 3, and added the option to have it execute asynchronously:<\/p>\n<p><a href=\"http:\/\/gist.github.com\/543176\">http:\/\/gist.github.com\/543176<\/a><\/p>\n<p>Demo (click to restart):<\/p>\n<p>[SWF]http:\/\/wahlers.com.br\/claus\/blog\/wp-content\/uploads\/BinPacker.swf, 400, 256[\/SWF]<\/p>\n<p><strong>3. De Casteljau: Move a point along a quadratic bezier<\/strong><\/p>\n<p>Recently i needed an algorithm to split a quadratic bezier curve in two. The solution was <a href=\"http:\/\/www.cs.mtu.edu\/~shene\/COURSES\/cs3621\/NOTES\/spline\/Bezier\/de-casteljau.html\">De Casteljau&#8217;s algorithm<\/a>.<\/p>\n<p><a href=\"http:\/\/gist.github.com\/524163\">http:\/\/gist.github.com\/524163<\/a><\/p>\n<p>Demo (click to restart):<\/p>\n<p>[SWF]http:\/\/wahlers.com.br\/claus\/blog\/wp-content\/uploads\/DeCasteljau.swf, 400, 400[\/SWF]<\/p>\n<p><strong>4. Silly font glyph plotter<\/strong><\/p>\n<p>This Flash movie parses itself, grabs the first glyph of an embedded font and draws it on screen (uses <a href=\"http:\/\/github.com\/claus\/as3swf\">as3swf<\/a> to parse itself, so you need <a href=\"http:\/\/github.com\/claus\/as3swf\/tree\/master\/bin\/\">as3swf.swc<\/a>). Kinda silly.<\/p>\n<p><a href=\"http:\/\/gist.github.com\/523033\">http:\/\/gist.github.com\/523033<\/a><\/p>\n<p>Demo:<\/p>\n<p>[SWF]http:\/\/wahlers.com.br\/claus\/blog\/wp-content\/uploads\/FontGlyph.swf, 400, 420[\/SWF]<\/p>\n<p><strong>5. Convert HTML to XML and use E4X to access DOM (AIR required)<\/strong><\/p>\n<p>Here&#8217;s a little utility function i wrote. <a href=\"http:\/\/github.com\/claus\/as3utils\/blob\/master\/src\/com\/codeazur\/utils\/XMLUtil.as\"><code>XMLUtils.jsDomToE4X()<\/code><\/a> converts HTML loaded via HTMLLoader (or the HTML DOM to be exact) into an AS3 XML object, so you can use simple E4X queries to scrape a HTML page. Evil.<\/p>\n<p>And here&#8217;s the source code for a minimalistic web browser built upon the Adobe AIR Flex HTML component, that dumps out the URLs of SWFs embedded into the loaded HTML document.<\/p>\n<p>The basic idea:<\/p>\n<pre><code>var x:XML = XMLUtil.jsDomToE4X(htmlControl.domWindow.document);\r\nvar ns:Namespace = Namespace(\"http:\/\/www.w3.org\/1999\/xhtml\");\r\nvar embeds:XMLList = <strong>x..ns::embed.@src<\/strong>;<\/code><\/pre>\n<p>The full source:<\/p>\n<p><a href=\"http:\/\/gist.github.com\/456130\">http:\/\/gist.github.com\/456130<\/a><\/p>\n<p><strong>That&#8217;s all, folks!<\/strong><\/p>\n<p>I hope you enjoyed my silly little collection. Please also check out my &#8220;serious&#8221; work on <a href=\"http:\/\/github.com\/claus\">GitHub<\/a>, and feel free to <a href=\"http:\/\/twitter.com\/cwahlers\">follow me<\/a> on Twitter.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been quite busy lately on both client and personal projects (can&#8217;t talk about the former, other than it being a big ass Flex 4 enterprise application i&#8217;ve been working on for the fine folks at Powerflasher; and it&#8217;s too &hellip; <a href=\"http:\/\/wahlers.com.br\/claus\/blog\/my-silly-gist-collection\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,8,4,12,3],"tags":[],"class_list":["post-198","post","type-post","status-publish","format-standard","hentry","category-air","category-as3","category-flash","category-swf","category-webdev"],"_links":{"self":[{"href":"http:\/\/wahlers.com.br\/claus\/blog\/wp-json\/wp\/v2\/posts\/198","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/wahlers.com.br\/claus\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/wahlers.com.br\/claus\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/wahlers.com.br\/claus\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/wahlers.com.br\/claus\/blog\/wp-json\/wp\/v2\/comments?post=198"}],"version-history":[{"count":25,"href":"http:\/\/wahlers.com.br\/claus\/blog\/wp-json\/wp\/v2\/posts\/198\/revisions"}],"predecessor-version":[{"id":235,"href":"http:\/\/wahlers.com.br\/claus\/blog\/wp-json\/wp\/v2\/posts\/198\/revisions\/235"}],"wp:attachment":[{"href":"http:\/\/wahlers.com.br\/claus\/blog\/wp-json\/wp\/v2\/media?parent=198"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/wahlers.com.br\/claus\/blog\/wp-json\/wp\/v2\/categories?post=198"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/wahlers.com.br\/claus\/blog\/wp-json\/wp\/v2\/tags?post=198"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}