<?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"
	>

<channel>
	<title>Everything old is new again</title>
	<atom:link href="http://www.svendtofte.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.svendtofte.com</link>
	<description>rantings &#38; scraps on code and web development</description>
	<pubDate>Tue, 12 Aug 2008 19:40:07 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>The utterly retarded IE PNG implementation (and pngstrip)</title>
		<link>http://www.svendtofte.com/web/the-utterly-retarded-ie-png-implementation-and-pngstrip/</link>
		<comments>http://www.svendtofte.com/web/the-utterly-retarded-ie-png-implementation-and-pngstrip/#comments</comments>
		<pubDate>Tue, 12 Aug 2008 19:40:07 +0000</pubDate>
		<dc:creator>svendtofte</dc:creator>
		
		<category><![CDATA[Web]]></category>

		<category><![CDATA[gamma]]></category>

		<category><![CDATA[internet explorer]]></category>

		<category><![CDATA[png]]></category>

		<category><![CDATA[pngstrip]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=117</guid>
		<description><![CDATA[pngstrip (32bit, Windows Executable at 59 kb) is a small program I&#8217;ve written to strip out the various kinds of gamma and chromacity information from PNG files. It&#8217;s written in standard ANSI C, so should compile on anything reasonable, though it has only been tested on Windows XP. The source code is also freely available. [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.svendtofte.com/wp-content/uploads/2008/08/pngstrip.exe">pngstrip</a> (32bit, Windows Executable at 59 kb) is a small program I&#8217;ve written to strip out the various kinds of gamma and chromacity information from PNG files. It&#8217;s written in standard ANSI C, so should compile on anything reasonable, though it has only been tested on Windows XP. <a href="http://www.svendtofte.com/wp-content/uploads/2008/08/pngstrip.c">The source code is also freely available.</a> It&#8217;s console program, just type out <code>pngstrip filename.png</code>, and <code>filename.png</code> will be stripped.</p>
<p>We spent years <a href="http://www.alistapart.com/stories/pngopacity/">agonizing over the lack of 8-bit alpha channel in PNG in IE</a>, and when we filly get it <a href="http://blogs.msdn.com/ie/archive/2005/04/26/412263.aspx">natively/nicely supported in IE</a> they go and botch is so horribly.</p>
<p>Most of us have heard about gamma. But unless you do something in the graphics/print field, it mostly remains a button on our screen, where we tweak the luminocity of the screen. But of course, when an artist makes a snazzy PNG picture, making sure that it appears at the same display intensity as it did on his screen is understandably an laudarble goal. So PNG embeds gamma information, saying that this and that color, should be show at this and that intensity. The problem occurs when the BOG STANDARD (for 15 years and counting) HTML and CSS colors are NOT processed through the same system and thus don&#8217;t get the same gamma correction applied. <a href="http://www.svendtofte.com/wp-content/uploads/2008/08/iepng.html">The problem is easy to spot</a> (need to be viewed in IE). The PNG files, once stripped, appears correctly.</p>
<p>I won&#8217;t really bother explaining this problem more, since it goes beyond stupid, I&#8217;ll just link further reading materials if you don&#8217;t know why you may wish to strip your PNG files for gamma information. <a href="http://hsivonen.iki.fi/png-gamma/">Henri Sivonen</a> has the best treatment on the topic.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/web/the-utterly-retarded-ie-png-implementation-and-pngstrip/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Setting up NHibernate 2.0</title>
		<link>http://www.svendtofte.com/serverside/setting-up-nhibernate-20/</link>
		<comments>http://www.svendtofte.com/serverside/setting-up-nhibernate-20/#comments</comments>
		<pubDate>Wed, 23 Jul 2008 20:52:47 +0000</pubDate>
		<dc:creator>svendtofte</dc:creator>
		
		<category><![CDATA[Serverside]]></category>

		<category><![CDATA[hibernate]]></category>

		<category><![CDATA[nhibernate]]></category>

		<category><![CDATA[or mapping]]></category>

		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=102</guid>
		<description><![CDATA[I&#8217;ve spent several long hours over the last week, trying to get Hibernate for .NET to even just work in Visual Studio. The changed configuration format has been, since I&#8217;m not seeing any real examples of how to setup NHibernate 2.0 (Beta 2, which will probably be going release later this month) on the net, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve spent several long hours over the last week, trying to get <a href="http://www.nhibernate.org/">Hibernate for .NET</a> to even just work in Visual Studio. The changed configuration format has been, since I&#8217;m not seeing any real examples of how to setup NHibernate 2.0 (Beta 2, which will probably be going release later this month) on the net, I&#8217;m just putting it out there now, since I&#8217;m trying to learn the whole framework, and so far this was my biggest stumbling point.</p>
<p>Important to note that this isn&#8217;t a <em>true example</em> by any measure. It merely shows what to put in your <code>App.config</code> (especially since the official documentation mostly covers the Java version, which naturally has no idea what <code>App.config</code> is. And what <a href="http://www.hibernate.org/362.html">little there is</a> for NHibernate, is for the last release. </p>
<p><span id="more-102"></span></p>
<p>The example is very simple, it mainly shows:</p>
<ul>
<li>
<p>The contents of <code>App.config</code></p>
</li>
<li>
<p>An example <code>*.hbm.xml</code> file for the sample <code>User</code> class.</p>
</li>
<li>
<p>If you should wish, the whole Visual Studio 2008 Solution file</p>
</li>
</ul>
<p>I used <a href="http://www.microsoft.com/express/vcsharp/">Visual C# 2008 Express Edition</a> and for the database I used <a href="http://www.microsoft.com/express/sql/download/default.aspx">SQL Server Express 2005</a> (make sure to get both &#8220;Microsoft SQL Server 2005 Express Edition &#8221; and  &#8220;SQL Server Management Studio Express&#8221;, the latter part is the GUI to manage the database, unless talking pure SQL into one end of a pipe satisfies you).</p>
<p><a href="http://www.svendtofte.com/wp-content/uploads/2008/07/nhibernatetest.zip">Download the entire VS 2008 Solution.</a></p>
<h2>Configs, etc</h2>
<p>The <code>App.config</code> looks like</p>
<pre>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;configuration&gt;
  &lt;configSections&gt;
    &lt;section name="hibernate-configuration"
             type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" /&gt;
  &lt;/configSections&gt;
  &lt;hibernate-configuration xmlns="urn:nhibernate-configuration-2.2" &gt;
    &lt;session-factory&gt;
      &lt;property name="dialect"&gt;
        NHibernate.Dialect.MsSql2005Dialect
      &lt;/property&gt;
      &lt;property name="connection.provider"&gt;
        NHibernate.Connection.DriverConnectionProvider
      &lt;/property&gt;
      &lt;property name="connection.driver_class"&gt;
        NHibernate.Driver.SqlClientDriver
      &lt;/property&gt;
      &lt;property name="connection.connection_string"&gt;
        Server=SVENDSDESKTOP\SQLEXPRESS;
        Database=NHibernate;
        Integrated Security=True;
      &lt;/property&gt;
    &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
&lt;/configuration&gt;</pre>
<p>The <code>NHibernateTest.User.hbm.xml</code>:</p>
<pre>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
&lt;hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" namespace="NHibernateTest"&gt;
  &lt;class name="User, NHibernateTest" table="users"&gt;
    &lt;id name="Id" column="LogonId" type="String" length="20"&gt;
      &lt;generator class="assigned" /&gt;
    &lt;/id&gt;
    &lt;property name="UserName" column="Name" type="String" length="40"/&gt;
    &lt;property name="Password" type="String" length="20"/&gt;
    &lt;property name="EmailAddress" type="String" length="40"/&gt;
    &lt;property name="LastLogon" type="DateTime"/&gt;
  &lt;/class&gt;
&lt;/hibernate-mapping&gt;</pre>
<p>And the startup code is the following.</p>
<pre>static void Main(string[] args)
{
    Configuration cfg = new Configuration();
    cfg.AddXmlFile("NHibernateTest.User.hbm.xml");

    ISessionFactory factory = cfg.BuildSessionFactory();
    ISession session = factory.OpenSession();
    ITransaction transaction = session.BeginTransaction();

    User newUser = new User();
    newUser.Id = "joe_cool";
    newUser.UserName = "Joseph Cool";
    newUser.Password = "abc123";
    newUser.EmailAddress = "joe@cool.com";
    newUser.LastLogon = DateTime.Now;

    // Tell NHibernate that this object should be saved
    session.Save(newUser);

    // commit all of the changes to the DB and close the ISession
    transaction.Commit();
    session.Close();
}</pre>
<p>Annnd, the SQL needed would be the following. Note that the database used is &#8220;NHibernate&#8221;.</p>
<pre>USE [NHibernate]
GO
/****** Object:  Table [dbo].[users]    Script Date: 07/23/2008 22:32:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[users](
	[LogonID] [nvarchar](20) NOT NULL DEFAULT ('0'),
	[Name] [nvarchar](40) NULL DEFAULT (NULL),
	[Password] [nvarchar](20) NULL DEFAULT (NULL),
	[EmailAddress] [nvarchar](40) NULL DEFAULT (NULL),
	[LastLogon] [datetime] NULL DEFAULT (NULL),
PRIMARY KEY CLUSTERED
(
	[LogonID] ASC
)WITH (PAD_INDEX  = OFF,
       STATISTICS_NORECOMPUTE  = OFF,
       IGNORE_DUP_KEY = OFF,
       ALLOW_ROW_LOCKS  = ON,
       ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/serverside/setting-up-nhibernate-20/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Useful shortcuts for Visual Studio</title>
		<link>http://www.svendtofte.com/visual-studio/useful-shortcuts-for-visual-studio/</link>
		<comments>http://www.svendtofte.com/visual-studio/useful-shortcuts-for-visual-studio/#comments</comments>
		<pubDate>Sun, 20 Jul 2008 20:06:26 +0000</pubDate>
		<dc:creator>svendtofte</dc:creator>
		
		<category><![CDATA[Visual Studio]]></category>

		<category><![CDATA[customize]]></category>

		<category><![CDATA[keyboard]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=29</guid>
		<description><![CDATA[I&#8217;ve been using Visual Studio for quite some time now, but I&#8217;ve never really bothered to investigate this important tool too much. I&#8217;ve finally gotten around to check things out, and am I&#8217;m gonna try to learn some techniques to increase effieincy a little bit (almost seems like heresy). First round, I&#8217;ll focus on keyboard [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using Visual Studio for quite some time now, but I&#8217;ve never really bothered to investigate this important tool too much. I&#8217;ve finally gotten around to check things out, and am I&#8217;m gonna try to learn some techniques to increase effieincy a little bit (almost seems like heresy). First round, I&#8217;ll focus on keyboard shortcuts. I&#8217;ve grouped them into 4 categories, navigation, debugging, editing and others, hopefully they are fairly explanatory. Now mind you that these are the default short cuts for Visual Studio for C#, for C++ and VB they may not work (you&#8217;ll have to customize the binding yourself).</p>
<p><span id="more-29"></span></p>
<h3>Navigation</h3>
<style type="text/css">td {height:2.5em;}</style>
<p> <!-- no margins allowed on table cells makes baby jebsu cry --></p>
<table cellspacing="0">
<tr>
<td><span class="keyboard">f12</span></td>
<td>Go to declaration</td>
</tr>
<tr>
<td><span class="keyboard">f7</span></td>
<td>Switch to code view (if applicable)</td>
</tr>
<tr>
<td><span class="keyboard">shift</span>+<span class="keyboard">f7</span></td>
<td>Switch to Switch to designer view (if applicable) </td>
</tr>
<tr>
<td><span class="keyboard">ctrl</span>+<span class="keyboard">i</span></td>
<td>Incremental Search (only current document)</td>
</tr>
<tr>
<td><span class="keyboard">ctrl</span>+<span class="keyboard">shift</span>+<span class="keyboard">i</span></td>
<td>Reverse incremental search (only current document)</td>
</tr>
<tr>
<td><span class="keyboard">ctrl</span>+<span class="keyboard">m</span>,<span class="keyboard">ctrl</span>+<span class="keyboard">m</span></td>
<td>Toggle outline</td>
</tr>
</table>
<h3>Debug</h3>
<p></p>
<table>
<tr>
<td><span class="keyboard">f5</span></td>
<td>Run with debugging</td>
</tr>
<tr>
<td><span class="keyboard">shift</span>+<span class="keyboard">f5</span></td>
<td>Stop debugging</td>
</tr>
<tr>
<td><span class="keyboard">f10</span></td>
<td>Step over</td>
</tr>
<tr>
<td><span class="keyboard">f11</span></td>
<td>Step into</td>
</tr>
<tr>
<td><span class="keyboard">shift</span>+<span class="keyboard">f11</span></td>
<td>Step out</td>
</tr>
<tr>
<td><span class="keyboard">ctrl</span>+<span class="keyboard">f10</span></td>
<td>Run to cursor</td>
</tr>
<tr>
<td><span class="keyboard">f9</span></td>
<td>Toggle a breakpoint</td>
</tr>
</table>
<h3>Editing</h3>
<p></p>
<table>
<tr>
<td><span class="keyboard">ctrl</span>+<span class="keyboard">-</span></td>
<td>Move to previous edit point (back)</td>
</tr>
<tr>
<td><span class="keyboard">ctrl</span>+<span class="keyboard">alt</span>+<span class="keyboard">i</span></td>
<td>Switch to the Immediate window</td>
</tr>
<tr>
<td><span class="keyboard">ctrl</span>+<span class="keyboard">space</span></td>
<td>Intellisense-menu</td>
</tr>
<tr>
<td><span class="keyboard">ctrl</span>+<span class="keyboard">k</span>, <span class="keyboard">ctrl</span>+<span class="keyboard">c</span></td>
<td>Comment selection</td>
</tr>
<tr>
<td><span class="keyboard">ctrl</span>+<span class="keyboard">k</span>, <span class="keyboard">ctrl</span>+<span class="keyboard">u</span></td>
<td>Uncomment selection</td>
</tr>
<tr>
<td><span class="keyboard">ctrl</span>+<span class="keyboard">shift</span>+<span class="keyboard">l</span></td>
<td>Delete line</td>
</tr>
<tr>
<td><span class="keyboard">ctrl</span>+<span class="keyboard">.</span></td>
<td>Resolve namespaces</td>
</tr>
<tr>
<td><span class="keyboard">ctrl</span>+<span class="keyboard">k</span>,<span class="keyboard">ctrl</span>+<span class="keyboard">f</span></td>
<td>Prettify code</td>
</tr>
<tr>
<td><span class="keyboard">ctrl</span>+<span class="keyboard">k</span>,<span class="keyboard">ctrl</span>+<span class="keyboard">s</span></td>
<td>Snippets (also around selection)</td>
</tr>
</table>
<h3>Other</h3>
<p></p>
<table>
<tr>
<td><span class="keyboard">ctrl</span>+<span class="keyboard">shift</span>+<span class="keyboard">b</span></td>
<td>Build solution</td>
</tr>
</table>
<p>&nbsp;</p>
<h2>Configuring shortcuts</h2>
<p> I&#8217;m using a danish keyboard, so the <code>ctrl+-</code> shortcut does not work for me for whatever reason. You can customize your shortcuts by going Tools -> Customize -> Keyboard &#8230; Which brings you to the following dialog. </p>
<div id="attachment_70" class="wp-caption alignnone" style="width: 660px"><a href="http://www.svendtofte.com/wp-content/uploads/2008/07/vs-kbd-custom.png"><img src="http://www.svendtofte.com/wp-content/uploads/2008/07/vs-kbd-custom.png" alt="Visual Studio keyboard customization dialog" title="vs-kbd-custom" width="650" height="351" class="size-full wp-image-70" /></a><p class="wp-caption-text">Visual Studio keyboard customization dialog</p></div>
<p>You&#8217;ll need to locate the shortcut your want to configure first (and there&#8217;s loads). Type in &#8220;back&#8221; into the &#8220;Show commands containing:&#8221;. You should find &#8220;View.NavigateBackwards&#8221; a bit down the last. You can bind it to something else, I use <code>ctrl+´</code>, but whatever works for you.</p>
<h2>Other shortcuts</h2>
<p>As you can see from the list, the amount of bindable actions is very large, and as far as I know not documented at all. Further, they also assume a US keyboard layout (and despite of <a href="http://www.svendtofte.com/wp-content/uploads/2008/07/ibm-model-m-desk.jpg" title="My IBM Model M keyboard">old faithfull </a>, I&#8217;m currently on a Danish keyboard, as it just does make some things easier). But that said, <a href="http://www.codinghorror.com/blog/archives/000412.html">Coding Horror has a great script</a> that will enumerate all of the short cuts, their name, and what object they belong to (View, Edit, etc). Microsoft also has some great looking posters for VB, C# and C++</p>
<ul>
<li>
<p><a href="http://www.microsoft.com/downloadS/details.aspx?FamilyID=e5f902a8-5bb5-4cc6-907e-472809749973&#038;displaylang=en">Visual C# 2008 Keybinding Reference Poster</a> (and for <a href="http://www.microsoft.com/downloadS/details.aspx?familyid=C15D210D-A926-46A8-A586-31F8A2E576FE&#038;displaylang=en">2005</a>)</p>
</li>
<li>
<p><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=255b8cf1-f6bd-4b55-bb42-dd1a69315833&#038;DisplayLang=en">Visual Basic 2008 Keybinding Reference Poster</a></p>
</li>
<li>
<p><a href="http://www.microsoft.com/downloads/details.aspx?familyid=4411BBFC-0E3C-42B3-BD05-AF1D292C986F&#038;displaylang=en">Visual C++ 2008 Keybinding Reference Poster</a></p>
</li>
</ul>
<p>But since those aren&#8217;t editable, and I&#8217;m just not sure I need <em>that many</em> short cuts, I&#8217;ve compiled <a href="http://www.svendtofte.com/wp-content/uploads/2008/07/vs-shortcuts.doc">my own little Word document</a> I&#8217;ll print out, and also list my own bindings in.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/visual-studio/useful-shortcuts-for-visual-studio/feed/</wfw:commentRss>
		</item>
		<item>
		<title>JavaScript date string formatting</title>
		<link>http://www.svendtofte.com/javascript/javascript-date-string-formatting/</link>
		<comments>http://www.svendtofte.com/javascript/javascript-date-string-formatting/#comments</comments>
		<pubDate>Tue, 15 Jul 2008 21:23:20 +0000</pubDate>
		<dc:creator>svendtofte</dc:creator>
		
		<category><![CDATA[JavaScript]]></category>

		<category><![CDATA[date]]></category>

		<category><![CDATA[formatting]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=18</guid>
		<description><![CDATA[Date string formatting is very brutal in JavaScript, which probably has the worst built in library in relation to the distribution this language sees. So a long time ago I whipped up a script file, for doing just this. I always though PHP&#8217;s date function looked very nice, so I decided to model my function [...]]]></description>
			<content:encoded><![CDATA[<p>Date string formatting is very brutal in JavaScript, which probably has the worst built in library in relation to the distribution this language sees. So a long time ago I whipped up a script file, for doing just this. I always though <a href="http://php.net/date">PHP&#8217;s date function</a> looked very nice, so I decided to model my function upon that. </p>
<p><span id="more-18"></span></p>
<p>Download: <a href="http://www.svendtofte.com/wp-content/uploads/2008/07/formatdate.js">formatDate.js</a> (13kB)</p>
<h3>Supported switches and test</h3>
<p>I&#8217;m not going to duplicate <a href="http://php.net/date">PHP&#8217;s documentation</a>. But I will list briefly the supported switches. Basicly, switches should return the same as in PHP, if they don&#8217;t, it&#8217;s most likely in error, so let me know at <script>myEmail();</script>. </p>
<table class="tufteDesign">
<tr>
<td>Supported switches</td>
<td>Unsupported switches</td>
<td>Currently unsupported, but might be included in the future</td>
</tr>
<tr>
<td>a, A, B, c, d, D, F, g, G, h, H, i, I (uppercase i), j, l (lowecase L),  L, m, M, n, N, O, P, r, s, S, t, U, w, W, y, Y, z, Z</td>
<td>T, e, o</td>
<td></td>
</tr>
</table>
<p>Here&#8217;s some examples.</p>
<p><script src="http://www.svendtofte.com/wp-content/uploads/2008/07/formatdate.js"></script><script>
var currDate = new Date();
</script></p>
<table class="tufteDesign">
<tr>
<td>Example</td>
<td>Output</td>
</tr>
<tr>
<td><code>F j, Y, g:i a</code></td>
<td><script>document.write(currDate.formatDate("F j, Y, g:i a"));</script></td>
</tr>
<tr>
<td><code>m.d.y</code></td>
<td><script>document.write(currDate.formatDate("m.d.y"));</script></td>
</tr>
<tr>
<td><code>j, n, Y</code></td>
<td><script>document.write(currDate.formatDate("j, n, Y"));</script></td>
</tr>
<tr>
<td><code>Ymd</code></td>
<td><script>document.write(currDate.formatDate("Ymd"));</script></td>
</tr>
<tr>
<td><code>h-i-s, j-m-y, it is w Day z</code></td>
<td><script>document.write(currDate.formatDate("h-i-s, j-m-y, it is w Day z"));</script></td>
</tr>
<tr>
<td><code>%i%t %i%s %t%h%e jS %d%a%y.</code></td>
<td><script>document.write(currDate.formatDate("%i%t %i%s %t%h%e jS %d%a%y."));</script></td>
</tr>
<tr>
<td><code>D M j G:i:s T Y</code></td>
<td><script>document.write(currDate.formatDate("D M j G:i:s T Y"));</script></td>
</tr>
<tr>
<td><code>H:m:s %m %i%s% %m%o%n%t%h</code></td>
<td><script>document.write(currDate.formatDate("H:m:s %m %i%s% %m%o%n%t%h"));</script></td>
</tr>
<tr>
<td><code>H:i:s</code></td>
<td><script>document.write(currDate.formatDate("H:i:s"));</script></td>
</tr>
</table>
<p>And here you can test your own flags if you should wish.<br />
<script>
function testDateFormat() {
  var inFormat = document.getElementById("dateFormatIn").value;
  var output = document.getElementById("dateFormatOut");
  var d = new Date();
  output.innerHTML = d.formatDate(inFormat);
}
</script></p>
<form onsubmit="return false;">
<p><input type="text" width="20" id="dateFormatIn" value="c"/>
<input type="button" value="hit it!" onclick="testDateFormat();return false;" /> output: <code><span id="dateFormatOut"></span></code></p>
</form>
<h3>Differences and gotchas</h3>
<p>You should note quite quickly that you use <code>%</code> to escape, not backslash (<code>\</code>). PHP gets to treat strings a bit different, and frankly, <code>\\d\\u\\m\\b</code> looks stupid (not to mention the quadruple escape, <code>\\\\</code>, if you want a <em>single</em> backslash in your output).</p>
<p>Another thing to note is that this code operates either directly on a Date object (which always have a time set), or a passed in value, which it interprets as a date. <em>The script doesn&#8217;t help you in any way in setting a time.</em> As a developer, you need to be careful when juggling dates on the client side, and also if you create any dates, don&#8217;t make assumptions regarding what timezone the runtime thinks it is.</p>
<p>I&#8217;ve obsoleted my old page, though <a href="/code/date_format/_index.php">it&#8217;s still on the site under a different name</a>. It had some more rigerous testing (it&#8217;s using the old version of the script so take care), and also some stuff about localization which I don&#8217;t really think is that interesting anyway.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/javascript/javascript-date-string-formatting/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Anyone else tired of w3schools?</title>
		<link>http://www.svendtofte.com/other/anyone-else-tired-of-w3schools/</link>
		<comments>http://www.svendtofte.com/other/anyone-else-tired-of-w3schools/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 23:32:22 +0000</pubDate>
		<dc:creator>svendtofte</dc:creator>
		
		<category><![CDATA[Other]]></category>

		<category><![CDATA[reference]]></category>

		<category><![CDATA[Stylesheets]]></category>

		<category><![CDATA[w3schools]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=16</guid>
		<description><![CDATA[&#8230; and the mediocre content they provide? I&#8217;m especially tired of the high ranking they (still) get in google. I go to hit google with &#8220;PlaceHolder asp.net&#8221;, and w3schools is the second hit. If you go read their page it has barely 3 lines regarding this control (highlighted with red outline), the remaining details are [...]]]></description>
			<content:encoded><![CDATA[<p>&#8230; and the mediocre content they provide? I&#8217;m especially tired of the high ranking they <em>(still)</em> get in google. I go to hit google with &#8220;PlaceHolder asp.net&#8221;, and w3schools is <a href="http://www.google.com/search?q=asp.net+PlaceHolder">the second hit</a>. If you go read their page it has <em>barely 3 lines</em> regarding this control (highlighted with red outline), the remaining details are simply aggregate data, or advertising (outlined with green, doesn&#8217;t include all the further ads you&#8217;d see if you had scrolled down).</p>
<p class="imgWithCaption"><img src="http://www.svendtofte.com/wp-content/uploads/2008/07/documentation-galore.gif" alt="w3schools webpage screenshot" title="documentation-galore" width="500" height="475" class="alignnone size-full wp-image-17" /><br />
w3schools &#8220;3 lines of documentation&#8221; regarding the ASP.NET PlaceHolder class.</p>
<p>I mean, this is a total joke. When did w3schools start out? 2000? They became popular with their concise CSS properties listings back in the day. But seriously, it&#8217;s like this site is frozen in time. Their CSS reference point is <a href="http://www.w3.org/TR/REC-CSS2/">2.0 from 1998</a> (not that a mere properties reference would list much different from 2.0 and 2.1, but there are some <a href="http://www.w3.org/TR/CSS21/changes.html#new">minor additions</a>.) I would prefer they would work on updating their CSS reference instead of wasting time on ASP.NET.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/other/anyone-else-tired-of-w3schools/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Blogrolls and links</title>
		<link>http://www.svendtofte.com/other/blogrolls-and-links/</link>
		<comments>http://www.svendtofte.com/other/blogrolls-and-links/#comments</comments>
		<pubDate>Sun, 06 Jul 2008 21:43:17 +0000</pubDate>
		<dc:creator>svendtofte</dc:creator>
		
		<category><![CDATA[Other]]></category>

		<category><![CDATA[blogrolls]]></category>

		<category><![CDATA[bookmarks]]></category>

		<category><![CDATA[content]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=12</guid>
		<description><![CDATA[I guess I think of many things as arrogant. I guess it also strikes me as somewhat arrogant that visitors to my site should somehow be interested in whatever random links I might have, especially when they are so generics as to be included in &#8220;blogrolls&#8221;, or whatever the term seems to be.
There&#8217;s enough &#8220;interesting [...]]]></description>
			<content:encoded><![CDATA[<p>I guess I think of many things as arrogant. I guess it also strikes me as somewhat arrogant that visitors to my site should somehow be interested in whatever random links I might have, especially when they are so generics as to be included in &#8220;blogrolls&#8221;, or whatever the term seems to be.</p>
<p>There&#8217;s enough &#8220;<a href="http://www.stumbleupon.com/">interesting</a> <a href="http://del.icio.us/">link</a> <a href="http://digg.com/">sites</a>&#8221; services out there there&#8217;s just no need to attempt to present down my perhaps 4-5 daily site checks as somehow unique. They aren&#8217;t. I check <a href="http://blogs.msdn.com/oldnewthing/default.aspx" title="Win32 developtment blog">the old new thing</a> now and then. I read <a href="http://www.computerworld.dk/" title="Danish Computer News portal/site">Computerworld.dk</a> to get a view of how the landscape of the danish commercial software scene. I wish I was cool and spent alot of time on <a href="http://lambda-the-ultimate.org/" title="Programming language news site">Lambda the Ultimate</a>, but I&#8217;m not, so I just visit it every few weeks and poke around. </p>
<p>Overall it just seems like we&#8217;re building paths to everywhere. But it&#8217;s nice to <em>arrive</em> as well. And I guess I wish for this site to be a destination for some people (and maybe helpful as well). Feel free to hit your back button now!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/other/blogrolls-and-links/feed/</wfw:commentRss>
		</item>
		<item>
		<title>IE formatting oddity</title>
		<link>http://www.svendtofte.com/stylesheets/ie-formatting-oddity/</link>
		<comments>http://www.svendtofte.com/stylesheets/ie-formatting-oddity/#comments</comments>
		<pubDate>Sun, 06 Jul 2008 18:19:09 +0000</pubDate>
		<dc:creator>svendtofte</dc:creator>
		
		<category><![CDATA[Stylesheets]]></category>

		<category><![CDATA[CSS]]></category>

		<category><![CDATA[error]]></category>

		<category><![CDATA[internet explorer]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=9</guid>
		<description><![CDATA[It&#8217;s good to know that within 1 day of returning to any amount of CSS work, Internet Explorer can still baffle me. Maybe I&#8217;m missing something here, but seems that if a small tag (yes, let the damnations begin, but it was mostly due to the WordPress default template using it, that I came across [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s good to know that within 1 day of returning to any amount of CSS work, Internet Explorer can still baffle me. Maybe I&#8217;m missing something here, but seems that if a <code>small</code> tag (yes, let the damnations begin, but it was mostly due to the WordPress default template using it, that I came across it) does not include some <em>trailing whitespace</em>, it receives a little extra padding.</p>
<p class="imgWithCaption">
<img src="http://www.svendtofte.com/wp-content/uploads/2008/07/small_margin.gif" width="435" height="338" alt="Small element rendering comparison" /><br />
Rendering oddity with <code>small</code> tags with no trailing whitespace.
</p>
<p>The HTML code used validates, <a href="http://www.svendtofte.com/wp-content/uploads/2008/07/wth_ie.html">should you wish to inspect it yourself</a>. The &#8220;CSS1Compat&#8221; mode is merely to ensure we&#8217;re in &#8220;standards mode&#8221;. </p>
<pre>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" dir="ltr"&gt;
&lt;head&gt;&lt;title&gt;wth ie&lt;/title&gt;
&lt;style type="text/css"&gt;
h2{
background-color:red;
margin-bottom:0;}

.wth {
background-color:green;
margin-top:0;}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;

&lt;h2&gt;foo&lt;/h2&gt;    &lt;small class="wth"&gt; b ar &lt;/small&gt;

&lt;h2&gt;foo&lt;/h2&gt;    &lt;small class="wth"&gt; b az&lt;/small&gt;

&lt;hr/&gt;
&lt;script type="text/javascript"&gt;
document.write(document.compatMode);
&lt;/script&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
<p>You&#8217;ll notice I remove all margin on the elements. And indeed, the first header <code>h2</code> and <code>small</code> does render correctly. But the second gets a 2 pixel margin added for &#8230; who knows what reason. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/stylesheets/ie-formatting-oddity/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Reflections on max-width</title>
		<link>http://www.svendtofte.com/stylesheets/reflections-on-max-width/</link>
		<comments>http://www.svendtofte.com/stylesheets/reflections-on-max-width/#comments</comments>
		<pubDate>Sat, 05 Jul 2008 01:52:45 +0000</pubDate>
		<dc:creator>svendtofte</dc:creator>
		
		<category><![CDATA[Stylesheets]]></category>

		<category><![CDATA[browsers]]></category>

		<category><![CDATA[CSS]]></category>

		<category><![CDATA[hacks]]></category>

		<category><![CDATA[internet explorer]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=4</guid>
		<description><![CDATA[A couple of years ago, I added a page to my old site on an &#8220;easy&#8221; fix for emulating max-width behavior in Internet Explorer, by utilizing a powerful IE5 feature called dynamix properties/expressions.
Briefly, these expressions allow a web author to hook script expressions into the dynamic nature of HTML elements. The natural events of the [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of years ago, I added a page to my old site on an &#8220;easy&#8221; fix for emulating max-width behavior in Internet Explorer, by utilizing a powerful IE5 feature called <a href="http://msdn.microsoft.com/en-us/library/ms537634.aspx">dynamix properties/expressions.</a></p>
<p>Briefly, these expressions allow a web author to hook script expressions into the dynamic nature of HTML elements. The natural events of the page (<code>onresize</code>, <code>onclick</code>, <code>onmouseover</code> and so on) causing these expressions to be re-evaluated whenever content could possibly reflow. The effect is naturally very powerful.</p>
<p><span id="more-4"></span></p>
<pre>&lt;html&gt;
&lt;head&gt;
&lt;style&gt;
#container {
width:expression(this.parentElement.clientWidth-100);
background-color:red;}
&lt;/style&gt;
&lt;/head&gt;
&lt;body style="background-color:blue;"&gt;
&lt;div id="container"&gt;foo&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>The effect is unique, and should be obvious to anyone that this allows for very powerful behavior.</p>
<h3>A problem of foresight</h3>
<p>I&#8217;ll try to explain the motive for posting my old article, <a href="http://www.svendtofte.com/code/max_width_in_ie/">max-width in Internet Explorer</a>. First off, at the time I was studying alot of <a href="http://en.wikipedia.org/wiki/Human-computer_interaction"><abbr title="Human-computer interaction">HCI</abbr></a>. So while making a HTML site for a school related project, I saw a good excuse for sounding clever about line-widths. Even with most of that stuff holding true, I simply didn&#8217;t think through the ramifications of posting this &#8220;hack&#8221;. And for a large part, I simply wanted to sell the <code>expression</code> technique, as I feel it&#8217;s extremely powerful, and many developers are unfamiliar with it. So I cooked up what seemed at the time as a &#8220;elegant&#8221; solution to this max-width problem.</p>
<p>I&#8217;ve received more email about this article then anything else ever on my site (quick hit in my inbox says hundreds of mails containing <code>max-width</code>). I still receive mail about it, with IE7 supporting max-width and the related properties. So, for a very long time, I&#8217;ve wanted to &#8220;set things straight&#8221;, and I shall attempt to do this here.</p>
<h3>Not for the faint-hearted</h3>
<p>As I noted, expressions are very powerful. To fully utilize and appreciate raw expressions you <em>need</em> a solid understanding of scripting, stylesheets and how they interact in Internet Explorer, and especially you need to understand how IE works, with &#8220;<a href="http://msdn.microsoft.com/en-us/library/ms533687(VS.85).aspx">standards mode</a>&#8220;, and the <a href="http://en.wikipedia.org/wiki/Internet_Explorer_box_model_bug">old-time box-model</a>.</p>
<h4>&#8220;Houston, we have a problem&#8221;</h4>
<p>So, let&#8217;s explorer some of the problems we can run into. First off, this technique <em>may look like a style</em> in the presentation given above, but <em>it&#8217;s behavior is anything but</em>. First off, the <code>expression</code> construct used above is simply &#8220;short hand&#8221; for the <a href="http://msdn.microsoft.com/en-us/library/ms531196(VS.85).aspx"><code>setExpression</code></a> function. This means that once IE encounters the <code>expression</code> construct it <em>binds the code directly to the object</em>. If you use any fancy DOM work to disable either the entire stylesheet (stylesheet switching) or just to kill a single element, it won&#8217;t work as the expression is already bound to the actual elements. It should be easy to see in this example where <a href="http://www.svendtofte.com/wp-content/uploads/2008/07/expr_sticks.html">you can easily kill the stylesheet</a>, but observe how the <code>background-color</code> style sticks regardless.</p>
<h4>Far side of the moon</h4>
<p>Let&#8217;s examine the actual code I posted in that old article. You can see the example of <a href="http://www.svendtofte.com/wp-content/uploads/2008/07/maxwidth.html">a simulated max-width</a> here, but remember this only works in IE.</p>
<pre>&lt;html&gt;
&lt;style&gt;
body {
width:100%;
margin:0;
padding:0;}

p {
border:1px solid red;
max-width:800px;
width:expression(document.body.clientWidth &gt; 800? "800px": "auto" );
}
&lt;/style&gt;
&lt;body&gt;
&lt;p&gt;
[alot of text]
&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>If you try it out in IE, it&#8217;s <em>perfect</em>. The red line is never past the view port of the browser, never does any scroll bar appear, and so on. It looks like a spot on emulation (and for this little example, it is). The code is deceptively simple, if <code>body.clientWidth</code> is more then 800 pixels wide, then we enforce a <code>width</code> of 800 pixels. Super simple and straight forward right? </p>
<p>Now, what assumptions are at work here? Well, a huge assumption is that the <code>body</code> element (or rather, the <a href="http://www.w3.org/TR/REC-CSS2/visudet.html#x0">containing box</a> of the content we wish to apply a maximum width to has no padding and/or margin. Another (more dangerous assumption) is that <em>the box model applied is the old non-standards compliant box model</em>. Another problem is that we&#8217;re working in pixels. The entire point of the article was to discuss line-lenghts. Falling back on the pixel defeats that idea. The basic problem is that it&#8217;s just so hard to retrieve information about an elements size using relative units, so I just &#8220;wing&#8221; it a bit in the article, which helps no one.</p>
<h4>Crashing hard</h4>
<p>Now, let&#8217;s see what happens when we change some of those assumptions. First off, including a proper DOCTYPE in the document causes IE to change the box model used. This will cause borders, padding, etc to not be counted towards the width of the element. This in itself isn&#8217;t so bad, it merely causes the &#8220;effect&#8221; to appear more jittery.</p>
<p>It&#8217;s far worse, if you try to apply the max-width to an element whose own width is dependent on the elements contained within. Reflowing content causes the onresize event to fire, which in turn may cause an infinite loop. <a href="http://www.svendtofte.com/wp-content/uploads/2008/07/hanging_maxwidth.html">Look at the following code same code from before</a>. <strong>WARNING: this code is designed to hang your browser if you use any older version of Internet Explorer</strong>.</p>
<pre>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;style&gt;
body {
width:100%;
margin:0;
padding:0;}

div {
background-color:green;}

p {
border:10px solid red;
padding:10px;
margin:10px;
width:expression(foo());
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id="ctb"&gt;
&lt;p&gt;
&lt;script&gt;
document.write(document.compatMode);

function foo() {
	return (ctb.offsetWidth &gt; 800 ? "auto" : "800px");
}
&lt;/script&gt;
[alot of text]
&lt;/p&gt;

&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Things to note is that a <code>DOCTYPE</code> has been added, a containing box for the paragraph has been added, and some margins and padding added as well. If you attempt to run this code in IE6 (seems this has been fixed for IE7), the browser simply locks up hard, and here&#8217;s why. The paragraph will tell itself to be 800 pixels wide when the <code>ctb</code> element shrinks to any less (<code>min-width</code>). Now due to the padding and margins I&#8217;ve added, the paragraphs width will add up to 820 pixels. This will cause the <code>ctb</code> element to widen to contain it, and suddenly it&#8217;s wider then 800 pixels, and poof, the script expression thinks the width should be <code>auto</code>. The paragraph, with it&#8217;s new setting of <code>width: auto;</code> snaps down in width, to fit within the browser window, and in turn, meaning that <code>ctb</code> can size down as well, and then the whole affair just starts over. And <em>infinite loop</em>, and it locks the browser up.</p>
<p>And I think <strong>locking the browser up in this manner is about as crappily as you can treat any visitor to your site</strong>.</p>
<p>As aside, I can note that there has been some fixes to IE, to prevent the browser from hanging. First off, <em>the above code actually works in IE 7</em>. It hangs IE 6. But in order to cause it to hang, I had to swap the code out into it&#8217;s own function. If I inline the code, IE 6 just ignores the code completely, presumably using some heuristics to sniff out that this isn&#8217;t really code it wants to execute.</p>
<h3>Solutions</h3>
<p>I think the time for solutions is well past. Back in the day, Dead Edwards had a hancy HTC you could add to pages, to make IE implement all sorts of CSS properties, including max-width (seems he <a href="http://code.google.com/p/ie7-js/">continues to do this</a>). I would probably have recommended that, as that was probably a more solid drag-and-drop solution.</p>
<p>At any rate, I&#8217;ve always had a sour taste in my mouth with my old page, and I&#8217;ve tried a sort of carthasis with this post, trying to wash some of it out. I&#8217;ve never been a fan of the popular &#8220;hacks&#8221; that started to develop once Cascading Stylesheets started to catch on like wildfire. It seems to me, that relying on broken behavior in very specific versions of browsers is just stupid. It&#8217;s basicly against everything most web developers wish for when they look at a page rendering in Firefox and IE, and wish they looked the same. Refusing to accept a &#8220;blemish&#8221; on your page, and instead resorting to hacks (of which mine was admittedly the worst) to make sure your vision is presented faithfully to the visitor just smacks of arrogance to me.</p>
<p>I&#8217;ve long since stopped working at the yoke of the visual designers with photoshop files being sent my way by, and as such, I&#8217;m not entirely sure how the industry works in practise. But I sincerely hope that it has matured enough to accept imperfections, and see them for what they really are; an expression of the open nature of the web.</p>
<p>Littering our pages with browser specific hacks is no better then client sniffing code. Each time we introduce a browser specific feature on our sites, the web gets to be a little bit messier. The IE team at Microsoft has <a href="http://blogs.msdn.com/ie/archive/2008/01/21/compatibility-and-ie8.aspx">a pertinent article on what writing these browsers are like.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/stylesheets/reflections-on-max-width/feed/</wfw:commentRss>
		</item>
		<item>
		<title>First post</title>
		<link>http://www.svendtofte.com/other/first-post/</link>
		<comments>http://www.svendtofte.com/other/first-post/#comments</comments>
		<pubDate>Thu, 03 Jul 2008 21:36:04 +0000</pubDate>
		<dc:creator>svendtofte</dc:creator>
		
		<category><![CDATA[Other]]></category>

		<category><![CDATA[first post]]></category>

		<guid isPermaLink="false">http://www.svendtofte.com/?p=3</guid>
		<description><![CDATA[Riding high on the technology wave of the last millenium, I&#8217;ve finally gotten around to getting an actual genuine blog. I spent about a week tweaking the WordPress platform, look and code to make it appear more or less like my old site.
My old site had a very article &#8220;centric&#8221; look, and I&#8217;m not entirely [...]]]></description>
			<content:encoded><![CDATA[<p>Riding high on the technology wave of the <i>last millenium</i>, I&#8217;ve finally gotten around to getting an actual genuine blog. I spent about a week tweaking the WordPress platform, look and code to make it appear more or less like my old site.</p>
<p>My old site had a very article &#8220;centric&#8221; look, and I&#8217;m not entirely sure I managed to translate that look and feel over to a more snippet oriented 2 column classic blog format. But mostly because this new software just contains so many more pages then my old did. So still lots of stuff to do; I need to get around to looking at making some nice URLs, instead of these horrible <code>?id=213</code> URL fragments that floats around. The site probably doesn&#8217;t validate. And overall need to check that the site works in all it&#8217;s little niches &#8230;</p>
<p>Oh, and if you&#8217;re looking for the old stuff, the content is in all the usual places, haven&#8217;t deleted any content, and until such a time as I get the old front page index and possibly content ported over (still not sure how to handle that), <a href="old.index.php">here&#8217;s a link to the old index page.</a></p>
<p>And this makes for my &#8230; 8th or so iteration of my site, which has lived on this domain since 2001, and on a few others for a few years before that. And I wish to send my gratitude to my <a href="http://www.bitmand.dk/" rel="friend met co-worker">friend Lasse</a>, for providing great hosting ever since my <a href="http://web.archive.org/web/20020923150532/http://svend.neoideo.dk/">former domain</a> went defunct in late 2002.</p>
<p>But anyway. I&#8217;m very happy to finally have a blog and having it gotten launched tonight.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.svendtofte.com/other/first-post/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
