Balancing Tags in HTML and XHTML Excerpts

It is fairly common to want to take an HTML source of variable length and display an excerpt. Although some formats, such as Atom and RSS, anticipate this and create a separate summary element, we don’t always have the luxury of using such a data source.

Creating an excerpt introduces a problem, though: if we create an excerpt based on a number of words or characters, we may end up with unbalanced HTML or even broken tags.

One solution is to discard all tags and display plain text, but this is often unsatisfactory.

Here is my method of balancing tags. It assumes that the input is an excerpt of a valid XHTML snippet. The reason for this requirement has to do with self-closing tags, which I hope will be apparent from the description:
Continue reading Balancing Tags in HTML and XHTML Excerpts

SharePoint 2010 Cross-Site Lookup using PowerShell

A common SharePoint request is to create a lookup field from a list in another site. This is possible so long as the sites are within the same site collection, but it does require some customization.

Since I am dealing with a single-server farm, I was able to do this fairly quickly in PowerShell:

# Set the site collection in which the source and destination webs exist
$site = Get-SPSite("https://mysite/path/")

# Set the source web to the web where the source list exists
$sourceweb = $site.OpenWeb("sourcepath")

# Set the destination web to the web where you wish to add the lookup
$destinationweb = $site.OpenWeb("destinationpath")

# Set the source list to the list in which the field exists
$sourcelist = $sourceweb.Lists["List Name"]

# Set the source field to the field you wish to perform lookups on
$sourcefield = $sourcelist.Fields["Field Name"]

# Get the collection of all fields in the destination list
$destinationfields = $destinationweb.Lists["List Name"].Fields

# Add a lookup field to the fields collection
# See the SPFieldCollection AddLookup(String,Guid,Guid,Boolean) method
# For details: http://msdn.microsoft.com/en-us/library/ms430950.aspx
$lookupname = $destinationfields.AddLookup($sourcefield.Title,$sourcelist.ID,$sourceweb.ID,false)
# The above produces an error: Missing expression after ','. At line:1, char:83
# Right--in Powershell, $false is False.
$lookupname = $destinationfields.AddLookup($sourcefield.Title,$sourcelist.ID,$sourceweb.ID,$false)

# Get the newly-added lookup field
$lookup = $destinationfields.GetFieldByInternalName($lookupname)

# Set the lookup field to the internal name of the source field
$lookup.LookupField = $sourcefield.InternalName

# Update the lookup -- without this the previous changes won't be saved
$lookup.Update()

# Dispose of the SPWeb and SPSite objects
$sourceweb.Dispose()
$destinationweb.Dispose()
$site.Dispose()

Oracle stored procedures and ColdFusion

I’ve heard for years that using Oracle’s stored procedures is both more efficient and more secure than writing queries against the database. It turns out, not everyone agrees with that and there is quite a bit of room for debate (most of the articles focus on MS-SQL Server and T-SQL, not Oracle and PL/SQL, although some general principles still apply):

I was still interested in how to use Oracle stored procedures with ColdFusion, though.
Continue reading Oracle stored procedures and ColdFusion

JAWS Screen Reader Reads Hidden Span in Internet Explorer

5 years ago, Juicy Studio posted in the article Screen Readers and display: none that the JAWS Screen Reader reads the content of hidden span elements on a page when used with Internet Explorer.

Although a subsequent article (JAWS, Window-Eyes and display:none: Return to 2007) suggests that this issue has been resolved in JAWS version 12 when used with Internet Explorer 9.

I have not yet tested this in Internet Explorer 9, but I noted that there is still at least one issue when using JAWS 12 with Internet Explorer 8: the title attribute of a hidden span element is read aloud. For example, take the following HTML:

<p>Paragraph element. You should hear this text.</p>
<p>Paragraph element. You should hear this text. <span style=”display:none”>Hidden span element. You should not hear this text.</span></p>
<p>Paragraph element. You should hear this text. <span title=”Title attribute of hidden span element. You should not hear this text.” style=”display:none”></span></p>

I expected to hear exactly what is displayed on-screen:

  • Paragraph element. You should hear this text.
  • Paragraph element. You should hear this text.
  • Paragraph element. You should hear this text.

Instead, I hear:

  • Paragraph element. You should hear this text.
  • Paragraph element. You should hear this text.
  • Paragraph element. You should hear this text. Title attribute of hidden span element. You should not hear this text.

I don’t know for certain that this is unexpected behavior, although I know that I personally expected different behavior.

How Many People Does It Take To Silence an Alarm System?

This is my fourth logbook entry for my Human-Computer Interaction (HCI) course.

A few weeks ago on a Sunday morning, a piercing, ear-splitting din pervaded my apartment: the fire alarm. This is not anything like your typical household smoke detector: smoke detectors are merely loud. This sound causes pain. We managed to scoop up the cat and shove her into her carrier and head outside. Fortunately, it was a false alarm: workers in the restaurant on the ground floor of my building accidentally triggered the alarm system.

The fire department arrived and confirmed that, indeed, there was no fire. However, they did not have the code to turn off the alarm. Neither did the employees at the restaurant. I called the maintenance number for our building who relayed the top-secret code that would reset the alarm: 1-2-3-4.
Continue reading How Many People Does It Take To Silence an Alarm System?

Big Belly Trash Cans and Usability

This is my third logbook entry for my Human-Computer Interaction (HCI) course.

A few years ago, Philadelphia replaced many of the garbage cans with BigBelly Solar trash compactors.

Big Belly Solar Trash Compactors
2 recycling bins and a solar compactor in Penn Park

I’d first seen Big Belly at a park in Chicago. It seemed like a great idea: the smart trash can compacts refuse so that it needs to be collected less frequently, and even sends out a signal to the grounds crew when it is full, so that there’s never an overflowing trash receptacle (the latter was a big problem in Philly, especially on weekends).

Time Magazine recently ran an article on BigBelly (“Trash Talk“), particularly citing their success in Philadelphia. I still think the solar compactors are a great improvement over the overflowing trash cans of years past. The streets are cleaner, and they save money. But from a resident’s perspective, I think they have room for improvement.
Continue reading Big Belly Trash Cans and Usability

Moving SharePoint sites using stsadm.exe

I recently needed to move a SharePoint site from one site collection to another. Fortunately, this is very easy to do using the stsadm tool (located in the bin directory of the 14 hive).

Following the instructions at Using Stsadm.exe to Migrate Site Data (a SharePoint 2007 document, but still applicable to SharePoint 2010), I used the stsadm export command from the 14 hive with the following parameters:

bin\stsadm.exe -o export -includeusersecurity -versions 4 -url 'https://mysite.url/oldcollection/myweb' -filename myweb.cmp

However, that returned the following error message:
Syntax error in argument: url

If you drop the quotation marks around the URL, it works:
bin\stsadm.exe -o export -includeusersecurity -versions 4 -url https://mysite.url/oldcollection/myweb -filename myweb.cmp

(I find that really unbelievable. Text parameters almost always appear as quoted values. Even if it doesn’t need the quotes, you’d still expect it to accept the quotes!)

The instructions for the export command mention cabsize but don’t indicate the default:
-cabsize <integer>
Specifies the maximum size of the .cmp file in megabytes. The range is from 1 to 1024 MB. If the export data exceeds the maximum specified, the data is split into multiple files."

For the site I was working with, the export command saved the site as 4 files, each around 25 megabytes. I decided I would prefer a single .cmp file (and the site I was exporting did not exceed 1024Mb) so I increased the cabsize to the maximum:
bin\stsadm.exe -o export -cabsize 1024 -includeusersecurity -versions 4 -url 'https://mysite.url/oldcollection/myweb' -filename myweb.cmp

To import the site into the new site collection, run the import command:
bin\stsadm.exe -o import -url https://mysite/newcollection/myweb/ -filename myweb.cmp

Once you’ve moved the site–and checked the new location to make sure everything worked–don’t forget to delete the old site and the .cmp file.

Javascript Array Sort & Random Ordering

Recently a colleague and I were looking at some Javascript code that randomizes a list of elements. The code did this by creating an array of list-item elements, and then passing a comparison function that returns a random result to the array.sort() method. Unfortunately, the random order was anything but random: after reloading the page 50 times, the distribution was skewed heavily towards the original array ordering.

In case you don’t feel like reading my entire exploration of this topic, I’ll give you the short version:
Don’t use array.sort() to randomize arrays! There are methods of randomizing arrays that produce better (i.e. more random) results, and that are (probably) faster.
Continue reading Javascript Array Sort & Random Ordering

Center City Philadelphia’s Lack of Pedestrian Signals

This is my second log-entry for my Human-Computer Interaction class this summer.

When I first moved to Center City, Philadelphia, one thing that struck me as odd was the use of regular traffic lights as pedestrian signals. Even at the intersection of two one-way streets, there would be traffic signals in all four directions. There are generally not separate pedestrian signals.


Pedestrian signals in Center City, Philadelphia

While you will find separate pedestrian signals at broad intersections, these are the exceptions rather than the rule. (Perhaps other cities do this too, but if so I have not taken notice.)

After living here for years, it very quickly becomes a part of the landscape and no longer seems abnormal. But I took notice again this year on the 4th of July: a big holiday in Philadelphia that draws a lot of tourists. I noticed a fair number of confused pedestrians, but also a couple of drivers who attempted to drive the wrong way down one-way streets.

It is a convention at most intersections in most cities that if one direction has a visible traffic light, traffic is expected to flow in that direction. Drivers from out-of-town, many of whom are not used to one-way streets, see these pedestrian signals and think they indicate the direction of traffic. But really, it’s only foot traffic, on the sidewalk, that flows that direction. Sure, there are other visible signs: one-way signs and cars parked facing only the opposite direction. In the absence of immediate oncoming traffic, though, those signals can really send the wrong signal.

Why did Philadelphia choose to use the usual automobile traffic signals for pedestrian signals? I assume it saves money: not that the signals themselves are necessarily more costly, but that one computer/controller–or perhaps a simpler controller–can manage each intersection. I don’t really know the reason, though. I definitely feel that it is a mistake to break such a common convention. On the other hand, though I have seen confused pedestrians and drivers, I have yet to see an accident caused by this confusion.Rental

Ambiguous “On” Indicators on Television Sets and Monitors

I’m currently taking a course on Human-Computer Interaction (HCI). The instructor advised us to keep logs of things we notice in the world that relate to the course material. This is one of my log entries.

One item I noticed today was the On indicator on a Samsung television at work. It’s a large flat-panel screen that we have connected to a PC for presentation purposes in a small conference room. I was preparing for a presentation and sat down at the keyboard and mouse. The power light glowed amber, so I wiggled the mouse. Nothing. I pressed CTRL-ALT-DEL. Nothing. I checked to make sure that the PC was on, and then I checked to make sure the cables were connected. Everything looked correct–why wasn’t the screen getting a signal?

Bottom panel of a television set displaying an amber light. Note that although the indicator light is near the power symbol, it could be much closer.

Continue reading Ambiguous “On” Indicators on Television Sets and Monitors