<?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>Andrew Beaton :: FAQ &#187; Programming</title>
	<atom:link href="http://andrewbeaton.net/faq/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewbeaton.net/faq</link>
	<description>Tips from the world of a software developer</description>
	<lastBuildDate>Wed, 13 Jul 2011 17:03:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>Grep to find ^M (Windows carriage return)</title>
		<link>http://andrewbeaton.net/faq/2011/07/13/grep-to-find-m-windows-carriage-return/</link>
		<comments>http://andrewbeaton.net/faq/2011/07/13/grep-to-find-m-windows-carriage-return/#comments</comments>
		<pubDate>Wed, 13 Jul 2011 16:58:17 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[carriage]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[hat m]]></category>
		<category><![CDATA[new line]]></category>
		<category><![CDATA[windows carriage return]]></category>
		<category><![CDATA[\r]]></category>
		<category><![CDATA[^m]]></category>

		<guid isPermaLink="false">http://andrewbeaton.net/faq/?p=154</guid>
		<description><![CDATA[There are two options here, one we used before when searching for the ^M&#8217;s in VI, the other is new: ^M $'\r' So to find all files with the Windows carriage return in them, use one of the following&#8230; grep -r &#34;^M&#34; * grep -r $'\r' * ^M is entered by pressing Ctrl+V followed by [...]]]></description>
			<content:encoded><![CDATA[<p>There are two options here, one we used before when searching for the ^M&#8217;s in VI, the other is new:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">^M</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$<span style="color: #ff0000;">'\r'</span></pre></div></div>

<p>So to find all files with the Windows carriage return in them, use one of the following&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-r</span> <span style="color: #ff0000;">&quot;^M&quot;</span> <span style="color: #000000; font-weight: bold;">*</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-r</span> $<span style="color: #ff0000;">'\r'</span> <span style="color: #000000; font-weight: bold;">*</span></pre></div></div>

<p>^M is entered by pressing <strong>Ctrl+V</strong><strong> followed by <strong>Ctrl+M</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://andrewbeaton.net/faq/2011/07/13/grep-to-find-m-windows-carriage-return/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>View output of  the dd command</title>
		<link>http://andrewbeaton.net/faq/2011/06/23/view-output-of-dd/</link>
		<comments>http://andrewbeaton.net/faq/2011/06/23/view-output-of-dd/#comments</comments>
		<pubDate>Thu, 23 Jun 2011 10:48:36 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[dd]]></category>
		<category><![CDATA[dd output]]></category>
		<category><![CDATA[dd verbose]]></category>
		<category><![CDATA[format]]></category>
		<category><![CDATA[wipe]]></category>

		<guid isPermaLink="false">http://andrewbeaton.net/faq/?p=142</guid>
		<description><![CDATA[Recently whilst wiping some old hard disks I thought it would be useful to see what the &#8216;dd&#8217; command was doing, rather than sitting there blankly for hour. I knocked up a little bash script to run in another terminal that will update the terminal running dd with some useful status information. In this example, [...]]]></description>
			<content:encoded><![CDATA[<p>Recently whilst wiping some old hard disks I thought it would be useful to see what the &#8216;dd&#8217; command was doing, rather than sitting there blankly for hour. I knocked up a little bash script to run in another terminal that will update the terminal running dd with some useful status information.</p>
<p>In this example, dd will be run as&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">dd</span> <span style="color: #007800;">if</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>random <span style="color: #007800;">of</span>=<span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>sda</pre></div></div>

<p>copy the following into ddUpdate.sh for example and run it&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #007800;">ddpid</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ps</span> auwx <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'/dd if/ &amp;&amp; !/awk/ { print $2}'</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">while</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$ddpid</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>
<span style="color: #000000; font-weight: bold;">do</span>
<span style="color: #c20cb9; font-weight: bold;">kill</span> <span style="color: #660033;">-USR1</span> <span style="color: #007800;">$ddpid</span>
<span style="color: #c20cb9; font-weight: bold;">sleep</span> <span style="color: #000000;">1</span>
<span style="color: #007800;">ddpid</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">ps</span> auwx <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'/dd if/ &amp;&amp; !/awk/ { print $2}'</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>This outputs the following to the terminal running dd&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">xxxxxx records <span style="color: #000000; font-weight: bold;">in</span>
xxxxxx records out
xxxxxx bytes <span style="color: #7a0874; font-weight: bold;">&#40;</span>xx nn<span style="color: #7a0874; font-weight: bold;">&#41;</span> copied, xxxx s, xx MB<span style="color: #000000; font-weight: bold;">/</span>s</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://andrewbeaton.net/faq/2011/06/23/view-output-of-dd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Get DateTime in YYYY-mm-dd HH:MM:SS format using Perl</title>
		<link>http://andrewbeaton.net/faq/2011/04/14/get-datetime-in-yyyy-mm-dd-hhmmss-format-using-perl/</link>
		<comments>http://andrewbeaton.net/faq/2011/04/14/get-datetime-in-yyyy-mm-dd-hhmmss-format-using-perl/#comments</comments>
		<pubDate>Thu, 14 Apr 2011 11:54:34 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[date]]></category>
		<category><![CDATA[datetime]]></category>
		<category><![CDATA[localtime]]></category>
		<category><![CDATA[POSIX]]></category>
		<category><![CDATA[strftime]]></category>
		<category><![CDATA[time]]></category>
		<category><![CDATA[YYYY-mm-dd HH-MM-SS]]></category>

		<guid isPermaLink="false">http://andrewbeaton.net/faq/?p=133</guid>
		<description><![CDATA[For many years I&#8217;ve been using the long process of obtaining everything from localtime(), adding 1900 to the year etc. etc. but I&#8217;ve just come across the method below, which uses strftime from the POSIX module. use POSIX; &#160; my $DateTime = strftime &#34;%F %T&#34;, localtime $^T; This gives you: 2006-10-02 02:06:07 Now that&#8217;s a [...]]]></description>
			<content:encoded><![CDATA[<p>For many years I&#8217;ve been using the long process of obtaining everything from <em>localtime()</em>, adding  1900 to the year etc. etc. but I&#8217;ve just come across the method below, which uses <em>strftime</em> from the <a title="POSIX" href="http://perldoc.perl.org/POSIX.html">POSIX</a> module.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> POSIX<span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$DateTime</span> <span style="color: #339933;">=</span> strftime <span style="color: #ff0000;">&quot;%F %T&quot;</span><span style="color: #339933;">,</span> <span style="color: #000066;">localtime</span> <span style="color: #0000ff;">$^T</span><span style="color: #339933;">;</span></pre></div></div>

<p>This gives you:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000;">2006</span>-<span style="color: #000000;">10</span>-02 02:06:07</pre></div></div>

<p>Now that&#8217;s a lot easier!</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewbeaton.net/faq/2011/04/14/get-datetime-in-yyyy-mm-dd-hhmmss-format-using-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;Object reference not set to an instance of an object.&#8221; when using OpenSubKey</title>
		<link>http://andrewbeaton.net/faq/2010/11/09/object-reference-not-set-to-an-instance-of-an-object-when-using-opensubkey/</link>
		<comments>http://andrewbeaton.net/faq/2010/11/09/object-reference-not-set-to-an-instance-of-an-object-when-using-opensubkey/#comments</comments>
		<pubDate>Tue, 09 Nov 2010 20:17:37 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Object Reference]]></category>
		<category><![CDATA[OpenSubKey]]></category>
		<category><![CDATA[Registry]]></category>
		<category><![CDATA[Registry Key]]></category>
		<category><![CDATA[Windows 64 bit]]></category>
		<category><![CDATA[Wow6432Node]]></category>

		<guid isPermaLink="false">http://andrewbeaton.net/faq/?p=119</guid>
		<description><![CDATA[Whilst using a working project on my new development machine, I came across an issue that stumped me for a while. Microsoft.Win32.Registry.LocalMachine.OpenSubKey(&#8220;subkey&#8221;).GetValue(&#8220;blah&#8221;) was failing with the error above, even though it worked perfectly previously and the key was clearly in the registry. After a bit of research I found it to be because I&#8217;m now [...]]]></description>
			<content:encoded><![CDATA[<p>Whilst using a working project on my new development machine, I came across an issue that stumped me for a while.</p>
<p>Microsoft.Win32.Registry.LocalMachine.OpenSubKey(&#8220;subkey&#8221;).GetValue(&#8220;blah&#8221;) was failing with the error above, even though it worked perfectly previously and the key was clearly in the registry.</p>
<p>After a bit of research I found it to be because I&#8217;m now using a 64 bit version of Windows. Even though the key existed in HKEY_LOCAL_MACHINE\SOFTWARE\<key>, it did not exist in HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\<key></p>
<p>To fix this, I simply created a copy of the key in Wow6432Node. </p>
<p>This may not be the correct solution but it worked for me&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://andrewbeaton.net/faq/2010/11/09/object-reference-not-set-to-an-instance-of-an-object-when-using-opensubkey/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Read MP3 ID3 Tags in Perl</title>
		<link>http://andrewbeaton.net/faq/2009/12/03/read-mp3-id3-tags-in-perl/</link>
		<comments>http://andrewbeaton.net/faq/2009/12/03/read-mp3-id3-tags-in-perl/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 20:59:12 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[id3]]></category>
		<category><![CDATA[id3 tags]]></category>
		<category><![CDATA[mp3]]></category>
		<category><![CDATA[tags]]></category>

		<guid isPermaLink="false">http://andrewbeaton.net/faq/?p=76</guid>
		<description><![CDATA[The package I use for simple tag reading is MP3::Tag, available on CPAN with more information here. The following example shows how easy it is to retrieve tags from an MP3 file. use MP3::Tag; &#160; my $file = MP3::Tag-&#62;new&#40;$filename&#41;; &#160; my &#40;$title, $track, $artist, $album, $comment, $year, $genre&#41; = $file-&#62;autoinfo&#40;&#41;; &#160; print &#34;Title: [$title]\n&#34;; print [...]]]></description>
			<content:encoded><![CDATA[<p>The package I use for simple tag reading is MP3::Tag, available on CPAN with more information <a href="http://search.cpan.org/~ilyaz/MP3-Tag-1.12/lib/MP3/Tag.pm">here</a>.</p>
<p>The following example shows how easy it is to retrieve tags from an MP3 file.</p>

<div class="wp_syntax"><div class="code"><pre class="perl" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">use</span> MP3<span style="color: #339933;">::</span><span style="color: #006600;">Tag</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #0000ff;">$file</span> <span style="color: #339933;">=</span> MP3<span style="color: #339933;">::</span><span style="color: #006600;">Tag</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">new</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$filename</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">my</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">$title</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$track</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$artist</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$album</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$comment</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$year</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">$genre</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">$file</span><span style="color: #339933;">-&gt;</span><span style="color: #006600;">autoinfo</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Title: [$title]<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Artist: [$artist]<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Album: [$album]<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Track: [$track]<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Year: [$year]<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Genre: [$genre]<span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000066;">print</span> <span style="color: #ff0000;">&quot;Comment: [$comment]<span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://andrewbeaton.net/faq/2009/12/03/read-mp3-id3-tags-in-perl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Add a space in XSL</title>
		<link>http://andrewbeaton.net/faq/2009/11/13/add-a-space-in-xsl/</link>
		<comments>http://andrewbeaton.net/faq/2009/11/13/add-a-space-in-xsl/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 23:35:52 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[XSL]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://andrewbeaton.com/faq/?p=52</guid>
		<description><![CDATA[The following shows you how to add a space or &#160; in XSL: &#60;xsl:text disable-output-escaping=&#34;yes&#34;&#62;&#38;nbsp;&#60;/xsl:text&#62;]]></description>
			<content:encoded><![CDATA[<p>The following shows you how to add a space or &nbsp; in XSL:</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;xsl:text</span> <span style="color: #000066;">disable-output-escaping</span>=<span style="color: #ff0000;">&quot;yes&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #ddbb00;">&amp;nbsp;</span><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/xsl:text<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://andrewbeaton.net/faq/2009/11/13/add-a-space-in-xsl/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Specifically target each browser in CSS</title>
		<link>http://andrewbeaton.net/faq/2009/11/13/specifically-target-each-browser-in-css/</link>
		<comments>http://andrewbeaton.net/faq/2009/11/13/specifically-target-each-browser-in-css/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 23:31:33 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[IE6]]></category>
		<category><![CDATA[IE7]]></category>
		<category><![CDATA[IE8]]></category>
		<category><![CDATA[Internet Explorer]]></category>

		<guid isPermaLink="false">http://andrewbeaton.com/faq/?p=49</guid>
		<description><![CDATA[The following CSS &#8216;hack&#8217; can be used to target all browsers IE 7, IE 6 and IE < 6 ... All browsers: margin-top: 44px; IE7 and below: *margin-top: 26px; IE6 and below: _margin-top: 44px; IE6 only: _mar\gin-top: 44px; All firefox: #selector&#91;id=selector&#93; &#123; color: red; &#125; All firefox: @-moz-document url-prefix() { .selector { color: red; } [...]]]></description>
			<content:encoded><![CDATA[<p>The following CSS &#8216;hack&#8217; can be used to target all browsers IE 7, IE 6 and IE < 6 ...</p>
<p>All browsers:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">44px</span><span style="color: #00AA00;">;</span></pre></div></div>

<p>IE7 and below:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*</span><span style="color: #000000; font-weight: bold;">margin-top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">26px</span><span style="color: #00AA00;">;</span></pre></div></div>

<p>IE6 and below:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">_margin-<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">44px</span><span style="color: #00AA00;">;</span></pre></div></div>

<p>IE6 only:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">_mar\gin-<span style="color: #000000; font-weight: bold;">top</span><span style="color: #00AA00;">:</span> <span style="color: #933;">44px</span><span style="color: #00AA00;">;</span></pre></div></div>

<p>All firefox:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#selector</span><span style="color: #00AA00;">&#91;</span>id<span style="color: #00AA00;">=</span>selector<span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>All firefox:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #a1a100;">@-moz-document url-prefix() { .selector { color: red; } }</span></pre></div></div>

<p>All Gecko:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #00AA00;">*&gt;</span><span style="color: #6666ff;">.selector</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Firefox 1.5 and newer:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #6666ff;">.selector</span><span style="color: #00AA00;">,</span> x<span style="color: #3333ff;">:-moz-any-link</span><span style="color: #00AA00;">,</span> x<span style="color: #3333ff;">:only-child </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Firefox 2 and older:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">body<span style="color: #3333ff;">:empty </span><span style="color: #6666ff;">.selector</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Firefox 2 and older:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;"><span style="color: #cc00cc;">#selector</span><span style="color: #00AA00;">&#91;</span>id<span style="color: #00AA00;">=</span>SELECTOR<span style="color: #00AA00;">&#93;</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Firefox 2 and older:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">html<span style="color: #00AA00;">&gt;</span><span style="color: #808080; font-style: italic;">/**/</span>body <span style="color: #6666ff;">.selector</span><span style="color: #00AA00;">,</span> x<span style="color: #3333ff;">:-moz-any-link </span><span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

<p>Firefox 3:</p>

<div class="wp_syntax"><div class="code"><pre class="css" style="font-family:monospace;">html<span style="color: #00AA00;">&gt;</span><span style="color: #808080; font-style: italic;">/**/</span>body <span style="color: #6666ff;">.selector</span><span style="color: #00AA00;">,</span> x<span style="color: #3333ff;">:-moz-any-link</span><span style="color: #00AA00;">,</span> x<span style="color: #00AA00;">:</span><span style="color: #993333;">default</span> <span style="color: #00AA00;">&#123;</span> <span style="color: #000000; font-weight: bold;">color</span><span style="color: #00AA00;">:</span> <span style="color: #993333;">red</span><span style="color: #00AA00;">;</span> <span style="color: #00AA00;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://andrewbeaton.net/faq/2009/11/13/specifically-target-each-browser-in-css/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Use a button as an A Href link</title>
		<link>http://andrewbeaton.net/faq/2009/11/13/use-a-button-as-an-a-href-link/</link>
		<comments>http://andrewbeaton.net/faq/2009/11/13/use-a-button-as-an-a-href-link/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 23:06:42 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[a href]]></category>
		<category><![CDATA[Button]]></category>

		<guid isPermaLink="false">http://andrewbeaton.com/faq/?p=33</guid>
		<description><![CDATA[To create an A Href link that can be used as a button, we can use one of the two following methods: function SubmitFrom&#40;&#41;&#123; document.myform.target.value=&#34;somescript.php3&#34; document.myfrom.submit&#40;&#41; &#125; function ResetFrom&#40;&#41;&#123; document.myfrom.reset&#40;&#41; &#125; &#160; &#60;a href=&#34;javascript:SubmitForm()&#34;&#62;&#60;img src=....&#62;&#60;/a&#62; or &#60;FORM name=remove ACTION='removeItem.php3' METHOD='POST' ENCTYPE='application/x- www-form-urlencoded'&#62; &#60;a href=&#34;javascript:document.remove.submit()&#34;&#62;remove from cart&#60;/a&#62; &#60;/form&#62;]]></description>
			<content:encoded><![CDATA[<p>To create an A Href link that can be used as a button, we can use one of the two following methods:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #003366; font-weight: bold;">function</span> SubmitFrom<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    document.<span style="color: #660066;">myform</span>.<span style="color: #660066;">target</span>.<span style="color: #660066;">value</span><span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;somescript.php3&quot;</span>
    document.<span style="color: #660066;">myfrom</span>.<span style="color: #660066;">submit</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #003366; font-weight: bold;">function</span> ResetFrom<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    document.<span style="color: #660066;">myfrom</span>.<span style="color: #660066;">reset</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #339933;">&lt;</span>a href<span style="color: #339933;">=</span><span style="color: #3366CC;">&quot;javascript:SubmitForm()&quot;</span><span style="color: #339933;">&gt;&lt;</span>img src<span style="color: #339933;">=</span>....<span style="color: #339933;">&gt;&lt;/</span>a<span style="color: #339933;">&gt;</span></pre></div></div>

<p>or</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">FORM</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span>remove <span style="color: #000066;">ACTION</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'removeItem.php3'</span> <span style="color: #000066;">METHOD</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'POST'</span> <span style="color: #000066;">ENCTYPE</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">'application/x-</span>
<span style="color: #009900;">www-form-urlencoded'</span>&gt;</span> 
    <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">a</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;javascript:document.remove.submit()&quot;</span>&gt;</span>remove from cart<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">a</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://andrewbeaton.net/faq/2009/11/13/use-a-button-as-an-a-href-link/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Run only one instance of a program in C#</title>
		<link>http://andrewbeaton.net/faq/2009/11/13/run-only-one-instance-of-a-program-in-csharp/</link>
		<comments>http://andrewbeaton.net/faq/2009/11/13/run-only-one-instance-of-a-program-in-csharp/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 22:45:22 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[Mutex]]></category>

		<guid isPermaLink="false">http://andrewbeaton.com/faq/?p=15</guid>
		<description><![CDATA[This example shows you how to ensure that only one instance of an application is running. // Ensure only one instance of this application is running. bool alone = false; Mutex m = new Mutex&#40;true, &#34;&#60;name&#62;&#34;, out alone&#41;; &#160; if &#40;!alone&#41; &#123; Console.WriteLine&#40;&#34;Another instance is already running.&#34;&#41;; Console.ReadKey&#40;&#41;; return; &#125; &#160; Console.WriteLine&#40;&#34;Running...\n&#34;&#41;; Console.ReadKey&#40;&#41;; &#160; // [...]]]></description>
			<content:encoded><![CDATA[<p>This example shows you how to ensure that only one instance of an application is running.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Ensure only one instance of this application is running.</span>
<span style="color: #6666cc; font-weight: bold;">bool</span> alone <span style="color: #008000;">=</span> <span style="color: #0600FF; font-weight: bold;">false</span><span style="color: #008000;">;</span>
Mutex m <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Mutex<span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">true</span>, <span style="color: #666666;">&quot;&lt;name&gt;&quot;</span>, <span style="color: #0600FF; font-weight: bold;">out</span> alone<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span><span style="color: #008000;">!</span>alone<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Another instance is already running.&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    Console<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadKey</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">return</span><span style="color: #008000;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Running...<span style="color: #008080; font-weight: bold;">\n</span>&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
Console<span style="color: #008000;">.</span><span style="color: #0000FF;">ReadKey</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #008080; font-style: italic;">// Needed to ensure only one instance is running.</span>
GC<span style="color: #008000;">.</span><span style="color: #0000FF;">KeepAlive</span><span style="color: #008000;">&#40;</span>m<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://andrewbeaton.net/faq/2009/11/13/run-only-one-instance-of-a-program-in-csharp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Restart a Windows service using C#</title>
		<link>http://andrewbeaton.net/faq/2009/11/13/restart-a-windows-service-using-csharp/</link>
		<comments>http://andrewbeaton.net/faq/2009/11/13/restart-a-windows-service-using-csharp/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 22:38:05 +0000</pubDate>
		<dc:creator>Andrew</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[ServiceController]]></category>
		<category><![CDATA[ServiceControllerStatus]]></category>
		<category><![CDATA[services]]></category>
		<category><![CDATA[TimeSpan]]></category>

		<guid isPermaLink="false">http://andrewbeaton.com/faq/?p=11</guid>
		<description><![CDATA[This example shows how to start, stop and restart a windows service programmatically in C#. Start service The following method tries to start a service specified by a service name. Then it waits until the service is running or a timeout occurs. public static void StartService&#40;string serviceName, int timeoutMilliseconds&#41; &#123; ServiceController service = new ServiceController&#40;serviceName&#41;; [...]]]></description>
			<content:encoded><![CDATA[<p>This example shows how to start, stop and restart a windows service programmatically in C#. </p>
<p><strong>Start service</strong></p>
<p>The following method tries to start a service specified by a service name. Then it waits until the service is running or a timeout occurs.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> StartService<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> serviceName, <span style="color: #6666cc; font-weight: bold;">int</span> timeoutMilliseconds<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    ServiceController service <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ServiceController<span style="color: #008000;">&#40;</span>serviceName<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">try</span>
    <span style="color: #008000;">&#123;</span>
        TimeSpan timeout <span style="color: #008000;">=</span> TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">FromMilliseconds</span><span style="color: #008000;">&#40;</span>timeoutMilliseconds<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        service<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        service<span style="color: #008000;">.</span><span style="color: #0000FF;">WaitForStatus</span><span style="color: #008000;">&#40;</span>ServiceControllerStatus<span style="color: #008000;">.</span><span style="color: #0000FF;">Running</span>, timeout<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">catch</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// ...</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><strong>Stop service</strong></p>
<p>The following method tries to stop the specified service and it waits until the service is stopped or a timeout occurs.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> StopService<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> serviceName, <span style="color: #6666cc; font-weight: bold;">int</span> timeoutMilliseconds<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    ServiceController service <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ServiceController<span style="color: #008000;">&#40;</span>serviceName<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">try</span>
    <span style="color: #008000;">&#123;</span>
        TimeSpan timeout <span style="color: #008000;">=</span> TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">FromMilliseconds</span><span style="color: #008000;">&#40;</span>timeoutMilliseconds<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        service<span style="color: #008000;">.</span><span style="color: #0000FF;">Stop</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        service<span style="color: #008000;">.</span><span style="color: #0000FF;">WaitForStatus</span><span style="color: #008000;">&#40;</span>ServiceControllerStatus<span style="color: #008000;">.</span><span style="color: #0000FF;">Stopped</span>, timeout<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #008000;">&#125;</span>
    <span style="color: #0600FF; font-weight: bold;">catch</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #008080; font-style: italic;">// ...</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p><strong>Restart service</strong></p>
<p>This method combinates both previous methods. It tries to stop the service (and waits until it&#8217;s stopped) then it begins to start the service (and waits until the service is running). The specified timeout is used for both operations together.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> RestartService<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> serviceName, <span style="color: #6666cc; font-weight: bold;">int</span> timeoutMilliseconds<span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
    ServiceController service <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ServiceController<span style="color: #008000;">&#40;</span>serviceName<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF; font-weight: bold;">try</span>
    <span style="color: #008000;">&#123;</span>
        <span style="color: #6666cc; font-weight: bold;">int</span> millisec1 <span style="color: #008000;">=</span> Environment<span style="color: #008000;">.</span><span style="color: #0000FF;">TickCount</span><span style="color: #008000;">;</span>
        TimeSpan timeout <span style="color: #008000;">=</span> TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">FromMilliseconds</span><span style="color: #008000;">&#40;</span>timeoutMilliseconds<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        service<span style="color: #008000;">.</span><span style="color: #0000FF;">Stop</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        service<span style="color: #008000;">.</span><span style="color: #0000FF;">WaitForStatus</span><span style="color: #008000;">&#40;</span>ServiceControllerStatus<span style="color: #008000;">.</span><span style="color: #0000FF;">Stopped</span>, timeout<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">// count the rest of the timeout</span>
        <span style="color: #6666cc; font-weight: bold;">int</span> millisec2 <span style="color: #008000;">=</span> Environment<span style="color: #008000;">.</span><span style="color: #0000FF;">TickCount</span><span style="color: #008000;">;</span>
        timeout <span style="color: #008000;">=</span> TimeSpan<span style="color: #008000;">.</span><span style="color: #0000FF;">FromMilliseconds</span><span style="color: #008000;">&#40;</span>timeoutMilliseconds <span style="color: #008000;">-</span> <span style="color: #008000;">&#40;</span>millisec2<span style="color: #008000;">-</span>millisec1<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        service<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        service<span style="color: #008000;">.</span><span style="color: #0000FF;">WaitForStatus</span><span style="color: #008000;">&#40;</span>ServiceControllerStatus<span style="color: #008000;">.</span><span style="color: #0000FF;">Running</span>, timeout<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
   <span style="color: #008000;">&#125;</span>
   <span style="color: #0600FF; font-weight: bold;">catch</span>
   <span style="color: #008000;">&#123;</span>
       <span style="color: #008080; font-style: italic;">// ...</span>
   <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://andrewbeaton.net/faq/2009/11/13/restart-a-windows-service-using-csharp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

