<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The Accidental Developer</title>
	<atom:link href="http://osric.com/chris/accidental-developer/feed/" rel="self" type="application/rss+xml" />
	<link>http://osric.com/chris/accidental-developer</link>
	<description>What if Gregor Samsa awoke a computer programmer?</description>
	<lastBuildDate>Mon, 30 Apr 2012 21:16:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Grammars and the Random Goth Lyric Generator</title>
		<link>http://osric.com/chris/accidental-developer/2012/04/grammars-and-the-random-goth-lyric-generator/</link>
		<comments>http://osric.com/chris/accidental-developer/2012/04/grammars-and-the-random-goth-lyric-generator/#comments</comments>
		<pubDate>Mon, 30 Apr 2012 00:34:09 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Games]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[formal language]]></category>
		<category><![CDATA[grammars]]></category>
		<category><![CDATA[natural language]]></category>
		<category><![CDATA[random]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=696</guid>
		<description><![CDATA[To celebrate one of the last day&#8217;s of National Poetry Month as well as The Accidental Developer&#8217;s 100th blog post, I will attempt to combine a bit of computer science and poetry. I&#8217;ve been studying grammars and formal languages, among other things, this past semester in my Theory of Computation class. One thing that it [...]]]></description>
			<content:encoded><![CDATA[<p>To celebrate one of the last day&#8217;s of National Poetry Month as well as The Accidental Developer&#8217;s 100th blog post, I will attempt to combine a bit of computer science and poetry.</p>
<p>I&#8217;ve been studying grammars and formal languages, among other things, this past semester in my Theory of Computation class. One thing that it reminded me of was the second Javascript application I ever developed (with the help of my friend and college classmate Miranda Tarrow): The <a href="http://osric.com/rglg/">Random Goth Lyric Generator</a>.</p>
<p>I took a simple sentence structure (subject, verb, adjective, object) and made random substitutions for each line, 4 lines per stanza, 4 stanzas per poem.</p>
<p>The (slightly less-than-formal) grammar for each line would look something like this:<br />
<code>Line -&gt; SSL | PSL<br />
SSL -&gt; SNP SV A O<br />
PSL -&gt; PNP PV A O<br />
SNP -&gt; Singular Noun | Singular Noun Phrase<br />
PNP -&gt; Plural Noun | Plural Noun Phrase<br />
SV -&gt; Singular Verb<br />
PV -&gt; Plural Verb<br />
A -&gt; Adjective<br />
O -&gt; Object</code></p>
<p>We could extend this to the entire poem:<br />
<code>Poem -&gt; Stanza Stanza Stanza Stanza<br />
Stanza - &gt; Line Line Line Line</code></p>
<p>The word list was meant to be dark and foreboding but was often hilarious&#8211;the examples included:</p>
<p><strong>Nouns &#038; Noun Phrases:</strong></p>
<ul>
<li>My solitude</li>
<li>Your touch</li>
<li>A ravenous she-wolf</li>
<li>Spiders</li>
</ul>
<p><strong>Verbs &#038; Verb Phrases:</strong></p>
<ul>
<li>entangles</li>
<li>summons</li>
<li>grovels before</li>
<li>spews forth</li>
</ul>
<p><strong>Adjectives:</strong></p>
<ul>
<li>labyrinthine</li>
<li>diseased</li>
<li>spectral</li>
<li>infernal</li>
</ul>
<p><em>Line -> SSL -> SNP SV A O</em> could become:</p>
<blockquote><p><em>Your touch entangles infernal spiders.</em></p></blockquote>
<p>I don&#8217;t know why the list of objects was a separate list of nouns, as it seems to me now that it could have pulled from the same list. Since the grammar used just one sentence structure, the results were very repetitive but frequently humorous. I often considered expanding the possible sentence structure (something as simple as making the adjective optional), but decided that the repetition was part of the charm. In fact, many poems and song lyrics feature repetition, and the results seemed eerily intentional at times.</p>
<p>The page was very popular for a time. I received quite a bit of e-mail regarding the page, including suggestions for additional words. Someone sent a song they&#8217;d recorded for which they used the random lyrics (with the addition of a shouted, <em>&#8220;There&#8217;s that m&#8212;&#8212;&#8212;&#8212; word again!&#8221;</em> in the middle). At least one randomly-generated poem was published in a small poetry journal.</p>
<p>I&#8217;ve considered creating a sequel to parody William Carlos Williams and loading it up with words from his own poems:<br />
<code>Poem -&gt; S1 S2 S3 S4<br />
S1 -&gt; Noun Verb newline Preposition<br />
S2 -&gt; Article Adjective Noun newline Noun<br />
S3 -&gt; Adjective Preposition Adjective newline Noun<br />
S4 -&gt; Preposition Article Adjective newline Noun</code></p>
<p>Which might produce something like:</p>
<blockquote><p>
<em>no one spilled<br />
with</p>
<p>the whole honey<br />
suckle</p>
<p>pressed after sweet<br />
odor</p>
<p>while the urgent<br />
petals</em></p></blockquote>
<p>It just doesn&#8217;t seem quite as funny or compelling. I can venture a guess that William&#8217;s sparse form and carefully selected language doesn&#8217;t lend itself to random imitation as well as verbose and self-indulgent free verse. Although perhaps the sample is merely too small!</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2012/04/grammars-and-the-random-goth-lyric-generator/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using FFmpeg to programmatically slice and splice video</title>
		<link>http://osric.com/chris/accidental-developer/2012/04/using-ffmpeg-to-programmatically-slice-and-splice-video/</link>
		<comments>http://osric.com/chris/accidental-developer/2012/04/using-ffmpeg-to-programmatically-slice-and-splice-video/#comments</comments>
		<pubDate>Sun, 29 Apr 2012 22:43:27 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Video]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[dependency hell]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[H.264]]></category>
		<category><![CDATA[ImageMagick]]></category>
		<category><![CDATA[mp4]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[video]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=690</guid>
		<description><![CDATA[My wife has a research project in which she needs to analyze brief (8-second) segments of hundreds of much longer videos. My goal was to take the videos (~30 minutes each) and cut out only the relevant sections and splice them together, including a static marker between each segment. This should allow her and her [...]]]></description>
			<content:encoded><![CDATA[<p>My wife has a research project in which she needs to analyze brief (8-second) segments of hundreds of much longer videos. My goal was to take the videos (~30 minutes each) and cut out only the relevant sections and splice them together, including a static marker between each segment. This should allow her and her colleagues to analyze the videos quickly and using precise time-points (instead of using a slider in a video player to locate and estimate time-points). I&#8217;ve posted my notes from this process below for my own reference, and in case it should prove useful to anyone else.</p>
<p>To my knowledge, the best tool for the job is <a href="http://ffmpeg.org/">FFmpeg</a>, an open source video tool. <span id="more-690"></span> FFmpeg provides much of the underlying processing functionality for other popular video tools, such as <a href="http://handbrake.fr/">Handbrake</a>, <a href="http://www.mirovideoconverter.com/">Miro</a>, and <a href="http://www.mplayerhq.hu">MPlayer</a>. Since you compile FFmpeg from source code, it should run on any system with a C compiler, including my OS X box. Unfortunately, it&#8217;s not the most user-friendly software package in the world.</p>
<p>The developers recommend using the latest version from <a href="http://git-scm.com/">Git</a> (which finally forced me to install Git, something I&#8217;d been meaning to do anyway). One <a href="http://stephenjungels.com/jungels.net/articles/ffmpeg-howto.html">how-to for FFmpeg on OS X</a> docs suggest that I&#8217;d also need <a href="http://lame.sourceforge.net/">LAME</a> in order to process audio. (The audio is irrelevant for my use case, so I didn&#8217;t bother with LAME.) But I couldn&#8217;t compile FFmpeg because, apparently, OS X doesn&#8217;t include GCC. To get GCC on OS X, the official Apple way, I needed XCODE from the <a href="https://developer.apple.com/technologies/tools/">Apple Developer Tools</a>. To get those you have to sign up for an Apple Developer account. Welcome to Dependency Hell, now featuring bureaucracy!</p>
<p>Hours later, I&#8217;ve compiled FFmpeg. However, the videos I&#8217;m dealing with are raw H.264 video files from a <a href="http://www.nightowlsp.com/Products/Complete-Kits/K-44500-C">Night Owl K-44500-C</a> surveillance system. Also, I want to save them as H.264-encoded MP4 files. That means I needed additional H.264 support&#8211;or, at least, I thought I did&#8211;from the <a href="http://www.videolan.org/developers/x264.html">x264</a> project. And you need <a href="http://yasm.tortall.net/">YASM</a> to compile x264.</p>
<p>I was actually unable to compile YASM from the Git repository, although I was able to compile it following the instructions in this <a href="https://trac.handbrake.fr/wiki/CompileGuide">Handbrake for Mac OS X guide</a>.</p>
<p>I recompiled FFmpeg with the &#8211;enable-libx264 and &#8211;enable-gpl switches:<br />
<code>./configure --enable-libx264 --enable-gpl<br />
make<br />
sudo make install</code></p>
<p>To select just the relevant portions of the video, I used the -ss (start/seek position) and -t (time/duration) flags, e.g.:<br />
<code>ffmpeg -f h264 -i input-video-file.264 -ss 180 -t 8 output-video-file.mp4</code></p>
<p>The above example takes 8 seconds of the input video starting at the 3-minute (180-second) mark.</p>
<p>However, when I played back the output, it played much too fast. The source videos included a timestamp, and about 4 seconds ticked by every for every second of video! It turned out that the source videos were recorded at 7 fps (frames per second). I added a flag to specify the framerate:<br />
<code>ffmpeg -f h264 -r:v 7 -i input-video-file.264 -ss 180 -t 8 output-video-file.mp4</code></p>
<p>After running this a few times for different 8 second segments, I needed to put the segments back together again. This is such a relatively common use-case that FFmpeg has instructions in their FAQ, <a href="http://ffmpeg.org/faq.html#How-can-I-join-video-files_003f">How can I join video files?</a>. The first method&#8211;concatenating MPEG-2 files&#8211;seemed like the easiest option. However, MPEG-2 doesn&#8217;t support the framerate (7 fps).</p>
<p>I tried the other suggested method of concatenating videos, using named pipes. This worked, although the BASH script was convoluted and very particular.</p>
<p>Another thing I wanted to add to the video was a separator&#8211;some static frames to divide each 8-second clip&#8211;and a title card. At first I created a JPEG and turned it into a 1-frame video, concatenated it with itself to create a 2-frame video, and then 4, 8, 16, etc. However, I discovered a much easier method of creating a video from a single image using the loop flag:<br />
<code>ffmpeg -f image2 -loop 1 -r:v 7 -i image.jpeg -pix_fmt yuv420p -an -t 2 image-movie.mpeg</code></p>
<p>(The pix_fmt flag was to set the correct color space, and the an flag ignores the audio channel.)</p>
<p>Now I had title cards, clip separators, and 8-second video clips that I could combine into a single video. But I needed to do this hundreds of times! I wrote a Python script to generate the appropriate BASH script based on the input filename. The BASH script would create the title cards and clip separators using <a href="http://www.imagemagick.org">ImageMagick</a>, and then call the appropriate FFmpeg commands to create and concatenate the video.</p>
<p>The ImageMagick commands look like this:<br />
<code>convert -size 704x480 -background SteelBlue1 -fill black -font Helvetica -pointsize 72 -gravity center label:[Video Title] titlecard.jpg</code></p>
<p>Then I used the find command to run the Python script on all the video files:<br />
<code>find *.264 -maxdepth 1 -exec ./process.sh '{}' \; -print</code></p>
<p>Eureka! It worked. Almost perfectly.</p>
<p><em>Almost.</em></p>
<p>Some (but not all) of the output videos would produce solid gray frames after a certain time point. Reviewing the FFmpeg output for those files, there was an error:<br />
<code>[h264 @ 0x9460340] FMO not supported</code></p>
<p>FMO stands for Flexible Macroblock Ordering, and based on the response to a <a href="http://roundup.libav.org/issue1440">libavcodec issue from 2009</a>, the FFmpeg developers don&#8217;t plan to support it (although one of the developers suggested that, if someone would like to create a software patch to enable FMO support, the community would welcome it).</p>
<p>I wrote to technical support for the camera system and asked if they had any suggestions. They replied that, although conversion to MPEG formats was not supported, they do provide a conversion utility to convert to AVI. I was able to successfully convert the AVIs to MP4s. An annoying extra step, but one that is only necessary in a subset of cases.</p>
<p>This solution took me several weeks to figure out, although it should save quite a bit of time in the long run.</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2012/04/using-ffmpeg-to-programmatically-slice-and-splice-video/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Robert Sedgewick: &#8220;Algorithms for the Masses&#8221;</title>
		<link>http://osric.com/chris/accidental-developer/2012/04/robert-sedgewick-algorithms-for-the-masses/</link>
		<comments>http://osric.com/chris/accidental-developer/2012/04/robert-sedgewick-algorithms-for-the-masses/#comments</comments>
		<pubDate>Tue, 10 Apr 2012 01:23:05 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[algorithms]]></category>
		<category><![CDATA[robert sedgewick]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=679</guid>
		<description><![CDATA[On 9 April 2012, I saw Robert Sedgewick give the talk, &#8220;Algorithms for the Masses,&#8221; on the campus of Drexel University. I have several of Sedgewick&#8217;s books on my shelves at home, including Algorithms in Java, Third Edition, Parts 1-5 and Introduction to Programming in Java: An Interdisciplinary Approach. One of my previous computer science [...]]]></description>
			<content:encoded><![CDATA[<p>On 9 April 2012, I saw Robert Sedgewick give the talk, &#8220;Algorithms for the Masses,&#8221; on the campus of Drexel University. I have several of Sedgewick&#8217;s books on my shelves at home, including <a href="http://www.amazon.com/gp/product/0201775786/ref=as_li_ss_tl?ie=UTF8&#038;tag=osriccom-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0201775786">Algorithms in Java, Third Edition, Parts 1-5</a><img src="http://www.assoc-amazon.com/e/ir?t=osriccom-20&#038;l=as2&#038;o=1&#038;a=0201775786" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /> and <a href="http://www.amazon.com/gp/product/0321498054/ref=as_li_ss_tl?ie=UTF8&#038;tag=osriccom-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0321498054">Introduction to Programming in Java: An Interdisciplinary Approach</a><img src="http://www.assoc-amazon.com/e/ir?t=osriccom-20&#038;l=as2&#038;o=1&#038;a=0321498054" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" />. One of my previous computer science professors, <a href="http://www.cis.uab.edu/sloan/">Kenneth Sloan</a>, counted Sedgewick among his classmates.</p>
<p>The basic thesis of the lecture was that <em>good algorithms matter</em> and that we need to champion good algorithms where they are most needed (particularly in the sciences).</p>
<p>One of his points was that computer science is currently very abstract and lacks a basis in the scientific method. Algorithms need to be tested against models to see how they actually perform. In some cases, the theoretical performance of an algorithm can be off by several orders of magnitude compared to actual performance. For example, the quicksort algorithm is quadratic (<em>N</em><sup>2</sup>) in the worst case, but <em>N</em> log <em>N</em> most of the time. There&#8217;s a reason why quicksort (by the way, the subject of Sedgewick&#8217;s 1975 PhD dissertation) is widely used, in spite of the fact that it is O(<em>N</em><sup>2</sup>) versus binary sort&#8217;s O(<em>N</em> log <em>N</em>).</p>
<p>Sedgewick said, though, that he has run into many computer scientists who fail to observe the difference between theoretical worst-case and actual performance. Some will choose an algorithm based on Big-O analysis alone. Sedgewick&#8217;s response: Big-O is an upper bound, but is your input an example of the worst-case? Probably not. Algorithms should be chosen based on their actual performance.</p>
<p>[As an alternative to Big-O notation, Sedgewick suggested <a href="http://introcs.cs.princeton.edu/java/41analysis/">Tilde notation</a>, although from my perspective I don't see that there is a great difference between them.]</p>
<p>He also gave an example of taking theory too far in the other direction. A computer scientist gave a talk demonstrating that his algorithm, Algorithm B, though exceedingly complex, was superior to the simpler Algorithm A. When Sedgewick asked him why, he explained that Algorithm B removed a log log <em>N</em> factor. Sedgewick&#8217;s analysis was that log log <em>N</em>, in this universe, amounts to 6 &#8212; hardly worth trading algorithms for what, realistically, amounts to a constant factor.</p>
<p>[Why 6? Wikipedia and other sources estimate the <a href="http://en.wikipedia.org/wiki/Observable_universe#Matter_content">number of atoms in the observable universe</a> at 10<sup>80</sup>. The natural logarithm of 10<sup>80</sup> is 184. The natural logarithm of 184 is 5.2. 6 sounds like a fine estimate.]</p>
<p>Another point was that scientists often need algorithms in their daily work, but do things the hard way for a lack of knowledge. One example was a biologist who was trying to use Excel to calculate a standard deviation for over a million data points, an idea that caused several audience members to cringe.</p>
<p>How do we bring a better understanding of algorithms to the masses? (By masses, I think he really means the masses of college-educated scientists&#8211;not quite everyone, but still a much larger group than just computer scientists.) He had several suggestions:</p>
<p><strong>Analytic Combinatorics</strong><br />
From what I gather, analytic combinatorics is a way of using formal languages to describe recurrence relations, and thus a simpler (and easier-to-teach) method of creating generating functions. I don&#8217;t exactly know what that means, but you can read the book on it (by Flajolet and, of course, Sedgewick): <a href="http://algo.inria.fr/flajolet/Publications/book.pdf">Analytic Combinatorics</a> (PDF).</p>
<p><strong>Testing Algorithms Empirically</strong><br />
In computer science classes, he suggests students run a program on an increasing series of inputs (e.g. n = { 1000, 2000, 4000, 8000, 16000, &#8230; }) and examining the ratios of input size to run times to understand the real impact of running in linear time, N log N time, quadratic time, etc. (This is something that some of my past computer science courses have included, so apparently they have already adopted this piece of Sedgewick&#8217;s advice.)</p>
<p><strong>Changing Intro to CS Courses</strong><br />
Sedgewick recommends identifying core elements of computer science, such as classic algorithms, and teaching them to everyone as early as possible. Some changes made to the curriculum at Princeton (where Sedgewick teaches) have led to a dramatic increase in enrollment in intro computer science courses and from a wider range of majors.</p>
<p><strong>Change Publishing</strong><br />
Sedgewick touted his Introduction to Programming in Java and its <a href="http://introcs.cs.princeton.edu/java/home/" title="Companion web site to the book, Introduction to Programming in Java">accompanying web site</a> as a major change for textbooks. The programming examples are short and simple, but demonstrate a wide range of real-world applications across several branches of science. (Although he did not mention it in the lecture, I also appreciated that the examples in this book often include graphics, sound, and animation &#8212; which are far more thrilling results than the usual ASCII that intro CS students see as the fruits of their labors.)</p>
<p>He also criticized academic publishing for making journal articles look as much like boring print articles as possible, in spite of the fact that they are now primarily accessed online. Where are the full-color figures? The hyperlinks? Animated simulations? These things are all possible online, but instead publishers restrict content to the form that is least likely to be accessed.</p>
<p>Several times in the lecture, he also mentioned that freshly-minted computer scientists often have little or no background in science: no physics, no chemistry, no biology. Although he recognized this as a problem, he had no solutions (other than to, perhaps, require foundational science courses as part of a CS degree).</p>
<p>The last two items&#8211;changing the curriculum and publishing&#8211;really sounded like a Sedgewick paid-programming infomercial. &#8220;Everyone should take courses in the subject of which I am an expert, and they should use the book I wrote to teach it.&#8221; It was hard not to be a little skeptical of his motives. At the same time, I can&#8217;t help but think that he&#8217;s right.</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2012/04/robert-sedgewick-algorithms-for-the-masses/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using a list or array as a PowerShell script input parameter</title>
		<link>http://osric.com/chris/accidental-developer/2012/03/using-a-list-or-array-as-a-powershell-script-input-parameter/</link>
		<comments>http://osric.com/chris/accidental-developer/2012/03/using-a-list-or-array-as-a-powershell-script-input-parameter/#comments</comments>
		<pubDate>Thu, 15 Mar 2012 22:51:21 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[sharepoint 2010]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=653</guid>
		<description><![CDATA[One of my colleagues created a PowerShell script that we use to migrate SharePoint 2010 sites from the SharePoint 2007 interface (UI 3) to the SharePoint 2010 interface (UI 4). The script works rather well for updating one or two sites at a time: Set-UserInterface2010.ps1 -url "https://my.sharepoint.site/path/" Today I received a request to update a [...]]]></description>
			<content:encoded><![CDATA[<p>One of my colleagues created a PowerShell script that we use to migrate SharePoint 2010 sites from the SharePoint 2007 interface (UI 3) to the SharePoint 2010 interface (UI 4). The script works rather well for updating one or two sites at a time:</p>
<p><code>Set-UserInterface2010.ps1 -url "https://my.sharepoint.site/path/"</code></p>
<p>Today I received a request to update a list of 32 sites. After updating one, I thought&#8211;this is going to be tedious. We can improve this.</p>
<p>First, I updated the parameter to accept an array of strings instead of a single string.</p>
<p><strong>Before</strong><br />
<code>param([string]$url = $(throw "Please specify a Site URL to convert to the SP2010 look and feel"))</code></p>
<p><strong>After</strong><br />
<code>param([string[]]$url = $(throw "Please specify a Site URL to convert to the SP2010 look and feel"))</code></p>
<p>Next, I wrapped the call to the main function in a ForEach loop:<br />
<code>ForEach ( $siteurl in $url ) {<br />
...<br />
# Throw in a line break to separate output<br />
Write-Host ("`n`n")<br />
}</code></p>
<p>The script can still take a single site as input (the string is treated as a string array with a single element), but now I can also pass it a list:</p>
<p><code>Set-UserInterface2010.ps1 -url "https://my.sharepoint.site/path1/","https://my.sharepoint.site/path2/","https://my.sharepoint.site/path3/"</code></p>
<p>Here&#8217;s hoping that taking a couple minutes to update the script and running it once saved me more time than running it 32 times!</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2012/03/using-a-list-or-array-as-a-powershell-script-input-parameter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Douglas Crockford: &#8220;Programming Style and Your Brain&#8221;</title>
		<link>http://osric.com/chris/accidental-developer/2012/01/douglas-crockford-programming-style-and-your-brain/</link>
		<comments>http://osric.com/chris/accidental-developer/2012/01/douglas-crockford-programming-style-and-your-brain/#comments</comments>
		<pubDate>Sat, 28 Jan 2012 23:13:31 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Douglas Crockford]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=632</guid>
		<description><![CDATA[Douglas Crockford provided many examples of error-resistant Javascript in his 13 January 2012 talk, "Programming Style and Your Brain." Here's a summary of the talk and 3 of the specific Javascript examples Crockford provided.]]></description>
			<content:encoded><![CDATA[<p>On 13 January, 2012, I saw Javascript expert <a href="http://www.crockford.com/">Douglas Crockford</a> deliver a talk titled &#8220;Programming Style and Your Brain&#8221; on the campus of the University of Pennsylvania. The brain portion of the talk (which Mr Crockford said borrowed heavily from Daniel Kahneman&#8217;s book <em><a href="http://www.amazon.com/gp/product/0374275637/ref=as_li_ss_tl?ie=UTF8&#038;tag=osriccom-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0374275637">Thinking, Fast and Slow</a><img src="http://www.assoc-amazon.com/e/ir?t=osriccom-20&#038;l=as2&#038;o=1&#038;a=0374275637" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></em>) was really just to emphasize that human beings have 2 distinct ways of thinking: Head (slow) and Gut (fast). Computer programming requires some of both, but the same Gut-thinking that can provide useful insights can sometimes also lead us astray.</p>
<p>For example, programmers have been arguing since the 1970s about the placement of curly braces. Some people prefer:</p>
<p><code>if ( true ) {<br />
    doSomething();<br />
}</code></pre>
<p>Others prefer:</p>
<p><code>if ( true )<br />
{<br />
    doSomething();<br />
}</code></p>
<p>Crockford says that if the compiler treats these 2 forms as equivalent, then there is really no difference (so long as you are consistent). These are Gut decisions. However, people will use their Head to try to rationalize their Gut decisions and come up with some ridiculous rationalizations.</p>
<p>OK, fine. What does that mean in practical terms, i.e. writing code?<br />
<span id="more-632"></span><br />
Crockford's advice is:</p>
<blockquote><p><strong><em>Prefer forms that are error-resistant.</em></strong></p></blockquote>
<p>This is aligned closely with my own advice:</p>
<blockquote><p><strong><em>Prefer explicit forms to implicit forms.</em></strong></p></blockquote>
<p>One of Crockford's illustrations (which I have not verified but sounds plausible enough) is that the space character was introduced into Latin writing after the prior practice of running all the words together led to ambiguity and transcription errors. The space characters made the text more explicit, and therefore less prone to transcription error.</p>
<p>Here are 3 of the Javascript examples Crockford provided during his talk:</p>
<p><strong>Curly Braces &#038; Conditional Statements and Loops</strong><br />
In Javascript, a conditional statement or a loop containing only one statement can be written without curly braces:<br />
<code>if ( condition ) doSomething();</code></p>
<p>This form is error-prone. Include the curly braces:<br />
<code>if ( condition ) {<br />
    doSomething();<br />
}</code></p>
<p>Some people might complain and say that this is less concise and requires extra typing. Crockford's response was: less concise is better, and the majority of the time it takes to write a program is in thinking, not typing. If adding a few characters is slowing you down, you either need to take a typing class or spend more time thinking!</p>
<p><strong>Double-Equals versus Triple-Equals</strong><br />
Crockford said that using double-equals (==) to compare objects is <em>always</em> a bad idea because it does implicit type conversion. For example:<br />
<code>var n = 5;<br />
n == 5; //true<br />
n == "5"; // true<br />
n === "5"; // false<br />
n === 5; // true</code></p>
<p>The triple-equals also helps developers know that a number is expected, not a character or other data type.</p>
<p>As Crockford emphasized:</p>
<blockquote><p><strong><em>If a feature is sometimes problematic, and a more reliable feature exists, use it!</em></strong></p></blockquote>
<p>Some people might try to justify the use of implicit type conversion: "But I'm doing it intentionally!" Crockford said that relying on implicit type conversion means you don't know what you're doing.</p>
<p><strong>Incrementing Values</strong><br />
Crockford said he never uses the prefix or postfix ++ operator, because many people don't understand the difference and it can lead to confusion. For example:<br />
<code>var x = 5;<br />
var y = x++; // y is now 5 and x is 6<br />
var z = ++x; // z is now 7 and x is 7<br />
x += 1; // x is now 8. This is Crockford's preferred method to increment a variable</code></p>
<p>Crockford provides several resources to help people write better, more error-resistant Javascript:</p>
<ul>
<li><a href="http://javascript.crockford.com/code.html">Code Conventions for the JavaScript programming language</a></li>
<li><a href="http://www.jslint.com/">JSLint</a>, which alerts you to errors in your code or error-prone code ("JSLint <em>will</em> hurt your feelings")</li>
<li><a href="http://javascript.crockford.com/jsmin.html">JSMin</a>, which "minifies" (removes unnecessary characters) from Javascript files. This should be largely unnecessary if your web server uses <a href="http://developer.yahoo.com/performance/rules.html#gzip">Gzip compression</a>.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2012/01/douglas-crockford-programming-style-and-your-brain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Test-Driven Programming Assignments</title>
		<link>http://osric.com/chris/accidental-developer/2012/01/test-driven-programming-assignments/</link>
		<comments>http://osric.com/chris/accidental-developer/2012/01/test-driven-programming-assignments/#comments</comments>
		<pubDate>Thu, 26 Jan 2012 02:22:41 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[JUnit]]></category>
		<category><![CDATA[TDD]]></category>
		<category><![CDATA[test-driven development]]></category>
		<category><![CDATA[unit tests]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=601</guid>
		<description><![CDATA[Is consuming unit tests as good an introduction to test-driven development as writing your own unit tests? In some ways, it may even be better.]]></description>
			<content:encoded><![CDATA[<p>I am enrolled in another graduate course this semester, Theory of Computation. Like last semester, the programming assignments include unit tests (<a href="http://www.junit.org/">JUnit</a> tests for the Java assignments). One can be very confident prior to submitting an assignment that it is done properly if it passes all the unit tests!</p>
<p>I&#8217;ve been interested in unit testing and test-driven development for several years now, but have never put it into practice. It seemed like a good idea in theory, but it required picking a testing framework, installing it, configuring it, and, of course, writing good tests. Without any hands-on experience, it&#8217;s a difficult practice to adopt. Getting introduced to unit tests this way lifts nearly all those burdens. On top of that, the advantages are clear: the tests will tell you when you have it right.</p>
<p>I was a little surprised to run into unit testing via coursework, because I&#8217;d been under the impression that computer science education focuses a lot on theory, and skips over a lot of the practice. I&#8217;ve met a lot of people coming out of computer science programs who, while probably excellent theorists, don&#8217;t know heads from tails when you sit them at a terminal. I was happy to see that my coursework included practical knowledge as well.</p>
<p>All the unit tests are provided by the professor. I assume we may write some tests of our own later on&#8211;and certainly nothing is stopping us from writing our own tests now&#8211;but I do wonder how many students will be prepared to take that next step. From what I understand, writing good tests is the better part of successful unit testing.</p>
<p>Some things I&#8217;ve noticed about the provided unit tests:</p>
<ul>
<li>There are <em>a lot</em> of them. The unit tests are half as long the code that passes them.</li>
<li>There are many sample values to test the same function, mostly to test specific <a href="http://en.wikipedia.org/wiki/Edge_case">edge cases</a>. Failure at a specific edge case helps to identify where the code went wrong.</li>
<li>In some cases, the tests are within a loop that generates random test data. Although there&#8217;s nothing quite like real human input to break your programs, 1000 random tests might help.</li>
</ul>
<p>In practice, do programmers tend to write their own unit tests? I imagine it would be ideal if you partnered with someone, and you wrote their unit tests, and they wrote yours. It might be easy to overlook an edge case or dismiss something as impossible if you are too involved with the specifications. At the same time, it is probably difficult to write a unit test without spending some time reading the specifications and understanding exactly what it is supposed to do.</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2012/01/test-driven-programming-assignments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>When should alt text be blank?</title>
		<link>http://osric.com/chris/accidental-developer/2012/01/when-should-alt-text-be-blank/</link>
		<comments>http://osric.com/chris/accidental-developer/2012/01/when-should-alt-text-be-blank/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 00:51:42 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[accessibility]]></category>
		<category><![CDATA[alt]]></category>
		<category><![CDATA[JAWS]]></category>
		<category><![CDATA[WCAG]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=386</guid>
		<description><![CDATA[Although HTML image elements (img) are required to have alt text, the recommendations on how to use alt text are vague. Linked graphics should have descriptive alt text. Decorative graphics should have blank (empty) alt text. But what about graphics that don't convey pertinent information, such as a photograph of a corporate headquarters?]]></description>
			<content:encoded><![CDATA[<p>The <em>alt</em> attribute of an image element is a required HTML attribute (see <a href="http://www.w3.org/TR/html401/struct/objects.html#edef-IMG">the IMG element</a>). If it is not present, screen-reader software will typically read the <em>src</em> attribute instead. Text-based user agents such as Lynx, or browsers that allow users to disable images, will also typically use the <em>src</em> attribute in the absence of the <em>alt</em> attribute.</p>
<p>I had always heard that, unless the image conveys important information (e.g. a graphic of text used as navigation, or a chart or graph) that the alt text should be left blank:<br />
<code>&lt;img src="myimage.png" alt="" /&gt;</code></p>
<p>A screen-reader passes such an image over without saying anything. This makes sense to me. When I&#8217;ve closed my eyes and tried navigating the web using a screen-reader like <a href="http://www.freedomscientific.com/products/fs/jaws-product-page.asp">JAWS</a>, anything non-essential was a distraction and just got in my way. Knowing that a page contained an image of, say, a corporate headquarters in no way helped me understand the page content.</p>
<p>However, a colleague of mine suggested that the alt text should describe, briefly, the image. He offered a compelling use case: you are browsing on your mobile device with images disabled, due to bandwidth. How would you know if there was an image that you did want to view if no description was provided? This is a case where the alt text can provide a better user experience for users without vision impairments. But does it make the experience worse for users with vision impairments using assistive technology?</p>
<p>(A case could be made that vision-impaired users should also know there is an image on the page for orientation purposes: &#8220;The link to the annual report is underneath the photo of the corporate headquarters.&#8221; However, what may appear <em>above</em> or <em>below</em> on screen may not make sense when page content is read linearly.)</p>
<p>I looked to the <a href="http://www.w3.org/TR/WCAG/#text-equiv">WCAG 2.0 section on text alternatives</a>, which states that images used for decoration or formatting should be implemented in such a way that they &#8220;can be ignored by assistive technology.&#8221; That&#8217;s a good case for using an empty <em>alt</em> attribute. If the image is <em>sensory</em> (WCAG 2.0 has been criticized for being vague&#8211;obviously anything visual is sensory), then the item should &#8220;at least provide descriptive identification of the non-text content.&#8221;</p>
<p>What about that photo of the corporate headquarters then? It&#8217;s decorative, but not in the same way as a fleuron or a border. It may not be an inspiring image, but maybe it should have associated alt text.</p>
<p>I decided to check 4 sites that I thought might demonstrate best-practice, but found little consistency across these examples:</p>
<ul>
<li><a href="http://www.nfb.org/">The National Federation for the Blind</a> &#8211; they use rather extensive alt text for the main image on their homepage: &#8220;Graphic consisting of two photos. On left is a group of children with white canes on a hayride. Right is a close-up of a finger reading Braille.&#8221; However, they fail to use the <em>alt</em> attribute for their menu divider graphic, which is clearly a decorative element.</li>
<li><a href="http://www.freedomscientific.com/products/fs/jaws-product-page.asp">Freedom Scientific&#8217;s JAWS Screen Reading Software</a> &#8211; the alt text &#8220;A student uses JAWS to do work on a desktop computer&#8221; accompanies a photo of a man at a computer. Decorative images (menu dividers, stars) use an empty string for the alt text.</li>
<li><a href="http://webaim.org/services/">WAIM &#8211; Web Accessibility in Mind</a> &#8211; they avoid the issue on their services page by inserting the pictures as CSS background images. These would not appear at all to a screen reader, to a text-based browser, or to a user agent with images disabled. This would be functionally equivalent to using empty alt text.</li>
<li><a href="http://www.ssa.gov/disability/">The Social Security Administration&#8217;s Disabilities Benefits</a> &#8211; this page gets it <em>completely</em> wrong, including alt text for images that do not even appear visible to users with normal vision (e.g. a tracking image with the alt text &#8220;DCSIMG&#8221; and a spacer image with the alt text &#8220;blank space&#8221;).</li>
</ul>
<p><a href="http://web.mit.edu/atic/www/accessibility/guidelines.html">MIT&#8217;s general web-accessibility guidelines</a> offer some additional guidance:</p>
<blockquote><p>ALT tags are often misused, mostly people overuse them. It&#8217;s better to leave the ALT tag blank (ALT=&#8221;") then to enter a text description that&#8217;s not useful or is redundant. For example an image with a caption below it does not need alt text that matches the caption, leave the alt text blank to avoid redundancy.</p></blockquote>
<p><a href="http://www.umich.edu/webaccess/best/quickguide.html#alt">The University of Michigan&#8217;s Accessibility Quick Guide</a> suggests using empty alt text for <em>non-informative</em> images.</p>
<p>Unfortunately, we&#8217;re still left with a rather vague recommendation: use a description when <em>useful</em> or <em>informative</em>. How do we decide when a description is <em>useful</em> or <em>informative</em>? My gut feeling is to agree with MIT: it should be left blank in most cases (such as with the hypothetical photograph of a corporate headquarters), but I think no great harm is done if a brief description is included.</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2012/01/when-should-alt-text-be-blank/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Updating a Windows timestamp</title>
		<link>http://osric.com/chris/accidental-developer/2011/12/updating-a-windows-timestamp/</link>
		<comments>http://osric.com/chris/accidental-developer/2011/12/updating-a-windows-timestamp/#comments</comments>
		<pubDate>Thu, 01 Dec 2011 21:38:31 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Tips & Tricks]]></category>
		<category><![CDATA[cygwin]]></category>
		<category><![CDATA[file attributes]]></category>
		<category><![CDATA[modified date]]></category>
		<category><![CDATA[timestamp]]></category>
		<category><![CDATA[touch]]></category>
		<category><![CDATA[windows]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=508</guid>
		<description><![CDATA[Let&#8217;s say you need to modify the timestamp, or last modified date, on a Windows file. In my case, I wanted to change the last modified date on a lot of PDF files, so that the last modified attribute would reflect the date the content was last modified (rather than the file). The best and [...]]]></description>
			<content:encoded><![CDATA[<p>Let&#8217;s say you need to modify the timestamp, or last modified date, on a Windows file. In my case, I wanted to change the last modified date on a lot of PDF files, so that the last modified attribute would reflect the date the <em>content</em> was last modified (rather than the <em>file</em>).</p>
<p>The best and easiest way I&#8217;ve found to do this is via <a href="http://www.cygwin.com/">Cygwin</a>:<br />
<code>touch -t 201109201145 *.pdf</code></p>
<p>When I searched for how to accomplish this, I found all sorts of sites advising me to download a $20 shareware application, or write a C# application to do it. Fortunately, in a *nix type environment, it&#8217;s a one-line command.</p>
<p>There are other ports of Unix/Linux/*nix commands for Windows, some of which may be more lightweight than Cygwin. (I rely on Cygwin quite a bit, so I have it installed on all my Windows machines.) I have not used any of the following, but here are links to some alternatives, in case you are interested:</p>
<ul>
<li><a href="http://www.gnu.org/software/coreutils/">Core Utils</a></li>
<li><a href="http://gnuwin32.sourceforge.net/packages/coreutils.htm">GNU Win32 Core Utils</a></li>
<li><a href="http://unxutils.sourceforge.net/">Unx Utils</a></li>
<li><a href="http://sourceforge.net/projects/touchforwindows/">Touch for Windows</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2011/12/updating-a-windows-timestamp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SharePoint error when editing a wiki page: Sys.WebForms.PageRequestManagerServerException: An unexpected error has occurred</title>
		<link>http://osric.com/chris/accidental-developer/2011/11/sharepoint-error-when-editing-a-wiki-page-sys-webforms-pagerequestmanagerserverexception-an-unexpected-error-has-occurred/</link>
		<comments>http://osric.com/chris/accidental-developer/2011/11/sharepoint-error-when-editing-a-wiki-page-sys-webforms-pagerequestmanagerserverexception-an-unexpected-error-has-occurred/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 23:56:59 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[sharepoint 2010]]></category>
		<category><![CDATA[wiki]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=579</guid>
		<description><![CDATA[I&#8217;ve had an ongoing problem where some users, when clicking the Edit Page button on a SharePoint 2010 wiki page, get the following error: Sys.WebForms.PageRequestManagerServerException: An unexpected error has occurred I found a couple blog posts about this suggesting a permissions issue (which made sense, as users in other groups could successfully edit pages): SP2010/Wiki [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve had an ongoing problem where some users, when clicking the <em>Edit Page</em> button on a SharePoint 2010 wiki page, get the following error:</p>
<p><a href="http://osric.com/chris/accidental-developer/wp-content/uploads/2011/11/sharepoint-wiki-unexpected-error.png"><img src="http://osric.com/chris/accidental-developer/wp-content/uploads/2011/11/sharepoint-wiki-unexpected-error.png" alt="" title="sharepoint-wiki-unexpected-error" width="447" height="171" class="alignnone size-full wp-image-585" /></a></p>
<p><code>Sys.WebForms.PageRequestManagerServerException: An unexpected error has occurred</code></p>
<p>I found a couple blog posts about this suggesting a permissions issue (which made sense, as users in other groups could successfully edit pages):</p>
<ul>
<li><a href="http://blogs.technet.com/b/sharepointjoe/archive/2011/01/19/sp2010-wiki-pages-quot-sys-webforms-pagerequestmanagerservererrorexception-an-unexpected-error-occured-quot-when-editing-a-page.aspx">SP2010/Wiki Pages: &#8220;Sys.WebForms.PageRequestManagerServerErrorException: An unexpected error occured.&#8221; when editing a page</a></li>
<li><a href="http://allthingssharepoint.blogspot.com/2011/06/syswebformspagerequestmanagerserverexce.html">Sys.WebForms.PageRequestManagerServerException error when editing pages</a></li>
</ul>
<p>Both sites suggested that an <em>Access Denied</em> message should appear in the ULS logs. However, no such message appeared in relation to my errors.</p>
<p><strong>ULS entry:</strong><br />
<code>System.NullReferenceException: Object reference not set to an instance of an object.<br />
at Microsoft.SharePoint.Publishing.WebControls.MediaWebPart.get_WebPartAdderId()<br />
at Microsoft.SharePoint.Publishing.WebControls.InsertMediaRibbonButton.RegisterRequiredScripts()<br />
at Microsoft.SharePoint.Publishing.WebControls.InsertMediaRibbonButton.OnPreRender(EventArgs e)<br />
at System.Web.UI.Control.PreRenderRecursiveInternal()<br />
at System.Web.UI.Control.PreRenderRecursiveInternal()<br />
at System.Web.UI.Control.PreRenderRecursiveInternal()<br />
at System.Web.UI.Control.PreRenderRecursiveInternal()<br />
at System.Web.UI.Control.PreRenderRecursiveInternal()<br />
at System.Web.UI.Control.PreRenderRecursiveInternal()<br />
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint...	1317dffd-b607-4f1c-9145-b4adc1d364ba</code></p>
<p>The MediaWebPart. SharePoint 2010 added a video/audio insertion feature on the ribbon, and the error occurred when trying to add the button.</p>
<p>It turns out, the permissions to the Web Part Gallery had been customized (i.e. broken inheritance from the parent site collection), and some groups who had permission to edit wiki pages did not have read permission for the Web Part Gallery (and, consequently, the MediaWebPart). Adding Restricted Read access for the group in question (to either the MediaWebPart or to the Web Part Gallery) solved this problem.</p>
<p>I don&#8217;t imagine this will be a common problem for other people, but I thought it worth mentioning.</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2011/11/sharepoint-error-when-editing-a-wiki-page-sys-webforms-pagerequestmanagerserverexception-an-unexpected-error-has-occurred/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Displaying numeric fields in SharePoint 2010 without commas</title>
		<link>http://osric.com/chris/accidental-developer/2011/11/displaying-numeric-fields-in-sharepoint-2010-without-commas/</link>
		<comments>http://osric.com/chris/accidental-developer/2011/11/displaying-numeric-fields-in-sharepoint-2010-without-commas/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 23:41:19 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[formatting]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[sharepoint 2010]]></category>
		<category><![CDATA[SharePoint Designer]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=570</guid>
		<description><![CDATA[The number field in a SharePoint list gives you a few basic formatting options (# of decimal places, include % sign), but automatically adds a comma as a thousands-separator. For some numeric data, e.g. Year of Publication, this would be inappropriate. This article describes 2 ways to apply formatting to remove the thousands separators.]]></description>
			<content:encoded><![CDATA[<p>A common request is to display number fields in SharePoint 2010 lists without commas. For example, if you had a list of books that included  <em>PublicationYear</em> column, it would format the values as:</p>
<ul>
<li>2,001</li>
<li>1,998</li>
<li>2,011</li>
</ul>
<p>This is confusing to the viewer, as values no longer look like years.</p>
<p>The most frequent suggestion is to create an additional field that calculates a value based on the Number field and ignores all non-numeric parts. This is relatively straightforward, and can be accomplished entirely within the browser:</p>
<p><code>=TEXT([MyNumericData], "0")</code></p>
<p>Or, in a case where you&#8217;d like to retain two digits after the decimal:<br />
<code>=TEXT([MyNumericData], "0.00")</code></p>
<p>SharePoint appears to store the data in its numeric format in a another column, hidden to the browser but visible in SharePoint Designer. It&#8217;s [column name] followed by a period. For example, I created a field called MyNumericData, so the hidden field is MyNumericData<strong>.</strong> Again:</p>
<ul>
<li>MyNumericData</li>
<li>MyNumericData<strong>.</strong></li>
</ul>
<p>Adding this to a view via SharePoint Designer is non-obvious. Here are the steps I used:</p>
<ol>
<li>Click on a data item in Design mode until you see a tab labeled <em>xsl:value-of</em>:<br />
<div id="attachment_573" class="wp-caption alignnone" style="width: 240px"><img src="http://osric.com/chris/accidental-developer/wp-content/uploads/2011/11/MyNumericData-xsl-value-of.png" alt="" title="MyNumericData-xsl-value-of" width="230" height="110" class="size-full wp-image-573" /><p class="wp-caption-text">SharePoint Designer 2010 Design Mode</p></div></li>
<li>Right-click the item and select <em>Edit Formula</em></li>
<li>Remove the current XPath expression</li>
<li>Add the MyNumericData<strong>.</strong> row from the fields pane</li>
<li>Add the <em>format-number</em> function from the <em>Math / Number</em> functions</li>
<li>Add the appropriate format pattern (e.g. &#8216;#&#8217;)</li>
</ol>
<p>The appropriate format pattern depends on how you wish to display the data:</p>
<ul>
<li>Display integer value:<br />
<code>format-number($thisNode/@MyNumericData.,'#')</code></li>
<li>Always display two digits after the decimal:<br />
<code>format-number($thisNode/@MyNumericData.,'0.00')</code></li>
<li>Display up to 2 digits after the decimal:<br />
<code>format-number($thisNode/@MyNumericData.,'#.##')</code></li>
</ul>
<p>If you look at the code view after making these changes, you will see that SharePoint Designer added a hefty chunk of XSL to the XsltListViewWebPart.</p>
<p>Is there any advantage to this method over adding a calculated field? Not as far as I can tell&#8211;but it&#8217;s interesting to note that there is more than one overly-complicated solution to what seems like a trivial problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2011/11/displaying-numeric-fields-in-sharepoint-2010-without-commas/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

