<?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>Sat, 28 Jan 2012 23:13:31 +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>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>0</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>0</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>0</slash:comments>
		</item>
		<item>
		<title>Updating a SharePoint page&#8217;s Page Layout using PowerShell</title>
		<link>http://osric.com/chris/accidental-developer/2011/11/updating-a-sharepoint-pages-page-layout-using-powershell/</link>
		<comments>http://osric.com/chris/accidental-developer/2011/11/updating-a-sharepoint-pages-page-layout-using-powershell/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 22:28:39 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[powershell]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[sharepoint 2010]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=564</guid>
		<description><![CDATA[Earlier today I tried to update the page layout on a SharePoint 2010 site via the browser, which produced an error. I looked up the error&#8217;s correlation ID in the ULS logs and found this: GetFileFromUrl: ArgumentException when attempting get file Url https://oldsitename/webname/_catalogs/masterpage/Block.aspx Value does not fall within the expected range. I couldn&#8217;t change the [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier today I tried to update the page layout on a SharePoint 2010 site via the browser, which produced an error. I looked up the error&#8217;s correlation ID in the ULS logs and found this:<br />
<code>GetFileFromUrl: ArgumentException when attempting get file Url https://oldsitename/webname/_catalogs/masterpage/Block.aspx Value does not fall within the expected range.</code></p>
<p>I couldn&#8217;t change the page layout via the browser. I couldn&#8217;t change the page layout via SharePoint Designer.</p>
<p>Fortunately, I found Patrick Lamber&#8217;s helpful post, <a href="http://www.lamber.info/post/2010/04/02/How-to-programmatically-change-the-page-template-in-Moss-2007.aspx">How to programmatically change the page template in Moss 2007</a>, which basically described the same error and described applying a new page layout via the object model.</p>
<p>For whatever reason, I thought I could do it just as easily via PowerShell. I started following Jason Grimme&#8217;s post, <a href="http://studioshorts.com/blog/2011/01/update-sharepoint-list-items-with-powershell/">Update SharePoint List Item(s) with Powershell</a>, but I was unable to check-out/check-in the page or access the <em>PublishingPageLayout</em> property.</p>
<p>Liam Cleary&#8217;s reply on a TechNet post (<a href="http://social.technet.microsoft.com/Forums/en-US/sharepoint2010programming/thread/4a9b3a4a-cafb-4e2b-8d4f-a32720ed6c3c/">Using PowerShell to Checkout and Checkin a file</a>) tipped me off that I needed to use SPFile (rather than SPListItem) in order to perform the necessary operations. Here are the commands I ended up using:</p>
<p><code>$spWeb = Get-SPWeb("http://currentsitename/webname")<br />
$spFile = $spWeb.GetFile("http://currentsitename/webname/Pages/Test-Page.aspx")<br />
$spFile.CheckOut("Online",$null)<br />
$spFile.Properties["PublishingPagelayout"] = "/_catalogs/masterpage/Block.aspx, Block"<br />
$spFile.Update()<br />
$spFile.CheckIn("Update page layout via PowerShell",[Microsoft.SharePoint.SPCheckinType]::MajorCheckIn)<br />
$spWeb.Dispose()</code></p>
<p>I visited the page and&#8230;another error! This one telling me there wasn&#8217;t a valid page layout. Funny, it worked in development.</p>
<p>It turns out, when I compared it to the <em>PublishingPageLayout</em> property of a working page, I had missed the space character after the comma.</p>
<p><strong>Doesn&#8217;t work:</strong><br />
<code>"/_catalogs/masterpage/Block.aspx,Block"</code></p>
<p><strong>Works:</strong><br />
<code>"/_catalogs/masterpage/Block.aspx, Block"</code></p>
<p>Once I applied the proper path, I was also able to change the page layout via the browser again.</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2011/11/updating-a-sharepoint-pages-page-layout-using-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monitoring web server status with a shell script</title>
		<link>http://osric.com/chris/accidental-developer/2011/09/monitoring-web-server-status-with-a-shell-script/</link>
		<comments>http://osric.com/chris/accidental-developer/2011/09/monitoring-web-server-status-with-a-shell-script/#comments</comments>
		<pubDate>Sun, 11 Sep 2011 16:00:48 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[cron]]></category>
		<category><![CDATA[curl]]></category>
		<category><![CDATA[monitoring]]></category>
		<category><![CDATA[web server]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=499</guid>
		<description><![CDATA[Recently, my VPS (Virtual Private Server) ran into some issues where it exceeded the maximum amount of RAM allotted under my subscription. When this happens, the web server software shuts down and does not restart until I manually restart it. This is bad. I&#8217;m not always visiting my own web site, so it could be [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, my VPS (Virtual Private Server) ran into some issues where it exceeded the maximum amount of RAM allotted under my subscription. When this happens, the web server software shuts down and does not restart until I manually restart it.</p>
<p>This is bad. I&#8217;m not always visiting my own web site, so it could be down for days without me knowing. Although I really need to identify what is using all the RAM, in the meantime I&#8217;ll settle for a monitoring system that will notify me when the server is down.</p>
<pre><code>#!/bin/bash
if curl -s --head http://osric.com/ | grep "200 OK" &gt; /dev/null
  then
    echo "The HTTP server on osric.com is up!" &gt; /dev/null
  else
    echo "The HTTP server on osric.com is down!"
fi</code></pre>
<p><a href="http://curl.haxx.se/" title="cURL">cURL</a> will let you retrieve a URL via the command line, and provides more options than <a href="http://www.gnu.org/s/wget/" title="Wget">Wget</a> for a single URL. In this case, I used the <em>silent</em> switch to eliminate the status/progress output, and the <em>head</em> switch to retrieve only the document headers. The document header is then piped to <a href="http://www.gnu.org/s/grep/" title="Grep">Grep</a>, which searches for the string &#8220;200 OK&#8221; (the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.1" title="HTTP status message 200 OK">HTTP status message for a successful request</a>).</p>
<p>I send the result of that to /dev/null so that the output doesn&#8217;t appear on the screen.</p>
<p>If grep does find 200 OK, then I send a success message to /dev/null. This is largely unnecessary, but it is nice to leave in to test the script in a successful case&#8211;just remove the <code>&gt; /dev/null</code>. If it doesn&#8217;t find 200 OK, then there is a problem. It might not mean, necessarily, that the web server is down, but it definitely indicates there is a problem that needs to be identified.</p>
<p>I added a call to this script to a crontab to run every 5 minutes. If there is no output, nothing happens. If there is output, the output is sent to me via e-mail, which, assuming I am checking my e-mail religiously, should reduce server downtime.</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2011/09/monitoring-web-server-status-with-a-shell-script/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>CFFTP Transfers a Zero-Byte File and Throws a Timeout Error</title>
		<link>http://osric.com/chris/accidental-developer/2011/08/cfftp-transfers-a-zero-byte-file-and-throws-a-timeout-error/</link>
		<comments>http://osric.com/chris/accidental-developer/2011/08/cfftp-transfers-a-zero-byte-file-and-throws-a-timeout-error/#comments</comments>
		<pubDate>Mon, 22 Aug 2011 22:49:21 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[ColdFusion]]></category>
		<category><![CDATA[cfftp]]></category>
		<category><![CDATA[ftp]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=472</guid>
		<description><![CDATA[Although I&#8217;ve used ColdFusion for 7+ years now, I&#8217;ve never used the cfftp tag before. Yesterday, I found a reason to try it out. I figured it would be as simple as cfhttp&#8211;and it was, with one exception (no pun intended). Here is my sample code: &#60;cfftp action="open" connection="test" server="ftp.osric.com" username="chris" password="********************" timeout="60" stoponerror="yes"&#62; &#60;cfftp [...]]]></description>
			<content:encoded><![CDATA[<p>Although I&#8217;ve used ColdFusion for 7+ years now, I&#8217;ve never used the cfftp tag before. Yesterday, I found a reason to try it out. I figured it would be as simple as cfhttp&#8211;and it was, with one exception (no pun intended).</p>
<p>Here is my sample code:</p>
<pre><code>&lt;cfftp action="open"
    connection="test"
    server="ftp.osric.com"
    username="chris"
    password="********************"
    timeout="60"
    stoponerror="yes"&gt;
&lt;cfftp
    connection = "test"
    action = "getFile"
    name = "downloadFile"
    transferMode = "binary"
    localFile = "S:\chris\handlebar-moustache.jpg"
    remoteFile = "handlebar-moustache.jpg"
    timeout="60"&gt;</code></pre>
<p>Here&#8217;s the error message it produced:<br />
<code>An error occurred during the FTP getFile operation.<br />
Error: getFile operation exceeded timeout.</code></p>
<p>However, the local file was still created (as a zero-byte file).</p>
<p>The solution, in my case, was to turn on passive mode (add attribute <code>passive="yes"</code> to the cfftp tag).</p>
<p><a href="http://slacksite.com/other/ftp.html">Active FTP vs. Passive FTP, a Definitive Explanation</a> has a brief explanation of the differences between active and passive FTP.</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2011/08/cfftp-transfers-a-zero-byte-file-and-throws-a-timeout-error/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Importing Data into a SharePoint List</title>
		<link>http://osric.com/chris/accidental-developer/2011/08/importing-data-into-a-sharepoint-list/</link>
		<comments>http://osric.com/chris/accidental-developer/2011/08/importing-data-into-a-sharepoint-list/#comments</comments>
		<pubDate>Wed, 17 Aug 2011 02:53:59 +0000</pubDate>
		<dc:creator>Chris Herdt</dc:creator>
				<category><![CDATA[Sharepoint]]></category>
		<category><![CDATA[import]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[visual studio]]></category>

		<guid isPermaLink="false">http://osric.com/chris/accidental-developer/?p=456</guid>
		<description><![CDATA[SharePoint Joel&#8217;s recent post, Managing Large Lists in SharePoint for Users and Site Admins got me interested in testing the 5000 list view item limit. It also gave me a good opportunity to put fakenamegenerator.com to the test. The site quickly provided me with a list of 6000 random names. Now, how to get them [...]]]></description>
			<content:encoded><![CDATA[<p>SharePoint Joel&#8217;s recent post, <a href="http://www.sharepointjoel.com/Lists/Posts/Post.aspx?ID=471">Managing Large Lists in SharePoint for Users and Site Admins</a> got me interested in testing the 5000 list view item limit.</p>
<p>It also gave me a good opportunity to put <a href="http://www.fakenamegenerator.com/">fakenamegenerator.com</a> to the test. The site quickly provided me with a list of 6000 random names.</p>
<p>Now, how to get them into a SharePoint list?<span id="more-456"></span></p>
<p>First, I tried creating an empty SharePoint project in Visual Studio, and adding a feature receiver to insert the items. The only issue is that I wasn&#8217;t sure how to parse the file from within the feature receiver, so I just created an array with 6000 members by copying-and-pasting a slightly modified CSV file into the constructor. But when I tried deploying it, I got this error:</p>
<p><code>Error:<br />
Error occurred in deployment step 'Activate Features': Unhandled exception was thrown by the sandboxed code wrapper's Execute method in the partial trust app domain: An unexpected error has occurred.</code></p>
<p>I checked the list, and 1368 of 6000 list items had been added. I tried deploying it a couple more times, and it added 1682 items and 1629 items. What was causing the error?</p>
<p>I took a look at the associated ULS log entries:</p>
<ul>
<li><code>Resource "IdlePercentProcessorTime" for monitored process "ipc://5a551cc1-06e5-4241-8c77-55a3a93f82db:7000 (PID=2764" has value: 71.21212 which is above absolute resource limit: 10.</code></li>
<li><code>The worker process "ipc://5a551cc1-06e5-4241-8c77-55a3a93f82db:7000", SHIM/PROXY PID 2764/1100 has been terminated because resource "IdlePercentProcessorTime" is above hard threshold value</code></li>
<li><code>Stopping shim process. Shim process name: "SPUCWorkerProcess" Shim PID: "0x0ACC" Shim service url: "ipc://5a551cc1-06e5-4241-8c77-55a3a93f82db:7000"</code></li>
<li><code>Stopping proxy process. Proxy process name: "SPUCWorkerProcessProxy" Proxy PID: "0x044C" Proxy service url: "ipc://00657311-1135-413b-bda0-839e7794fae6:7000"</code></li>
</ul>
<p>I saw the IdlePercentProcessorTime and focused on <em>ProcessorTime</em>&#8211;I thought the server was working too hard. I tried putting the thread to sleep for 100 milliseconds between items, but that time it only added 219 items!</p>
<p>Right: <em>Idle</em>PercentProcessorTime. The process had even more idle time, because it was sitting around with a sleeping thread. Apparently, sandboxed solutions can&#8217;t just tie up processor threads. (Check out <a href="http://mysharepointofview.com/2010/10/quotas-and-locks-for-sandbox-solutions/">Quotas and Locks for Sandboxed Solutions</a> for more info.)</p>
<p>I could deploy the data to the list in 6 batches of 1000, but that&#8217;s an inelegant solution. Besides, what if I wanted to insert 100,000 records instead?</p>
<p>Rather than mess with any of that, why not just bypass the sandbox restrictions and make it a farm solution? This time I got a different error:</p>
<p><code>Error occurred in deployment step 'Add Solution': failed to load receiver assembly "AddLotsOfNames...."</code></p>
<p>There were zero items in the feature, so there was no assembly. I addressed this by adding an empty module. The 6000 names were added to the list.</p>
<p>Using a feature receiver to add all the names is less than ideal, though. A console application would be better. I built a console app that would take a string as a command line argument and use that as the filename for the input data. (If I wanted to re-use the file, I could take other command line arguments, such as the SharePoint site and list address into which the data should be inserted.)</p>
<p>Visual Studio notified me of errors right away. My code from the feature receiver relied on a reference to Microsoft.SharePoint. I tried to add the reference to my console app, but the reference wasn&#8217;t listed. Why not? The console app was set to target .NET Framework 4, but the Microsoft.SharePoint component is in .NET Framework 3.5. Once I targeted the right framework, I was able to add the reference.</p>
<p>The console application compiled, but produced a run-time error:<br />
<code>An unhandled exception ('System.IO.FileNotFoundException') occurred in AddPeopleConsole.exe [5184]</code></p>
<p>This was a little confusing, because my first thought was to check the name and path of the data file, which was correct. It turns out that the console app is set, by default, to compile for an x86 (or 32-bit) platform. My development environment has a 64-bit processor, so I changed the platform target to Any CPU.</p>
<p>Here&#8217;s the working code:</p>
<pre><code>namespace AddPeopleConsole
{
  class Program
  {
    static void Main(string[] args)
    {
      string filename = args[0];
      var reader = new StreamReader(File.OpenRead(@filename));

      using (SPSite siteCollection = new SPSite("http://sp2010dev/"))
      {
        using (SPWeb web = siteCollection.RootWeb)
        {
          SPList list = web.GetList("/Lists/Contacts/");
          while (!reader.EndOfStream)
          {
            var person = reader.ReadLine();
            // Separate the person data into discrete values
            string[] values = person.Split(',');
            // Add an empty item to the list
            SPItem item = list.AddItem();
            // Assign values to the item
            item["Title"] = values[0];
            item["FirstName"] = values[1];
            item["WorkPhone"] = values[2];
            item["Email"] = values[3];
            // Save the item, i.e. put the person in the list
            item.Update();
          }
        }
      }
    }
  }
}</code></pre>
<p>Testing in my development environment isn&#8217;t very useful, in this case. The 5000 item limit on a list view is to protect the system from performance degradation, as a query of over 5000 items will cause the entire table to lock (for the duration of the query). On a single-user dev environment (or even a multi-user dev environment), these table locks would probably go unnoticed.</p>
<p>If I ever need to insert a huge number of records from a text file, though, I&#8217;m prepared!</p>
]]></content:encoded>
			<wfw:commentRss>http://osric.com/chris/accidental-developer/2011/08/importing-data-into-a-sharepoint-list/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

