<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 <title>Whoahbot!</title>
 <link href="http://whoahbot.com/atom.xml" rel="self"/>
 <link href="http://whoahbot.com/"/>
 <updated>2011-08-20T20:32:05-07:00</updated>
 <id>http://whoahbot.com/</id>
 <author>
   <name>Dan Herrera</name>
   <email>whoahbot@gmail.com</email>
 </author>
 
 
 <entry>
   <title>6502, assembly and you. Part 3</title>
   <link href="http://whoahbot.com/2011/08/20/6502_assembly_and_you_part_3.html"/>
   <updated>2011-08-20T00:00:00-07:00</updated>
   <id>http://whoahbot.com/2011/08/20/6502_assembly_and_you_part_3</id>
   <content type="html">&lt;h1&gt;6502, assembly and you. Part 3&lt;/h1&gt;
&lt;p&gt;Before I begin, let me say that while programming for the 6502, one must surely consider the following musical choices&lt;br /&gt;
to be at a premium: &lt;a href=&quot;http://www.souljazzrecords.co.uk/releases/?id=114&quot;&gt;Studio One Scorcher&lt;/a&gt;, or at the &lt;br /&gt;
very least: &lt;a href=&quot;http://en.wikipedia.org/wiki/The_Budos_Band&quot;&gt;Budos Band II&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;At any rate! If you have been &lt;a href=&quot;/2011/08/12/6502_assembly_and_you.html&quot;&gt;following&lt;/a&gt; &lt;a href=&quot;/2011/08/13/6502_assembly_and_you_part_2.html&quot;&gt;along&lt;/a&gt;, you surely have guessed that the missing instruction from the quiz in part 2 is of course &lt;span class=&quot;caps&quot;&gt;TXA&lt;/span&gt;!&lt;/p&gt;
&lt;p&gt;Once, again, our cast of characters:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.6502asm.com/&quot;&gt;The Sim&lt;/a&gt;, &lt;a href=&quot;http://www.obelisk.demon.co.uk/6502/&quot;&gt;The Book&lt;/a&gt;, &lt;a href=&quot;http://www.masswerk.at/6502/6502_instruction_set.html&quot;&gt;The Reference&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;And on to the plot. This is act 3, the climax and then the dénouement!&lt;/p&gt;
&lt;p&gt;Processor status register!&lt;/p&gt;
&lt;p&gt;On our happy little substrate of silica, we have the following flags that are stored in the processor status register:&lt;/p&gt;
&lt;pre&gt;
bit   7                           0
    +---+---+---+---+---+---+---+---+
    | N | V |   | B | D | I | Z | C |
    +---+---+---+---+---+---+---+---+
&lt;/pre&gt;
&lt;p&gt;Instructions to the processor can set these flags after an instruction to indicate things like whether the result of the last instruction (dec, inc, load) was zero. These all have their use, but we will set careful study for the moment upon the Z flag.&lt;/p&gt;
&lt;p&gt;By the by, if you haven&amp;#8217;t read &lt;a href=&quot;http://www.amazon.com/Zero-Biography-Dangerous-Charles-Seife/dp/0140296476&quot;&gt;Zero: The Biography of a Dangerous Idea&lt;/a&gt;, you most certainly would enjoy it&amp;#8230; By the by and by, if I lent you my copy of that book, could you please return it?&lt;/p&gt;
&lt;p&gt;Avast! Processor status flags, like our friend Zero are quite handy for control flow, as in the following example:&lt;/p&gt;
&lt;pre&gt;
LDA #01
LDX #05
jump:
STA $01FF,x
DEX
BNE jump
&lt;/pre&gt;
&lt;p&gt;Pray, notice carefully that we are no longer jumping forever! There is a new sherrif in town and her name is &lt;span class=&quot;caps&quot;&gt;BNE&lt;/span&gt;. Also note carefully the section of the reference that speaks volumes of the &lt;span class=&quot;caps&quot;&gt;DEX&lt;/span&gt; instruction:&lt;/p&gt;
&lt;pre&gt;
DEX  Decrement Index X by One

     X - 1 -&amp;gt; X                       N Z C I D V
                                      + + - - - -

     addressing    assembler    opc  bytes  cyles
     --------------------------------------------
     implied       DEC           CA    1     2

&lt;/pre&gt;
&lt;p&gt;The two plusses there indicate that this instruction can set the N or Z flags in the processor status register, in this case, decrementing X during the last run will set the Z flag of the processor status register, and the &lt;span class=&quot;caps&quot;&gt;BNE&lt;/span&gt; instruction checks to see if that flag is set before jumping back into he subroutine.&lt;/p&gt;
&lt;p&gt;Gifted with this new information, the careful bit manipulation of the skilled assembly alchemist becomes clear, and much more interesting operations present themselves.&lt;/p&gt;
&lt;p&gt;Do be careful when cooking with this recipe! Never forget that unless you are wary, another operation may have set that processor status flag much earlier in your program, and it may not be safe to use unless cleared beforehand.&lt;/p&gt;
&lt;p&gt;Thank you, dear reader. I bid you the fondest of farewells for now. I may continue with this series, if my mad education in this realm continues, but I shall always keep fond memories of our times together and the bits we flipped.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>6502, assembly and you. Part 2</title>
   <link href="http://whoahbot.com/2011/08/13/6502_assembly_and_you_part_2.html"/>
   <updated>2011-08-13T00:00:00-07:00</updated>
   <id>http://whoahbot.com/2011/08/13/6502_assembly_and_you_part_2</id>
   <content type="html">&lt;p&gt;Now, you&amp;#8217;ve heard the soulful sounds of &lt;a href=&quot;/2011/08/12/6502_assembly_and_you.html&quot;&gt;part one&lt;/a&gt;, this is part two. Are you ready?&lt;/p&gt;
&lt;p&gt;Introducing the players:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.6502asm.com/&quot;&gt;The Sim&lt;/a&gt;, &lt;a href=&quot;http://www.obelisk.demon.co.uk/6502/&quot;&gt;The Book&lt;/a&gt;, &lt;a href=&quot;http://www.masswerk.at/6502/6502_instruction_set.html&quot;&gt;The Reference&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The Sim is a wonder in itself, you&amp;#8217;ll want that open in another tab while you read on, dear friends. If you want to be taken back to the heady days of 8-bit gaming, load up &amp;#8220;Adventure&amp;#8221; from the examples menu. (Use &lt;span class=&quot;caps&quot;&gt;WSAD&lt;/span&gt; to move).&lt;/p&gt;
&lt;p&gt;In our happy little 8 bit wonder, we have several things to keep track of.&lt;/p&gt;
&lt;p&gt;There are a total of three general use registers:&lt;/p&gt;
&lt;p&gt;Register X&lt;br /&gt;
Register Y&lt;br /&gt;
The Accumulator&lt;/p&gt;
&lt;p&gt;The Accumulator handles all arithmetic and logic.&lt;br /&gt;
X and Y are general purpose registers that hold one byte (8 bits) of data. By the by, this is a joke that should be on the inside of&lt;br /&gt;
a laffy taffy wrapper:&lt;/p&gt;
&lt;p&gt;Q: What do you call one half of a byte?&lt;br /&gt;
A: A &lt;a href=&quot;http://www.nibblemagazine.com/&quot;&gt;Nibble&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I&amp;#8217;m sorry, our friend mentioned in part one had used the word &amp;#8216;nibble&amp;#8217; so many times that it wasn&amp;#8217;t funny to him anymore, but it made me laugh. Onward!&lt;/p&gt;
&lt;p&gt;You can load X and Y, and A with a value directly:&lt;/p&gt;
&lt;pre&gt;
LDA #02 ; Loads the value 2 into the accumulator
LDX #00 ; Loads the value 0 into register X
&lt;/pre&gt;
&lt;p&gt;Now then, we have two values that are loaded, one that we can use as a color (2 is red in this sim), we&amp;#8217;d like to store that color in a memory address. We do so, like so:&lt;/p&gt;
&lt;pre&gt;
STA $0200 // Store the value of the accumulator in memory address $0200
&lt;/pre&gt;
&lt;p&gt;Compile that, and run it, and you should have a little red &amp;#8216;pixel&amp;#8217; on the right. Keep in mind that this simulator is visually showing you the contents of memory as a color in that block.&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;caps&quot;&gt;STA&lt;/span&gt; can also take a register as an offset, thusly:&lt;/p&gt;
&lt;pre&gt;
STA $0200,x ; Store the value of the accumulator in memory address $0200 plus an offset of the value in the X register.
&lt;/pre&gt;
&lt;p&gt;Yes, yes, all very useful, but we need a looping construct! Enter &lt;span class=&quot;caps&quot;&gt;JMP&lt;/span&gt;.&lt;/p&gt;
&lt;pre&gt;
LDA #02
LDX #00
paint: ; Make a new subroutine called 'paint'
STA $0200,x
INX
JMP paint ; jump back to the subroutine called 'paint'
&lt;/pre&gt;
&lt;p&gt;This happy little 6502 program will continue to paint the town red. See how proudly it paints? &lt;a href=&quot;http://www.youtube.com/watch?v=U21OAkO3xj4&quot;&gt;Jump Forever!&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Red is nice, but there is a way to make the program paint pretty stripes instead using only one new instruction. See if you can figure out how. You&amp;#8217;ll need just one other instruction we haven&amp;#8217;t used before in your paint subroutine. &lt;a href=&quot;http://www.masswerk.at/6502/6502_instruction_set.html&quot;&gt;Here is&lt;/a&gt; the reference again for your perusing pleasure.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/stripey.png&quot;/&gt;&lt;/p&gt;
&lt;p&gt;Part 3 will cover processor flags, and what amazing possibilities await you armed with those tools!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>6502, assembly and you. Part 1</title>
   <link href="http://whoahbot.com/2011/08/12/6502_assembly_and_you.html"/>
   <updated>2011-08-12T00:00:00-07:00</updated>
   <id>http://whoahbot.com/2011/08/12/6502_assembly_and_you</id>
   <content type="html">&lt;h1&gt;6502, assembly and you. Part 1&lt;/h1&gt;
&lt;p&gt;Greetings Program!&lt;/p&gt;
&lt;p&gt;A friend of mine is quite the computer historian, spinning grand tales&lt;br /&gt;
of old silicon, and the heady days of computing in the 1970&amp;#8217;s. I&lt;br /&gt;
should more properly introduce him as a caretaker of knowledge. It&amp;#8217;s&lt;br /&gt;
difficult to speak to him on any subject and not have him surprise you&lt;br /&gt;
with something you didn&amp;#8217;t know on the matter.&lt;/p&gt;
&lt;p&gt;At any rate, on his most recent visit to my place of employ, he had a&lt;br /&gt;
mischevious grin on his face when he arrived. When probed further on&lt;br /&gt;
the source of the twinkling in his eye, he said that he had decided it&lt;br /&gt;
was time for us to learn assembly!&lt;/p&gt;
&lt;p&gt;&amp;#8220;Not just any assembly, either.&amp;#8221; He continued, &amp;#8220;This is 1970&amp;#8217;s&lt;br /&gt;
stuff, 8 bit processing with the 6502.&amp;#8221;&lt;/p&gt;
&lt;p&gt;Surely you recognize the 6502? No? Neither did I. My archival friend&lt;br /&gt;
did enlighten us:&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://en.wikipedia.org/wiki/MOS_Technology_6502&quot; /&gt;&lt;img
src=&quot;http://upload.wikimedia.org/wikipedia/commons/4/49/MOS_6502AD_4585_top.jpg&quot;
style=&quot;width:200px;&quot;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;At the time, the 6800 was the top dog of the day, but it&amp;#8217;s pricetag of $300&lt;br /&gt;
made it the purvey of kings and large companies.&lt;/p&gt;
&lt;p&gt;An intrepid lad named Chuck Peddle did try to Peddle the 6800 to&lt;br /&gt;
gentlefolk of lesser means, but their rejoinder was always the&lt;br /&gt;
same. They would love such a processor, but only at a much more modest price.&lt;/p&gt;
&lt;p&gt;Peddle began to design such a substrate of silica, and&lt;br /&gt;
brought his idea to the management team at Motorola. They laughed into&lt;br /&gt;
their cognac at his suggestion that they should make a processor,&lt;br /&gt;
since their flagship product had unfurled their flag so well.&lt;/p&gt;
&lt;p&gt;On to &lt;span class=&quot;caps&quot;&gt;MOS&lt;/span&gt; flew most of the design team at Motorola, en masse! Where&lt;br /&gt;
they completed work on the 6501, a totally new design with a sultry price tag,&lt;br /&gt;
and pin-compatible with the 6800 to boot!&lt;/p&gt;
&lt;p&gt;The management team at Motorola sputtered and spewed black clouds from&lt;br /&gt;
their havana cigars, and sued at once! And so, our modest friend the 6502&lt;br /&gt;
was made, and made &amp;#8220;Lawsuit Compatible&amp;#8221;.&lt;/p&gt;
&lt;p&gt;From this chip sprung many new computers of which I&amp;#8217;m sure you are&lt;br /&gt;
familiar with: the Apple ][, the &lt;span class=&quot;caps&quot;&gt;NES&lt;/span&gt;, the Commodore &lt;span class=&quot;caps&quot;&gt;VIC&lt;/span&gt;-20, the Commodore 64,&lt;br /&gt;
and your old friend, Atari 2600.&lt;/p&gt;
&lt;p&gt;Click the chip to read more of this fascinating tale, and adieu for&lt;br /&gt;
now, but I will post more this weekend on the nature of programming&lt;br /&gt;
the 8-bit beast and all that I have learned from our friend.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;/2011/08/13/6502_assembly_and_you_part_2.html&quot;&gt;Part two&lt;/a&gt;, are you ready?&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>In thirty days</title>
   <link href="http://whoahbot.com/2009/08/25/thirty_days.html"/>
   <updated>2009-08-25T00:00:00-07:00</updated>
   <id>http://whoahbot.com/2009/08/25/thirty_days</id>
   <content type="html">&lt;h1&gt;In thirty days&lt;/h1&gt;
&lt;p&gt;My Lords, Ladies and Gentlemen:&lt;/p&gt;
&lt;p&gt;Birthing an idea is such a strange and wonderful process.&lt;/p&gt;
&lt;p&gt;A while back, I was totally consumed over by something someone said in an interview.  I can&amp;#8217;t remember who it was that said it, although I thought it was one of the &lt;a href=&quot;http://github.com&quot;&gt;Github&lt;/a&gt; crew. (Please leave me a comment if you can find the source).  The premise is that if you have an idea, you should put it away for thirty days.  If you come back to your idea and thirty days and it&amp;#8217;s still a great idea, you should do it.&lt;/p&gt;
&lt;p&gt;I often times go through really slow periods of creativity where I feel uninspired to do anything.  I hardly write any of my ideas down.  I wanted to create something that would help me through these times when I&amp;#8217;m uninspired.  An idea, buried carefully in soft peat for a month to see if it will germinate.&lt;/p&gt;
&lt;p&gt;I also love weekend projects, the whirling energetic emergent pattern of colors and code and ideas.  Idea to finished product in days.  It was also a really great way to play with the Twitter &lt;span class=&quot;caps&quot;&gt;API&lt;/span&gt;.  &lt;a href=&quot;http://github.com/jnunemaker/twitter&quot;&gt;John Nunemaker&amp;#8217;s twitter gem&lt;/a&gt; made Twitter and OAuth painless, once you conceptually understand how things work.&lt;/p&gt;
&lt;p&gt;Also, if you haven&amp;#8217;t checked out &lt;a href=&quot;http://heroku.com&quot;&gt;Heroku&lt;/a&gt;, you should.  Heroku was instrumental in being able to develop and publish an idea in a weekend.&lt;/p&gt;
&lt;p&gt;So the finished concept is this.  You go to &lt;a href=&quot;http://inthirtydays.heroku.com/&quot;&gt;In Thirty Days&lt;/a&gt; and stash your idea.  In thirty days, an automated whoah-bot will DM the idea back to you on Twitter.&lt;/p&gt;
&lt;p&gt;Please drop me a line if you find it useful, or if you have some feedback at: whoahbot (at) gmail (dot) com&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>(((((Clojure))))))</title>
   <link href="http://whoahbot.com/2009/08/20/clojure-functional-programming-and-perverts.html"/>
   <updated>2009-08-20T00:00:00-07:00</updated>
   <id>http://whoahbot.com/2009/08/20/clojure-functional-programming-and-perverts</id>
   <content type="html">&lt;h1&gt;(((((Clojure))))))&lt;/h1&gt;
&lt;p&gt;&lt;a href=&quot;http://clojure.org/&quot;&gt;Clojure&lt;/a&gt; is an accessible funcitonal programming language, with it&amp;#8217;s paranthetical tendrils rooted in the jars of Java.  It&amp;#8217;s full of arcane goodness and (secrets (within secrets (within secrets))).  Yes, indeed, a &lt;a href=&quot;http://en.wikipedia.org/wiki/Lisp_%28programming_language%29&quot;&gt;Lisp&lt;/a&gt; dialect is this.&lt;/p&gt;
&lt;p&gt;It&amp;#8217;s fun to peer through time to speak a vernacular first uttered in 1958, my own personal journey facilitated greatly by the most excellent &lt;a href=&quot;https://peepcode.com/products/functional-programming-with-clojure&quot;&gt;screencast&lt;/a&gt; by the Topfunky hisself.&lt;/p&gt;
&lt;p&gt;Within the endless enclosures of code as a data type, the astute reader will discover a powerful grammar for dealing with concurrency and the virtues of laziness.  It infuses the mind with visions of infinite datasets resolving themselves into structures across powerful and massive architectures.  Heady stuff in these days of computing lazily from the clouds.&lt;/p&gt;
&lt;p&gt;Programming in clojure is fun, eschewing any notion of &amp;#8216;Objects&amp;#8217;, or &amp;#8216;Classes&amp;#8217;, or any such thing. Applying functions to functions to functions to functions to functions that return functions in fractal fashion.  Looking to the novice as a mindless series of parentheses, but to the aspiring journeyman as the intricate jewel crafted movements of a watch.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>DataMapper loves Redis</title>
   <link href="http://whoahbot.com/2009/05/27/redis-and-datamapper.html"/>
   <updated>2009-05-27T00:00:00-07:00</updated>
   <id>http://whoahbot.com/2009/05/27/redis-and-datamapper</id>
   <content type="html">&lt;h1&gt;DataMapper loves Redis&lt;/h1&gt;
&lt;p&gt;In some cultures, a diamond is the traditional gem of marriage.  I hope that you will forgive me, dear readers that I sealed this union with rubies.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://datamapper.org&quot;&gt;DataMapper&lt;/a&gt; and &lt;a href=&quot;http://code.google.com/p/redis/&quot;&gt;redis&lt;/a&gt; are hitched up!  What a joyous event.  The sweet strain of &lt;a href=&quot;http://www.martinfowler.com/eaaCatalog/identityMap.html&quot;&gt;Identity Map&lt;/a&gt; we know as DataMapper found a beautiful partner in the sleek and speedy redis key-value database.&lt;/p&gt;
&lt;p&gt;The adapter is now ready to show it&amp;#8217;s love in public.  Hitch it up to your app and ring wedding bells.&lt;/p&gt;
&lt;h1&gt;Hardcore forking and gemming action:&lt;/h1&gt;
&lt;p&gt;You can fork the project, or install the latest gem at &lt;a href=&quot;http://github.com/whoahbot/dm-redis-adapter/&quot;&gt;GitHub&lt;/a&gt;, of course.&lt;/p&gt;
&lt;p&gt;Before I get too terribly sloshed at the reception, do let me know if you find &lt;a href=&quot;http://github.com/whoahbot/dm-redis-adapter/issues&quot;&gt;bugs&lt;/a&gt;.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>Jackin up .js with jabber, nginx, jsjac and ejabberd</title>
   <link href="http://whoahbot.com/2009/04/20/jabber-and-jsjac.html"/>
   <updated>2009-04-20T00:00:00-07:00</updated>
   <id>http://whoahbot.com/2009/04/20/jabber-and-jsjac</id>
   <content type="html">&lt;h1&gt;Jackin up .js with jabber, nginx, jsjac and ejabberd&lt;/h1&gt;
&lt;p&gt;Dear, dear friends:&lt;/p&gt;
&lt;p&gt;I wish to tell you of a great opportunity, yes yes!  A simple way to have the users of your site jabber away at each other night and day.  Lets introduce the players.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/bobo_wewo.png&quot; align=&quot;right&quot; /&gt;&lt;/p&gt;
&lt;p&gt;This is our hero, bobo wewo.  Bobo would really like to get his users chatting on his site, just the usual chatter about the wewo community that happens around the water cooler at work, but Bobo is of a mind that there should be a web site where people can talk about wewo things.  This is were we come in.&lt;/p&gt;
&lt;h3&gt;Ejabberd&lt;/h3&gt;
&lt;p&gt;Lucky for us, bobo already has a copy of &lt;a href=&quot;http://www.ejabberd.im/&quot;&gt;Ejabberd&lt;/a&gt; running.  Ejabberd is an excellent &lt;span class=&quot;caps&quot;&gt;XMPP&lt;/span&gt; server written in erlang.  Erlang is also excellent.  All of this is excellent.  But we need one more thing to glue this all together.&lt;/p&gt;
&lt;p&gt;Ejabberd implements an extension to &lt;span class=&quot;caps&quot;&gt;XMPP&lt;/span&gt; called &amp;#8220;&lt;span class=&quot;caps&quot;&gt;BOSH&lt;/span&gt;&amp;#8221;.  Bosh stands for &amp;#8220;Bidirectional-streams Over Synchronous &lt;span class=&quot;caps&quot;&gt;HTTP&lt;/span&gt;&amp;#8221;, and if you want all the gory details, you can read yourself silly right &lt;a href=&quot;http://xmpp.org/extensions/xep-0124.html&quot;&gt;here&lt;/a&gt;.  Traditional &amp;#8216;Ajax&amp;#8217; requests are asynchronous by definition, but in our case, we&amp;#8217;re going to use jsjac to open an request that doesn&amp;#8217;t close right away, or even send data right away.&lt;/p&gt;
&lt;p&gt;To accomplish this magical feat, we tell bobo&amp;#8217;s ejabberd server to enable the http_bind module.&lt;/p&gt;
&lt;script src=&quot;http://gist.github.com/98958.js&quot;&gt;&lt;/script&gt;&lt;p&gt;Also &lt;span style=&quot;color:green&quot;&gt;double&lt;/span&gt; &lt;span style=&quot;color:blue&quot;&gt;check&lt;/span&gt; to &lt;span style=&quot;color:purple&quot;&gt;make &lt;/span&gt; sure that the &lt;span style=&quot;color:red&quot;&gt;http_bind&lt;/span&gt; module is &lt;span style=&quot;color:salmon&quot;&gt;being loaded&lt;/span&gt; when you start Ejabberd.&lt;/p&gt;
&lt;h3&gt;Proxying requests to the ejabberd server.&lt;/h3&gt;
&lt;p&gt;If you&amp;#8217;ve read my other lewd exploits, you&amp;#8217;ll recall fondly that we&amp;#8217;ve spoken &lt;a href=&quot;/2009/02/08/JSONP_and_the_manchurian_candidate.html&quot;&gt;at length&lt;/a&gt; on the subject of browser security policies and how to trip lightly around their jackboots.  To accomplish our wewo-talking, we&amp;#8217;ll need to proxy requests to the ejabberd server using a webserver.  Even though the servers are on the same box, they still need to be proxied because they are on different ports.  Here are the config files to do this with apache or nginx.&lt;/p&gt;
&lt;script src=&quot;http://gist.github.com/98962.js&quot;&gt;&lt;/script&gt;&lt;h3&gt;JSJac&lt;/h3&gt;
&lt;p&gt;Oh yes, you&amp;#8217;ll need &lt;a href=&quot;http://blog.jwchat.org/jsjac/&quot;&gt;JSJac&lt;/a&gt;.  JSJac makes it very easy to manage connecting to a server, sending presence messages, and other message types. Speaking of which, why don&amp;#8217;t we do just that?&lt;/p&gt;
&lt;p&gt;Once you have jsjac installed in your page, it&amp;#8217;s a simple matter to get it connected:&lt;/p&gt;
&lt;script src=&quot;http://gist.github.com/98977.js&quot;&gt;&lt;/script&gt;&lt;p&gt;First, we create an object literal to house the settings for the connection, pull our username and password from the html form we&amp;#8217;ll use, and create a JSJaCHttpBindingConnection.  We also want to bind important events for the client to respond with, mainly messages, connection status and errors.&lt;/p&gt;
&lt;p&gt;Next, we construct a presence message, bound for a multi-user-chat room called #wewo.  Presence messages are love notes to the &lt;span class=&quot;caps&quot;&gt;XMPP&lt;/span&gt; server that in this case, tell it that we wish to join our pea-shaped peers in the chatroom.&lt;/p&gt;
&lt;script src=&quot;http://gist.github.com/98975.js&quot;&gt;&lt;/script&gt;&lt;p&gt;After doing so, our chatroom is ready to convey our messages to the rest of the wewo clan regarding last night&amp;#8217;s episode of &amp;#8216;fresh boss&amp;#8217;.  To send a message to the server, we once again leverage our friend jsjac to do so.  We set our message recipient to #wewo@conference.example.com/whoahbot, which tells the chatroom that this is a message from whoahbot, to the chatroom.  We set the body of the message, and lastly change the type of the message to &amp;#8216;groupchat&amp;#8217;.&lt;/p&gt;
&lt;script src=&quot;http://gist.github.com/99611.js&quot;&gt;&lt;/script&gt;&lt;h3&gt;Debugging&lt;/h3&gt;
&lt;p&gt;I found it most useful to use &lt;a href=&quot;http://psi-im.org/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;PSI&lt;/span&gt;&lt;/a&gt; when debugging, since you can easily see which xml stanzas are being exchanged by you and the server.&lt;/p&gt;
&lt;h3&gt;Fin&lt;/h3&gt;
&lt;p&gt;Lads lords and ladies, I do hope that is enough information about xmpp and jsjac to get you started, and enough information about wewo culture to last you a lifetime. Until next time, &lt;br /&gt;
&lt;a href=&quot;http://gist.github.com/98973&quot;&gt;Here&lt;/a&gt; is the skeleton of the app we&amp;#8217;ve been working on.  Bobo still hasn&amp;#8217;t paid, so I didn&amp;#8217;t style it.&lt;/p&gt;
&lt;p&gt;If you are going to use xmpp, might I make you highly suggestible with some sodium pentathol and &lt;span class=&quot;caps&quot;&gt;SUGGEST&lt;/span&gt; that you purchase the most excellent screencast on the topic by the topfunky himself: &lt;a href=&quot;https://peepcode.com/products/xmpp&quot;&gt;&lt;span class=&quot;caps&quot;&gt;XMPP&lt;/span&gt;/Jabber with Ruby&lt;/a&gt;.  Topfunky is so cool, he chose pink and black for his site and I&amp;#8217;m ever so jealous.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>DataMapper and Redis</title>
   <link href="http://whoahbot.com/2009/02/19/DataMapper_and_redis.html"/>
   <updated>2009-02-19T00:00:00-08:00</updated>
   <id>http://whoahbot.com/2009/02/19/DataMapper_and_redis</id>
   <content type="html">&lt;h1&gt;DataMapper and Redis&lt;/h1&gt;
&lt;p&gt;Listen:&lt;/p&gt;
&lt;p&gt;When we last left our hero, he was slinging silly coffees with someone named jason.  This week, dear friends, the shiniest bauble to have caught the Whoahbot&amp;#8217;s eye happens to be a chrome-plated, espresso powered monster called &lt;a href=&quot;http://code.google.com/p/redis/&quot;&gt;Redis&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;About Redis&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Redis is a key-value database. It is similar to memcached but the dataset is not volatile, and values can be strings, exactly like in memcached, but also lists and sets with atomic operations to push/pop elements.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This is the description on the home page, and you may be thinking: &amp;#8220;Crumbs, I really have to go&amp;#8230; I just saw a bit of paint drying in my kitchen that I must attend to&amp;#8221;.  But oh let me tell you, this is the ferrari of key-value databases:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;o&quot;&gt;======&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;GET&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;======&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;10000&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requests&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;completed&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;26&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;seconds&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parallel&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clients&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;38759&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;69&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requests&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;per&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;second&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;======&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;SET&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;======&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;10004&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requests&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;completed&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;24&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;seconds&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;50&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parallel&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;clients&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;41000&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mo&quot;&gt;00&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requests&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;per&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;second&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;I highly suggest that you dig out your rubies and try the excellent libraries offered by Ezra at &lt;a href=&quot;http://github.com/ezmobius/redis-rb&quot;&gt;Github&lt;/a&gt;, or try the &lt;a href=&quot;http://github.com/whoahbot/dm-redis-adapter/&quot;&gt;Gelato&lt;/a&gt; of &lt;a href=&quot;http://datamapper.org&quot;&gt;DataMapper&lt;/a&gt; adapters.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>JSONP web services with rack</title>
   <link href="http://whoahbot.com/2009/02/11/JSONP-services-with-rack.html"/>
   <updated>2009-02-11T00:00:00-08:00</updated>
   <id>http://whoahbot.com/2009/02/11/JSONP-services-with-rack</id>
   <content type="html">&lt;h1&gt;&lt;span class=&quot;caps&quot;&gt;JSONP&lt;/span&gt; web services with rack&lt;/h1&gt;
&lt;h2&gt;Our story begins&lt;/h2&gt;
&lt;p&gt;Listen:&lt;/p&gt;
&lt;p&gt;In our last gripping &lt;a href=&quot;/2009/02/08/JSONP_and_the_manchurian_candidate.html&quot;&gt;episode&lt;/a&gt;, we followed the grim tale of a cupcake and his deadly &lt;span class=&quot;coffeetime&quot;&gt;[coffee]&lt;/span&gt; messages.&lt;/p&gt;
&lt;p&gt;These secret susurruses were fetched from a Rack app that can serve both &lt;span class=&quot;caps&quot;&gt;JSON&lt;/span&gt;, and return a properly formatted &lt;span class=&quot;caps&quot;&gt;JSONP&lt;/span&gt; for javascript clients.&lt;/p&gt;
&lt;h2&gt;Enter the hero: Rack&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;http://rack.rubyforge.org/&quot;&gt;Rack&lt;/a&gt; is one of those things that you don&amp;#8217;t get at first, and then you get it, and then you were embarassed that you didn&amp;#8217;t get it in the first place. Or was that just me?&lt;/p&gt;
&lt;p&gt;A Rack compatible &amp;#8216;app&amp;#8217; just needs a few things to get going.&lt;/p&gt;
&lt;ul&gt;
	&lt;li&gt;Define a call method&lt;/li&gt;
	&lt;li&gt;Return an array with three items&lt;/li&gt;
	&lt;li&gt;The response code&lt;/li&gt;
	&lt;li&gt;The headers&lt;/li&gt;
	&lt;li&gt;Anything that responds to the each method.  Say&amp;#8230; a string, or a pack of &amp;#8220;wild dogs&amp;#8221;.each do |bite| &amp;#8220;ouch&amp;#8221; end&lt;/li&gt;
	&lt;li&gt;It should be nice and return the proper headers, Content-type and Content-length&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Install rack the same way you install any gemified rubies.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;bash&quot;&gt;sudo gem install rack
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Lambdas are a simple call girl, lets make her an app right now!  We&amp;#8217;ll return text/html as our mime type now so you can check it in a browser.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Rack&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;ContentLength&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;lambda&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;env&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Content-Type&amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;text/html&amp;#39;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Hey there, sailor&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;run&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Put that little lady in a file called config.ru, and run &amp;#8216;rackup ./config.ru&amp;#8217;.  You should be able to visit &lt;a href=&quot;http://localhost:9292/&quot;&gt;http://localhost:9292/&lt;/a&gt; for a good time.  What&amp;#8217;s that &amp;#8216;use&amp;#8217; statement for, you ask?  Err&amp;#8230; lets take a short break.&lt;/p&gt;
&lt;h2&gt;Intermission&lt;/h2&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/chimney_rock.jpg&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;Stumptowner&lt;/h2&gt;
&lt;p&gt;Your first rack app!  As much as your first rails app ever returned with quite a bit less code.  I was going to take a few more swings at rack jokes, the obvious ones just hanging there like rotten fruit, but I&amp;#8217;m sure you&amp;#8217;ll write an app to generate them for me anyway, so lets move on.&lt;/p&gt;
&lt;p&gt;So, where we did put a string that salutes our fighting sailors, we could put nearly anything that responds to the each method.  For the stumptowner app, we have a small, but quite silly string from the &lt;a href=&quot;http://github.com/whoahbot/stumptowner.whoahbot.com/blob/master/stumptowner.rb&quot;&gt;generator&lt;/a&gt;.  The string that is returned is properly formatted &lt;span class=&quot;caps&quot;&gt;JSON&lt;/span&gt; response.&lt;/p&gt;
&lt;p&gt;Our poor sailor is on his own with lady lambda, so I&amp;#8217;ve put my generator in it&amp;#8217;s place.&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;lambda&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;env&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Content-Type&amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;application/json&amp;#39;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Stumptowner&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;to_json&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;run&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Great, fabulous, contragulations you graduate.  Happy racking.  Here&amp;#8217;s your ruby shaped hat and diploma.&lt;/p&gt;
&lt;p&gt;Wait, stop!  Come back, cease and desist!  This won&amp;#8217;t do.  Whoahbot, you&amp;#8217;re fired.  See d. trump for your haircut on the way out.  This won&amp;#8217;t work for javascript apps making cross-domain requests.  We need a little p in our json for that.&lt;/p&gt;
&lt;h2&gt;Middleware&lt;/h2&gt;
&lt;p&gt;Yes yes, let us introduce you to rack middleware:&lt;/p&gt;
&lt;p&gt;&lt;span class=&quot;italics&quot;&gt;&lt;br /&gt;
what&amp;#8217;s great about rack&lt;br /&gt;
is that it will stack&lt;br /&gt;
on top of itself, hoo-ray!&lt;br /&gt;
&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Wierd, there&amp;#8217;s no syntax highlighting for limerick.  At any rate, middleware is the lego of web framework, it&amp;#8217;s the layers in your cake, the stacks of waffles downstairs, complete with butter and maple syrups.&lt;/p&gt;
&lt;p&gt;In our steamy &amp;#8216;sailor come hither&amp;#8217; app above, we used the rack supplied Rack::ContentLength middleware to properly set the content-length header of our response.  If you don&amp;#8217;t do that, rack has a lint middleware that will wag it&amp;#8217;s naughty finger at you. You can set the content-lengthby hand, or you could be lazy, the mark of any good programmer.&lt;/p&gt;
&lt;p&gt;Saying &amp;#8216;use Rack::Content::Length&amp;#8217; tells rack that before you return the finished response code, headers and body to the client, calculate the length of the response, and put that in the headers.&lt;/p&gt;
&lt;p&gt;Just as there is a middleware for setting the content-length, the fabulous, handsome and prolific minds of the rack community have produced &lt;a href=&quot;http://github.com/rack/rack-contrib/blob/43a508f7bdf59c3d1aee2856d71f815ae2056cf1/lib/rack/contrib/jsonp.rb&quot;&gt;&lt;span class=&quot;caps&quot;&gt;JSONP&lt;/span&gt;&lt;/a&gt; middleware as well.&lt;/p&gt;
&lt;p&gt;The completed app sings the body electric like this:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;stumptowner.rb&amp;#39;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;jsonp.rb&amp;#39;&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Rack&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;JSONP&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;use&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Rack&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;ContentLength&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;lambda&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;env&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;Content-Type&amp;#39;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;&amp;#39;application/json&amp;#39;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Stumptowner&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;to_json&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;run&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Tra-la!  The beauty of this approach is that non &lt;span class=&quot;caps&quot;&gt;JSONP&lt;/span&gt; clients just get regular &lt;span class=&quot;caps&quot;&gt;JSON&lt;/span&gt;, while jQuery and his pals get what they need.&lt;/p&gt;
&lt;p&gt;And they all lived happily ever after.  The end.&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>JSONP, and the manchurian candidate</title>
   <link href="http://whoahbot.com/2009/02/08/JSONP_and_the_manchurian_candidate.html"/>
   <updated>2009-02-08T00:00:00-08:00</updated>
   <id>http://whoahbot.com/2009/02/08/JSONP_and_the_manchurian_candidate</id>
   <content type="html">&lt;h1&gt;&lt;span class=&quot;caps&quot;&gt;JSONP&lt;/span&gt;, and the manchurian candidate&lt;/h1&gt;
&lt;p&gt;Got any coffee?  No?  Click &lt;span class=&quot;coffeetime&quot;&gt;[Coffee?]&lt;/span&gt; for the brew of the day.&lt;/p&gt;
&lt;p&gt;Good.  Now lean back, and let me tell you how you just put the &lt;a href=&quot;http://us.imdb.com/title/tt0056218/&quot;&gt;manchurian candidate&lt;/a&gt; of cupcakes into your window object.  (Don&amp;#8217;t look now, he&amp;#8217;s gone).&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;http://www.json.org/&quot;&gt;&lt;span class=&quot;caps&quot;&gt;JSON&lt;/span&gt;&lt;/a&gt; is a fantastical data structure, coalesced into being by one of the few &lt;a href=&quot;http://www.crockford.com/&quot;&gt;people&lt;/a&gt; on the planet that think that JavaScript is a wonderful and mellifluous language to write in.  Well, maybe he only likes the &lt;a href=&quot;http://www.amazon.com/exec/obidos/ASIN/0596517742/wrrrldwideweb&quot;&gt;Good Parts&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;But until Crockford&amp;#8217;s JSONRequest is widely implemented, what we have to work with for cross site mashups is the blackest of black arts.  There are secret handshakes for you to grasp and grip.  A mysterious contract hitter called &lt;span class=&quot;caps&quot;&gt;JSONP&lt;/span&gt;, or &lt;span class=&quot;caps&quot;&gt;JSON&lt;/span&gt; with &amp;#8216;Padding&amp;#8217;.  I will tell all fingerings of the handshakes in time, but first, I want you to meet your browser window:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/happy_choppy.png&quot; align=&quot;right&quot; /&gt;&lt;/p&gt;
&lt;p&gt;A cheerful fellow.  Happy-go-lucky.  Ties his shoes the same way every morning.  But something lurks beneath his frosted grin.  Yes, our friend here is highly suggestible, he buys the new car &lt;span class=&quot;caps&quot;&gt;AND&lt;/span&gt; the undercoating.  Poor fellow, we&amp;#8217;ll imprint him with a secret phrase when we initiate a &lt;span class=&quot;caps&quot;&gt;JSONP&lt;/span&gt; request.&lt;/p&gt;
&lt;p&gt;I think our brothers in arms at &lt;a href=&quot;http://www.jquery.com&quot;&gt;jQuery&lt;/a&gt; said it best when they said:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;&lt;span class=&quot;c1&quot;&gt;// Handle JSONP-style loading&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;jsonp&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;
	&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;tmp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;nx&quot;&gt;success&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
	&lt;span class=&quot;nx&quot;&gt;complete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
	&lt;span class=&quot;c1&quot;&gt;// Garbage collect&lt;/span&gt;
	&lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;jsonp&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;delete&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;jsonp&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;];&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){}&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;head&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		&lt;span class=&quot;nx&quot;&gt;head&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;removeChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;script&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Whoah!  What was that that just whizzed by?  Did our tasty friend get a new function planted in his cake?  Yes!  And when the secret word is mouthed at the dinner party he&amp;#8217;s attending, he screams forth his &lt;span class=&quot;caps&quot;&gt;JSON&lt;/span&gt; object literal!  Layered cakes are not to be trusted.&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;/images/posts/angry_choppy.png&quot; align=&quot;right&quot; /&gt;&lt;/p&gt;
&lt;p&gt;When the ajax request went out, it looked like this: http://stumptowner.whoahbot.com/?callback=jsonp1236556779135.  When it came back, it called the secret function &amp;#8216;jsonp1236556779135&amp;#8217; thusly:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;&lt;span class=&quot;nx&quot;&gt;jsonp1236556779135&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;coffee&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Pallat of Panama Manifested&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;s2&quot;&gt;&amp;quot;country&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Panama&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;elevation&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;2935 - 3317 Meters&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;s2&quot;&gt;&amp;quot;varietal&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;Chai and Chai&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;s2&quot;&gt;&amp;quot;flavors&amp;quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;Fragrance of bacon, pie and mango delivering a silken mouth feel.&amp;quot;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In the snippet above, window[jsonp] is a function that takes one argument.  That argument is the &lt;span class=&quot;caps&quot;&gt;JSON&lt;/span&gt; data returned from the &lt;span class=&quot;caps&quot;&gt;AJAX&lt;/span&gt; call.&lt;/p&gt;
&lt;p&gt;What&amp;#8217;s going on here?  Why would someone do this?  Why a cupcake for the love of confectioner&amp;#8217;s sugar! The problem lies buried in cross-border passport restrictions for XMLHTTPRequests. Cross-domain ajax requests are forbidden by your browser&amp;#8217;s same-origin policy and the internet gestapo.&lt;/p&gt;
&lt;p&gt;This is most distressing for us that want to make hilarious &lt;span class=&quot;caps&quot;&gt;JSON&lt;/span&gt; mashup datasources!  And so, &lt;a href=&quot;http://bob.pythonmac.org/archives/2005/12/05/remote-json-jsonp/&quot;&gt;Bob Ippolito&lt;/a&gt; proposed an ad-hoc standard that neatly dances through checkpoint charlie.&lt;/p&gt;
&lt;p&gt;For those that are about to &lt;span class=&quot;caps&quot;&gt;JSONP&lt;/span&gt;, here is how we salute you:&lt;/p&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;javascript&quot;&gt;&lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;getJSON&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;http://stumptowner.whoahbot.com/?callback=?&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;&amp;#39;.something&amp;#39;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;lt;div class=&amp;#39;coffee&amp;#39;&amp;gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;coffee&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;lt;/div&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;lt;div class=&amp;#39;elevation&amp;#39;&amp;gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;elevation&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;lt;/div&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;lt;div class=&amp;#39;varietal&amp;#39;&amp;gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;varietal&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;lt;/div&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;
  &lt;span class=&quot;nx&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;lt;div class=&amp;#39;flavors&amp;#39;&amp;gt;&amp;quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&amp;quot;flavors&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&amp;quot;&amp;lt;/div&amp;gt;&amp;quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Your friendly neighborhood jQuery.getJSON function, or it&amp;#8217;s big brother $.ajax, will replace the callback=? in the url parameter with an automatically generated callback function name.  Tra-la!&lt;/p&gt;
&lt;p&gt;Next up, constructing iron-curtain subversive &lt;span class=&quot;caps&quot;&gt;JSONP&lt;/span&gt; (P for propaganda) web-services using Rack!&lt;/p&gt;</content>
 </entry>
 
 <entry>
   <title>whoahblog</title>
   <link href="http://whoahbot.com/2009/02/05/blogging_with_whoahbot.html"/>
   <updated>2009-02-05T00:00:00-08:00</updated>
   <id>http://whoahbot.com/2009/02/05/blogging_with_whoahbot</id>
   <content type="html">&lt;h1&gt;whoahblog&lt;/h1&gt;
&lt;div class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;ruby&quot;&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;times&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;do&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;begin&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;create_new_blog&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;rescue&lt;/span&gt; &lt;span class=&quot;no&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;no&quot;&gt;Frustration&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;drink&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;gin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;ensure&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;drunk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;vi&quot;&gt;@whoahbot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;</content>
 </entry>
 
</feed>
