Wednesday, January 8, 2014

Using a StyleSheet in Actionscript 2 to display an iTunes img Correctly

There are times when a simple request turns into a flight down the rabbit hole. mathies and mathclips share an XML file with information about learning tools available to Ontario students.  A link to Sketchpad Explorer on the App store needed to be added.  On the mathies webpage, this was easily done with html like:
       

Sketchpad Explorer is available from the 
<a href="http://itunes.apple.com/ca/app/sketchpad-explorer/id452811793?mt=8&amp;uo=4" target="itunes_store">
<img src="http://www.oame.on.ca/mathiesbeta/images/badge_appstore-sm.png" height="15px" width="61px" />
</a>
getting a result like:
where the image was unnecessarily copied from one created with http://linkmaker.itunes.apple.com to the local server.

In Flash, there were two issues:
  1. A phantom underline preceded the image as the result of a <u> tag surrounding the <a>...<img /> tags
  2. The topic list, a feature only of the mathclips tool tab,  appeared next to the image and not below it, despite <br /> tags.  This is due to Flash floating images.
The wrapping issue was solved using an idea from Panax and StyleSheets and the underline issue was solved by creating a blueNoUnderline class.

The StyleSheet is created in code as follows:
var myStyleSheet:TextField.StyleSheet = new TextField.StyleSheet();
myStyleSheet.setStyle("a", {color:'#0000FF', textDecoration:'underline'});
myStyleSheet.setStyle(".blueNoUnderline", {color:'#0000FF', textDecoration:'none'});
myStyleSheet.setStyle(".imageSpacer30", {fontSize:30});
The htmlText is massaged to wrap the <img /> tag inside a <p> tag (red text below).  The dummy paragraph suggested by Panax is added (green text below).  The blueNoUnderline class is added to the <a> tag to avoid a bit of underlined space (blue text below).
       
Sketchpad Explorer is available from the 
<a href='http://itunes.apple.com/ca/app/sketchpad-explorer/id452811793?mt=8&uo=4' target='itunes_store' class='blueNoUnderline'>
<p>
<img src='http://www.oame.on.ca/mathiesbeta/images/badge_appstore-sm.png' width='61px' height='15px' />
</p>
</a>
<p class='imageSpacer30'></p>
<br />
<p><font size=\"10\">(Geometry, Measurement, Simulations)</font></p>
The necessity to precede the "blueNoUnderline" name with period in the setStyle was a late discovery as I did not see it any of the examples I looked at.  For a while, I was convinced that StyleSheets read from .css files were the only ones that worked.

Wednesday, November 13, 2013

Sublime Text Plugin to Sort Tabs

I am a huge fan of the Sublime Text Editor.  Today, Greg Clarke and I created our first plugin.  It will add items to the Tab Context menu that will sort the open files, by file name.  Sublime is a really fun environment in which to program in Python.  You can download the plugin, copy it to your Sublime Text Installed Packages Folder, rename it as TabOrdering.sublime-package and it will be available to you once you restart Sublime.  To create your own plugin see NetTuts' instructions.

Thursday, May 9, 2013

More Circle Drawing

This seems like a long time into 2013 for the year's first post.  The occasion is the receipt of an email from Dan Meyer (possibly in error) alerting me to a fun circle drawing applet a student in England put together.  This is a nice followup to my previous posts (first, second) about Alexander Overwijk, a teacher at my alma mater, Glebe Collegiate whose motto is "in alta tende", which I have always loved.  The three of us were at OAME 2013 last week which was marvelous.  The applet would be a interesting tool to judge a freehand circle drawing contest.

Incidently, Vi Hart just posted a circle drawing video.  One of the featured speakers at OAME 2014 will be George W. Hart, who was introduced as Vi's father - only in the internet age!





Tuesday, June 19, 2012

Using IronSpread and Regular Expressions in Excel

I get a lot of traffic on this blog related to Regular Expressions in Excel, much of it from http://stackoverflow.com/questions/4556910/how-do-i-get-regex-support-in-excel-via-a-function-or-custom-function.  There are comments there that indicate that it does not work with Office 2010.

I stumbled upon www.ironspread.com, which allows you to use Python to "program" Excel 2007 and 2010 sheets.  Python has excellent support for Regular Expressions.  It looks like there are other libraries for Python that can be used with Excel and OpenOffice; PyUNO for one.

I quickly cooked up the following example using a regular expression for valid email addresses found at http://www.regular-expressions.info/email.html.

The Excel sheet looks like:


The Python program looks like:

 # see http://www.regular-expressions.info/email.html for discussion about  
 # regular expressions to check email addresses  
 import re  
 emailRE = r"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|asia|jobs|museum)\b"  
 for i in range(1, 100):  
   currCellValue = Cell(i,1).value  
   if currCellValue == 0:  
     break  
   try:  
     m = re.match(emailRE, currCellValue).group(0)  
     if m == currCellValue:  
       # matches full address  
       Cell(i,2).value = ""  
       Cell(i,3).value = ""  
     else:  
       # matches part of address  
       Cell(i,2).value = "Suggestion"  
       Cell(i,3).value = m  
   except:  
     # no match  
     Cell(i,2).value = "Invalid"  
     Cell(i,3).value = ""  

and once finished, columns B and C are filled in


I am a novice programmer in this environment, so I hope there are no glaring newbie mistakes and that the example is illustrative.

IronSpread installs a Python editor, IDLE, and a command shell which can be used to test your work.  I still love Sublime Text 2 as an editor, so give a command like:
execfile("c:/Users/Ross/Documents/EmailAddresses.py")
in the shell to run the program saved by Sublime.  Any print statements will output to the shell.  I have linked to the Excel Sheet and Python program above if you want to try them out.

Monday, May 14, 2012

Spectacular Sears Successes

I don't usually feature my family here (with rare exceptions), but will now.  Jonathan was one of two actors in Salt-Water Moon at the Sears Provincial Showcase and came away with an award of excellence for acting together with Sam.  The play, by the late David French, is a lovely story and the two actors, together with their stage manager, director, costume and set designers rendered it beautifully.

Here is a piece from the radio where you can get a sense of their Newfoundland accents and stage chemistry.


And here they are with their award.


Saturday, May 12, 2012

Two cewebrities at one session

I am at the OAME 2012 Conference in Kingston, showing folks the new CLIPS wrapper, calculator and Multiplying Fractions Activities in development mode.  I did get a chance to see Dan Meyer's presentation on Thursday "Why Kids Hate Word Problems".  It was a sensible, craftful, and powerful appeal.

A delightful part was that by coincidence I sat next to another internet sensation, Mr. O.  Faithful readers of this blog (a bit of useful fiction) will remember my earlier post about this teacher at my alma mater and his 15 minutes of internet fame.  That post had some of the details wrong, apparently.  Mr. O was flown to Portugal for the making of a movie about the perfect circle and spoke at Art Basel, in Switzerland, about his experience.  He even spoke to producers at the Letterman show. Apparently, the video was shot in June 2006 by Glebe's webmaster, who you can hear in the background, and posted to their site where it received about as much interest as this blog.  In January, some kid in North Dakota posted it to YouTube, College Humor and some other sites.  It went viral and was YouTube's featured video for two weeks.  Mr. O. did not until that time even know what YouTube was.  He does now.

In case you require documentation, I have embedded the footage from the World Championship.


Wednesday, March 14, 2012

You say minus I say ptooey

I have started a vigorous comment thread in response to Keith Devlin's Huffington Post post.  Maybe you would like to weigh in...

$(-3)^\frac{-3}{2}$

Latex Equation created with the help of codecogs.com