Brian's Site Stuff Brian is working on 2012-02-08T12:10:24+08:00 tag:www.wubo.org,2011-04-01:/atom.xml Brian Taylor el.wubo@gmail.com Doctors Visits http://brianttaylor.com/entry/6 2011-07-20T00:00:00Z <p>My Doctor's visits usually break down something like this: </p> <p>My Doctor's visits usually break down something like this: </p> <ul> <li> 99% waiting </li> <li> 0.9% in some kind of new visit induced pain </li> <li> 0.1% getting the information I came for </li> </ul> <p> Along the way there's something like a 50% probability I'll be asked to remove my pants. </p> <p> On the whole, it's not something I enjoy but having a Kindle solves 99% of it. </p> First Android Game! http://brianttaylor.com/entry/5 2011-07-05T00:00:00Z <p>Hi there. </p> <p>Hi there. </p> <p> <img src="http://brianttaylor.com/static/memmatch/bigicon.png" alt="http://brianttaylor.com/static/memmatch/bigicon.png" /> </p> <p> I've just published my first Android game. It's simple, but I'm proud of it. It's one of several (unfortunately) games named "Memory Match" in the Android store. You can either search the store for "wubo" or you can just follow <a href="https://market.android.com/details?id=org.wubo.memmatch&amp;feature=search_result">this direct link</a> and let me know what you think. </p> <p> I'm open to suggestions in the comments either here or in the market. </p> Shadow Tiles http://brianttaylor.com/entry/4 2011-04-08T00:00:00Z <p>I just finished implementing the rules for when to draw shadows on a tile and what shadows to draw. The creator of the "Planet Cute" tileset includes this very helpful guide: </p> <p>I just finished implementing the rules for when to draw shadows on a tile and what shadows to draw. The creator of the "Planet Cute" tileset includes this very helpful guide: </p> <p> <img src="http://brianttaylor.com/static/platformer/shadow-instructions.png" alt="http://brianttaylor.com/static/platformer/shadow-instructions.png" /> </p> <p> Thankfully, before I wasted too much time, I realized this was just the sort of thing that I could write a small DSL to describe. Here's my mapping to code of the image above: </p> <pre class="src src-clojure">(<span class="org-keyword">def</span> <span class="org-function-name">*shadow-types*</span> [(shadow-with <span class="org-builtin">:shadow-south-east</span> (present [1 1 1]) (absent [1 0 1])) (shadow-with <span class="org-builtin">:shadow-east</span> (present [1 0 1])) (shadow-with <span class="org-builtin">:shadow-north-east</span> (present [1 -1 1]) (absent [1 -1 0]) (absent [1 0 1])) (shadow-with <span class="org-builtin">:shadow-side-west</span> (present [0 1 -1]) (absent [0 1 0])) (shadow-with <span class="org-builtin">:shadow-south</span> (present [1 1 0])) (shadow-with <span class="org-builtin">:shadow-north</span> (present [1 -1 0])) (shadow-with <span class="org-builtin">:shadow-south-west</span> (present [1 1 -1]) (absent [1 0 -1])) (shadow-with <span class="org-builtin">:shadow-west</span> (present [1 0 -1])) (shadow-with <span class="org-builtin">:shadow-north-west</span> (present [1 -1 -1]) (absent [1 -1 0]) (absent [1 0 -1]))]) </pre> <p> And the resulting shadowed image: </p> <p> <img src="http://brianttaylor.com/static/platformer/shadow-test.png" alt="http://brianttaylor.com/static/platformer/shadow-test.png" /> </p> <p> The updated code is up on github. </p> </div> </body> </html> Starting Something New http://brianttaylor.com/entry/3 2011-04-08T00:00:00Z <p>I just created a new repository up on GitHub. </p> <p>I just created a new repository up on GitHub. </p> <p> <a href="https://github.com/netguy204/platformer">https://github.com/netguy204/platformer</a> </p> <p> My current vision is to create a game with a play style somewhat like a classic platformer. I'm doing that because I think I can achieve the basic rendering/controls/collisions pretty quickly and can focus on what I really want to do: Physics! </p> <p> Ah, the real motivation. </p> <p> I recently purchased the excellent <a href="http://www.amazon.com/gp/product/0123819768/ref=as_li_qf_sp_asin_il_tl?ie=UTF8&amp;tag=brisstu-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0123819768">Game Physics Engine Development</a> by Ian Millington and I want to make a sandbox that I can use to play with the things that I'm learning. </p> <p> I'm also using the very handy "Planet Cute" tile set from lostgarden. </p> <p> <a href="http://www.lostgarden.com/2007/05/dancs-miraculously-flexible-game.html">http://www.lostgarden.com/2007/05/dancs-miraculously-flexible-game.html</a> </p> <p> All I have now is a renderer. Naturally (given my current obsession) I'm working in closure. Here's a level definition: </p> <pre class="src src-clojure">(<span class="org-keyword">def</span> <span class="org-function-name">*scene*</span> [[[<span class="org-builtin">:stone</span> <span class="org-builtin">:stone</span> <span class="org-builtin">:brown</span>] [<span class="org-builtin">:stone</span> <span class="org-builtin">:brown</span> <span class="org-builtin">:brown</span>] [<span class="org-builtin">:stone</span> <span class="org-builtin">:dirt</span> <span class="org-builtin">:dirt</span>]] [[<span class="org-builtin">:none</span> <span class="org-builtin">:none</span> <span class="org-builtin">:chest</span>] [<span class="org-builtin">:none</span> <span class="org-builtin">:none</span> <span class="org-builtin">:none</span>] [<span class="org-builtin">:none</span> <span class="org-builtin">:dirt</span> <span class="org-builtin">:dirt</span>]]]) </pre> <p> And here's what that looks like rendered: </p> <p> <img src="http://brianttaylor.com/static/platformer/first.png" alt="http://brianttaylor.com/static/platformer/first.png" /> </p> <p> I need to add some shadows so that the height of one tile relative to another is less ambiguous. </p> </div> </body> </html> Porting to Clojure http://brianttaylor.com/entry/2 2011-04-01T00:00:00Z <p>I've been porting my org-mode blogging system to Clojure from Rails. So far, I've been pretty blown away by how fantastically-good the tools for doing web-development in Clojure are! </p> <p>I've been porting my org-mode blogging system to Clojure from Rails. So far, I've been pretty blown away by how fantastically-good the tools for doing web-development in Clojure are! </p> <p> For doing webdev in Clojure, I've finally found the secret ingredients: Enlive and Moustache. Enlive is a really solid template library that lets you extract, mutate, and re-assemble chunks of HTML primordial ooze into data-rich goodness. </p> <div id="outline-container-1" class="outline-3"> <h3 id="sec-1">Enlive </h3> <div class="outline-text-3" id="text-1"> <p> <a href="https://github.com/cgrand/enlive">https://github.com/cgrand/enlive</a> </p> <p> For example, the code generating the page you're looking at right now is: </p> <pre class="src src-clojure">(deftemplate page-template *page* [{<span class="org-builtin">:keys</span> [title blurb body]}] [<span class="org-builtin">:title</span>] (maybe-content title) [<span class="org-builtin">:#page_title</span>] (maybe-content title) [<span class="org-builtin">:#about</span> <span class="org-builtin">:p</span>] (maybe-content blurb) [<span class="org-builtin">:#buttons</span>] (content (<span class="org-builtin">map</span> button-model *buttons*)) [<span class="org-builtin">:#page_content</span>] (content body)) </pre> <p> And the HTML looks like: </p> <pre class="src src-html"><span class="org-comment-delimiter">&lt;!-- </span><span class="org-comment">just a snippet </span><span class="org-comment-delimiter">--&gt;</span> &lt;<span class="org-function-name">div</span> <span class="org-variable-name">id</span>=<span class="org-string">"buttons"</span>&gt; &lt;<span class="org-function-name">a</span> <span class="org-variable-name">class</span>=<span class="org-string">"button"</span> <span class="org-variable-name">href</span>=<span class="org-string">"/"</span>&gt;&lt;<span class="org-function-name">span</span>&gt;Projects&lt;/<span class="org-function-name">span</span>&gt;&lt;/<span class="org-function-name">a</span>&gt; &lt;<span class="org-function-name">a</span> <span class="org-variable-name">class</span>=<span class="org-string">"button"</span> <span class="org-variable-name">href</span>=<span class="org-string">"/"</span>&gt;&lt;<span class="org-function-name">span</span>&gt;Blog&lt;/<span class="org-function-name">span</span>&gt;&lt;/<span class="org-function-name">a</span>&gt; &lt;<span class="org-function-name">a</span> <span class="org-variable-name">class</span>=<span class="org-string">"button"</span> <span class="org-variable-name">href</span>=<span class="org-string">"/"</span>&gt;&lt;<span class="org-function-name">span</span>&gt;Github&lt;/<span class="org-function-name">span</span>&gt;&lt;/<span class="org-function-name">a</span>&gt; &lt;/<span class="org-function-name">div</span>&gt; &lt;<span class="org-function-name">div</span> <span class="org-variable-name">id</span>=<span class="org-string">"page_content"</span>&gt; &lt;<span class="org-function-name">h2</span> <span class="org-variable-name">class</span>=<span class="org-string">"post_title"</span>&gt;<span class="org-underline"><span class="org-bold-italic">The Title</span></span>&lt;/<span class="org-function-name">h2</span>&gt; &lt;<span class="org-function-name">div</span> <span class="org-variable-name">class</span>=<span class="org-string">"post_timestamp"</span>&gt;posting time&lt;/<span class="org-function-name">div</span>&gt; &lt;<span class="org-function-name">div</span> <span class="org-variable-name">class</span>=<span class="org-string">"post_body"</span>&gt; &lt;/<span class="org-function-name">div</span>&gt; &lt;/<span class="org-function-name">div</span>&gt; <span class="org-comment-delimiter">&lt;!-- </span><span class="org-comment">just a snippet </span><span class="org-comment-delimiter">--&gt;</span> </pre> <p> Compare those two chunks of code and think CSS. Enlive is letting me pick out chunks of the HTML using something that looks very much like a CSS selector, </p> <pre class="src src-clojure">[<span class="org-builtin">:#page_content</span>] (content body) </pre> <p> and then replace its content with something else and re-insert it into the document. </p> <p> As another neat example, here's the snippet of Clojure that's formatting each post itself: </p> <pre class="src src-clojure">(<span class="org-keyword">def</span> <span class="org-function-name">*post-sel*</span> [<span class="org-builtin">:#page_content</span>]) (defsnippet post-model *page* *post-sel* [{<span class="org-builtin">:keys</span> [title timestamp body] <span class="org-builtin">:or</span> {<span class="org-builtin">:timestamp</span> <span class="org-string">""</span>}}] [<span class="org-builtin">:.post_timestamp</span>] (content timestamp) [<span class="org-builtin">:.post_title</span>] (content title) [<span class="org-builtin">:.post_body</span>] (html-content body)) </pre> <p> This extracts just the portion of the page matched by "#page<sub>content</sub>" and replaces the timestamp, title, and body using its parameters. </p> <p> Enough of that. If you want to know more, check out the very excellent enlive-tutorial. </p> <p> <a href="https://github.com/swannodette/enlive-tutorial/">https://github.com/swannodette/enlive-tutorial/</a> </p> <p> This was virtually 100% of my reference material for Enlive while building this site. </p> </div> </div> <div id="outline-container-2" class="outline-3"> <h3 id="sec-2">Moustache </h3> <div class="outline-text-3" id="text-2"> <p> The other bit of secret-sauce is Moustache. </p> <p> <a href="https://github.com/cgrand/moustache">https://github.com/cgrand/moustache</a> </p> <p> This is a no-nonsense minimalist system for routing HTTP requests to appropriate handlers. Again, for the site you're looking at now, we have the code: </p> <pre class="src src-clojure">(<span class="org-keyword">def</span> <span class="org-function-name">routes</span> (app wrap-params [<span class="org-string">""</span>] (with-template (page-template {<span class="org-builtin">:title</span> <span class="org-string">"Brian's Site"</span> <span class="org-builtin">:body</span> (<span class="org-builtin">map</span> post-model (all-posts))})) [<span class="org-string">"entry"</span> id] (with-template (<span class="org-keyword">let</span> [post (get-post-id id)] (page-template {<span class="org-builtin">:title</span> (<span class="org-builtin">:title</span> post) <span class="org-builtin">:body</span> (post-model post)}))) [<span class="org-string">"atom.xml"</span>] (with-template (atom-template (atom-date) (<span class="org-builtin">map</span> atom-storify (all-posts)))) [<span class="org-string">"post"</span>] {<span class="org-builtin">:post</span> new-post})) </pre> <p> The coolest (in my opinion) of those routes is the second </p> <pre class="src src-clojure">[<span class="org-string">"entry"</span> id] (with-template (<span class="org-keyword">let</span> [post (get-post-id id)] (page-template {<span class="org-builtin">:title</span> (<span class="org-builtin">:title</span> post) <span class="org-builtin">:body</span> (post-model post)}))) </pre> <p> This route would match a request for "/entry/1" and would bind the "1" to id before executing the code next to it. It sure is nice to be working in a language with a proper macro system again. Sometimes Java makes me so sad. </p> </div> </div> <div id="outline-container-3" class="outline-3"> <h3 id="sec-3">Notes </h3> <div class="outline-text-3" id="text-3"> <p> Here's a handful of other links that I found useful while going through this process: </p><ul> <li><a href="http://mmcgrana.github.com/2010/07/develop-deploy-clojure-web-applications.html">http://mmcgrana.github.com/2010/07/develop-deploy-clojure-web-applications.html</a> </li> <li><a href="http://briancarper.net/blog/510/deploying-clojure-websites">http://briancarper.net/blog/510/deploying-clojure-websites</a> </li> <li><a href="http://cleancode.se/2011/01/04/getting-started-with-moustache-and-enlive.html">http://cleancode.se/2011/01/04/getting-started-with-moustache-and-enlive.html</a> </li> <li><a href="https://github.com/LauJensen/bestinclass.dk/">https://github.com/LauJensen/bestinclass.dk/</a> </li> <li><a href="http://www.bestinclass.dk/index.clj/2010/05/refresh-your-cache--best-in-class-has-been-baked.html">http://www.bestinclass.dk/index.clj/2010/05/refresh-your-cache&ndash;best-in-class-has-been-baked.html</a> </li> </ul> <p> Well, that's enough of my excited spouting. Hopefully this inspires someone to consider Clojure (esp. with Enlive and Moustache) for their next webapp experiment. I'm out. </p></div> </div> </div> </body> </html> Blogging in Org-Mode http://brianttaylor.com/entry/1 2011-02-13T00:00:00Z <p>I'm a fledgling user of the very excellent emacs org-mode. I'm finding that I gravitate to it naturally for capturing everything from quick TODO items to detailed notes and plans. It's amazing how a simple outline is really most of what I need to organize my day. </p> <p>I'm a fledgling user of the very excellent emacs org-mode. I'm finding that I gravitate to it naturally for capturing everything from quick TODO items to detailed notes and plans. It's amazing how a simple outline is really most of what I need to organize my day. </p> <p> I've been dabbling in elisp lately trying to build some way to post some of those thoughts to something resembling a blog. Here's what I came up with: </p> <p> This code extracts the org sub-tree that contains point and splits it into the title and body. Then it converts the body to HTML using org-mode's HTML export feature. </p> <pre class="src src-emacs-lisp">(<span class="org-keyword">defun</span> <span class="org-function-name">orgblog-post-file</span> () (interactive) (<span class="org-keyword">save-excursion</span> (<span class="org-keyword">let</span> (title-beg title-end body-beg body-end title body) (setq title-beg (<span class="org-keyword">progn</span> (org-back-to-heading) (point))) (setq title-end (<span class="org-keyword">progn</span> (end-of-line) (point))) (setq body-beg (<span class="org-keyword">progn</span> (beginning-of-line 2) (point))) (setq body-end (<span class="org-keyword">progn</span> (org-end-of-subtree) (point))) (setq title (buffer-substring-no-properties title-beg title-end)) (setq body (org-export-region-as-html body-beg body-end t 'string)) (orgblog-post orgblog-post-url (list (cons <span class="org-string">"title"</span> title) (cons <span class="org-string">"body"</span> body)))))) </pre> <p> Then this accomplishes the fairly simple task of building an HTTP POST request and passing those parameters up to the brain-dead simple web-api I slapped onto my blog. </p> <pre class="src src-emacs-lisp">(<span class="org-keyword">defun</span> <span class="org-function-name">orgblog-post</span> (url args) <span class="org-doc">"send ARGS to URL as a post request"</span> (<span class="org-keyword">let</span> ((url-request-method <span class="org-string">"POST"</span>) (url-request-extra-headers '((<span class="org-string">"Content-Type"</span> . <span class="org-string">"application/x-www-form-urlencoded"</span>) (<span class="org-string">"Accept"</span> . <span class="org-string">"application/json"</span>) (<span class="org-string">"Connection"</span> . <span class="org-string">"close"</span>))) (url-request-data (mapconcat (<span class="org-keyword">lambda</span> (arg) (concat (url-hexify-string (car arg)) <span class="org-string">"="</span> (url-hexify-string (cdr arg)))) args <span class="org-string">"&amp;"</span>))) (url-retrieve url 'orgblog-post-response))) </pre> <p> I'm sure there are far better ways to do this but this meets my needs and means that I can finally make blog posts without the distraction and frustration of leaving the work-environment I am most comfortable in. </p> </div> </body> </html>