Tag Archive: EppsNet Labs

EppsNet Labs: Glider

14 Mar 2008 / PE

Here's a really simple gliding tabs demo using glider.js, which is downloadable here.

As you can see from the really simple code below, you could do something pretty nice with this without too much extra effort.

Glider is dependent on the Prototype and Scriptaculous libraries, both of which are included in the glider download, as is the required stylesheet.

HTML:
  1. <link rel="stylesheet" href="stylesheets/glider.css" type="text/css">
  2. <script src="javascripts/prototype.js"></script>
  3. <script src="javascripts/effects.js"></script>
  4. <script src="javascripts/glider.js"></script>
  5.  
  6. <div id="glider">
  7.     <div class="controls">
  8.         <a href="#tab1">Tab 1</a> |
  9.         <a href="#tab2">Tab 2</a> |
  10.         <a href="#tab3">Tab 3</a> |
  11.         <a href="#tab4">Tab 4</a>
  12.     </div>
  13.  
  14.     <div class="scroller">
  15.         <div class="content">
  16.             <div class="section" id="tab1">Tab 1</div>
  17.             <div class="section" id="tab2">Tab 2</div>
  18.             <div class="section" id="tab3">Tab 3</div>
  19.             <div class="section" id="tab4">Tab 4</div>
  20.         </div>
  21.     </div>
  22. </div>
  23.  
  24. <script>
  25.     new Glider( 'glider', { duration:0.5 } );
  26. </script>


EppsNet Labs: VoiceXML RSS Reader

7 Oct 2007 / PE

The Big Picture

We're going to build application that takes RSS data -- specifically the EppsNet.com feed -- as input, and outputs a VXML file that can be read and spoken by a VoiceXML browser.

The RSS Source Format

The general structure of the EppsNet feed -- or any RSS 2.0 feed -- looks like this:

XML:
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- generator="wordpress/2.2.2" -->
  3. <rss version="2.0"
  4.     xmlns:content="http://purl.org/rss/1.0/modules/content/"
  5.     xmlns:wfw="http://wellformedweb.org/CommentAPI/"
  6.     xmlns:dc="http://purl.org/dc/elements/1.1/"
  7.     >
  8.  
  9.   <channel>
  10.     <title>EppsNet: Notes from the Golden Orange</title>
  11.     <link>http://eppsnet.com</link>
  12.     <description>Online journal based in Orange County, CA.
  13.         Hilarious anecdotes tempered by the icy chill of certain
  14.         death.</description>
  15.     <pubDate>Fri, 05 Oct 2007 03:51:21 +0000</pubDate>
  16.     <generator>http://wordpress.org/?v=2.2.2</generator>
  17.     <language>en</language>
  18.     <item>
  19.       ...
  20.     </item>
  21.     <item>
  22.       ...
  23.     </item>
  24.       ...
  25.   </channel>
  26. </rss>

Each item within the RSS feed has a format that looks (slightly simplified) like this:

XML:
  1. <item>
  2.       <title>Post Title</title>
  3.       <link>http://eppsnet.com/2007/10/post-title</link>
  4.       <pubDate>Fri, 05 Oct 2007 03:51:21 +0000</pubDate>
  5.       <dc:creator>PE</dc:creator>
  6.  
  7.       <category><![CDATA[Category1]]></category>
  8.  
  9.       <category><![CDATA[Category2]]></category>
  10.  
  11.       <description>
  12.         <![CDATA[
  13.         Item summary
  14.         ]]>
  15.       </description>
  16.       <content:encoded>
  17.         <![CDATA[
  18.         Full item content
  19.         ]]>
  20.       </content:encoded>
  21.     </item>

VXML Output

Consult the VoiceXML 2.1 specification for more details, but the output we want will look like this:

XML:
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <vxml version="2.1">
  3.   <form id="MainMenu">
  4.     <field name="select_num" type="digits">
  5.       <prompt>
  6.         EppsNet: Notes from the Golden Orange
  7.         <break size="small"/>
  8.       </prompt>
  9.       <prompt>Please select a story from the following list.</prompt>
  10.       <prompt>
  11.         1: Post Title 1
  12.         <break size="small"/>
  13.       </prompt>
  14.       ...
  15.       <prompt>
  16.         5: Post Title 5
  17.         <break size="small"/>
  18.       </prompt>
  19.       <noinput>
  20.         Please select a number.
  21.         <reprompt/>
  22.       </noinput>
  23.       <nomatch>
  24.         Please select a valid number.
  25.         <reprompt/>
  26.       </nomatch>
  27.     </field>
  28.     <filled>
  29.       <assign name="selection" expr="select_num"/>
  30.       <if cond="selection =='1'">
  31.         <prompt>
  32.           Post Title 1. Post summary goes here [...]
  33.           <break size="small"/>
  34.         </prompt>
  35.         ...
  36.         <elseif cond="selection =='5'"/>
  37.         <prompt>
  38.           Post Title 5. Post summary goes here [...]
  39.           <break size="small"/>
  40.         </prompt>
  41.       </if>
  42.       <clear namelist="select_num"/>
  43.       <reprompt/>
  44.     </filled>
  45.   </form>
  46. </vxml>

What this will do when processed by a VoiceXML browser is:

  1. Say the title of the RSS feed.
  2. Offer the listener a numbered list of post titles to select from.
  3. Parse the user's selection, by either voice or touch-tone input.
  4. Read out the selected post summary.
  5. Clear the input variable and offer the opportunity to select another item.

Generating VoiceXML from RSS

Because this is a WordPress site, we're going to use PHP for the task of converting RSS input to VXML output. To simplify the task of parsing the input, we'll use MagpieRSS, an RSS parser written in PHP.

The main loop in the code below processes up to 5 RSS items and simultaneously builds up two strings, one for the selection prompts and one for the item details.

PHP:
  1. <?php
  2. /* We need this for MagpieRSS */
  3. require_once 'rss_fetch.inc';
  4.  
  5. /* Read the RSS feed */
  6. $url = 'http://eppsnet.com/feed';
  7. $feed = fetch_rss($url);
  8.  
  9. $selection = '';
  10. $detail = '';
  11. $counter = 0;
  12.  
  13. $selection .= '<form id="MainMenu">';
  14. $selection .= '<field name="select_num" type="digits">';
  15. $selection .= '<prompt>';
  16. $selection .= $feed->channel['title'] . '<break size="small"/>';
  17. $selection .= '</prompt>';
  18. $selection .= '<prompt>';
  19. $selection .= 'Please select a story from the following list.';
  20. $selection .= '</prompt>';
  21.  
  22. foreach ($feed->items as $item ) {
  23.     /* Limit output to 5 items */
  24.     if ($counter++>= 5)
  25.         break;
  26.  
  27.     if ($counter == 1)
  28.     {
  29.         $detail .= '<filled>';
  30.         $detail .= '<assign name="selection" expr="select_num"/>';
  31.         $detail .= "<if cond=\"selection =='$counter'\">";
  32.     }
  33.     else
  34.     {
  35.         $detail .= "<elseif cond=\"selection =='$counter'\"/>";
  36.     }
  37.     $detail .= sprintf('<prompt>%s. %s<break size="small"/></prompt>',
  38. $item[title],$item[description]);
  39.  
  40.     $selection .= sprintf('<prompt>%d: %s<break size="small"/></prompt>',
  41. $counter,$item[title]);
  42. }
  43.  
  44. $selection .= '<noinput>Please select a number.
  45.                               <reprompt/></noinput>';
  46. $selection .= '<nomatch>Please select a valid number.
  47.                               <reprompt/></nomatch>';
  48. $selection .= '</field>';
  49.  
  50. $detail .= '</if>';
  51. $detail .= '<clear namelist="select_num"/><reprompt/>';
  52. $detail .= '</filled></form>';
  53.  
  54. /* Output the VXML */
  55. echo '<vxml version="2.1">';
  56. echo $selection;
  57. echo $detail;
  58. echo '</vxml>';
  59. ?>

Try It

I put the PHP script at http://eppsnet.com/lab/vxml but the output is not very interesting in a regular browser. Fortunately, Voxeo offers a free service that maps voice applications to phone numbers. You give them the URL of your voice app and they'll point a phone number to it.

So -- if you pick up the phone, call 800-289-5570 and enter PIN 9992002320, the Voxeo application will fetch the VXML output from our PHP script and read selected excerpts from the EppsNet feed to you over the phone.

Try it!

Limitations

The VXML output doesn't contain the entire contents of each post, just the truncated version from the RSS <description> field. I tried using the <content:encoded> field instead but some markup constructs choked the Voxeo application. I think I could get it to work if I spent enough time on it, but for now, I've decided to leave it as an exercise for the reader.


EppsNet Labs: The 99 Most Interesting Photos of Orange County, California

8 Jul 2007 / PE

You can see them here.


EppsNet Labs: Deriving the Quadratic Formula

20 Jun 2007 / PE

I saw the other day that Wordpress has a LaTeX plugin called LatexRender. I was interested in trying it out, so I chose as my subject a derivation of the quadratic formula:

\frac{-b\pm \sqrt{b^{2}-4ac}}{2a}

This is something I worked through with my 8th-grade son the other night -- he's studying quadratic equations in school -- and I'm sure others will be as fascinated by it as he was.

Hovering the cursor over each equation will display the LaTeX markup.

Ready? Here we go!

1. Start with a standard quadratic equation.

ax^{2}+bx+c=0

2. Move the constant to the other side of the equation.

ax^{2}+bx=-c

3. Divide through by a.

x^{2}+\frac{b}{a}x=-\frac{c}{a}

4. Take half of the x coefficient and square it.

\left(\frac{b}{2a}\right)^{2}=\frac{b^{2}}{4a^{2}}

5. Add the squared term to both sides.

x^{2}+\frac{b}{a}x+\frac{b^{2}}{4a^{2}}=-\frac{c}{a} + \frac{b^{2}}{4a^{2}}

6. Convert the right side of the equation to a common denominator.

x^{2}+\frac{b}{a}x+\frac{b^{2}}{4a^{2}}=-\frac{4ac}{4a^{2}} + \frac{b^{2}}{4a^{2}}

7. Convert the left side to square form and combine terms on the right.

\left(x+\frac{b}{2a}\right)^{2}=\frac{b^{2}-4ac}{4a^{2}}

8. Take the square root of both sides.

x+\frac{b}{2a}=\pm\sqrt\frac{b^{2}-4ac}{4a^{2}}=\frac{\pm\sqrt{b^{2}-4ac}}{2a}

9. Solve for x.

x=-\frac{b}{2a}\pm\frac{\pm\sqrt{b^{2}-4ac}}{2a}=\frac{-b\pm \sqrt{b^{2}-4ac}}{2a}

Q.E.D.!