Archive for the ‘Programming’ Category

Understanding UTF and ANSI encoding

Thursday, January 8th, 2009

I am pretty sure that I am not the only one who have had trouble with encoding when dealing with XML especially when reading from system to another. I found a good post that I will paste here mostly for my own reference next time when someone asks why I cannot read his ANSI XML even he puts UTF-8 on the XML definition.

–clip–

he Basics
Letters are represented in a computer by numeric codes. Pretty much everybody agrees that, when the computer sees a code of 100 (decimal), it represents a lowercase “d”. We don’t all agree on what 250 represents, and therein lies the rub.

ASCII vs ANSI
We commonly refer to character encoding as a letter’s “ASCII value,” when we really mean “ANSI value.” A lot of the time that’s sufficient, but in fact the ASCII standard is pretty much obsolete.

ASCII (American Standard Code for Information Interchange) is a 7-bit standard that has been around since the late 1950s (its current incarnation dates from 1968). It defines 128 different characters, which is more than enough for English: upper- and lowercase letters, punctuation, numerals, control codes (remember control-c?), and nonprinting codes such as tab, return, and backspace.

ASCII and ANSI are pretty good as long as you are western European. These two mappings are extremely limited in that they may only code (i.e. assign a number to) 256 letters, so that there is no space to include other glyphs from other languages.

Unicode
Unicode fixes the limitations of ASCII and ANSI, by providing enough space for over a million different symbols. Like the above two systems, each character is given a number, so that Russian ? is 042F, and the Korean won symbol ? is 20A9. (Note that all Unicode numbers are Hexadecimal, meaning that one counts by 16’s not 10’s, not a problem as users really don’t need to know the mapping numbers anyway.) So, although not yet totally comprehensive, Unicode covers most of the world’s writing systems. Most importantly, the mapping is consistent, so that any user anywhere on any computer has the same encoding as everyone else, no matter what font is being used.

So Unicode is a map, a chart of (what will one day be) all of the characters, letters, symbols, punctuation marks, etc. necessary for writing all of the world’s languages past and present.

What is the difference between UTF-8, UTF-16?
UTF-8 uses variable byte to store a Unicode. In different code range, it has its own code length, varies from 1 byte to 6 bytes. Because it varies from 8 bits (1 byte), it is so called “UTF-8″. UTF-8 is suitable for using on Internet, networks or some kind of applications that needs to use slow connection.

Unicode (or UCS) Transformation Format, 16-bit encoding form. The UTF-16 is the Unicode Transformation Format that serializes a Unicode scalar value (code point) as a sequence of two bytes, in either big-endian or little-endian format. Because it is grouped by 16-bits (2 bytes), it is also called “UTF-16″, which is the most commonly used standard.

Source: http://forum.iopus.com/viewtopic.php?t=2783

–clip–

Customize VS.NET 2008

Friday, November 14th, 2008

I started to use color themes in VS.NET 2005 (after reading Hanselman post about it) and I really liked more dark color than default white. It is somehow easier for eye, imho.

Anyhooooow here are couple of links for pimping Visual Studio 2008. I found many intresting posts from Norwegian developers (I don’t know how I end up to click around Norwegian blog roll) Some intresing stuff I haven’t personally tried yet AnkhSVN – Adds Subversion Source Control Management features to Visual Studio. Open source / free.

Chech out more at Lars Wilhelmsen post Pimp my Visual Studio (2008) also this and this post is worth of checking out if you are intrested to see different apps that may help your daily coding/testing.

Is XSLT dead in Microsoft world?

Monday, November 19th, 2007

Back in 2001 I was in TechEd Barcelona where Microsoft unveiled Sharepoint and .NET 1.o. I remember like yesterday when Don Box was demoing WebServices from bathtub (SOAP) and coding c# from MacBook in Microsoft event!.

Anyway, after seeing Microsoft’s plan for following years I decided fully focus on Microsoft Technology. I saw first SharePoint which I think sucked. WebServices weren’t interesting either it just felt a bit too hairy for doing simple things. But what I loved was the whole concept of ASP.NET, C# and XML. After seeing XSLT in action I knew this is going to be my language, and it was. Well at least until now. XSLT is really great for templating websites, I gone through many tempalting engines but nothing beats good old XML/XSLT transformations. It is simple and fast. Well, it can get complex sometimes but usually when XSLT gets complex it means you are doing something wrong. Then it’s time to stop and think. Maybe, this is faster in code-behind or perhaps maybe it’s a good idea to write XSL -helper in code-behind for this.

I have to say, I have never come comfortable building sites from .NET controls basically because it was producing bad html markup-up and I don’t have full control how to build html on it but Microsoft has made it better over the time and nowadays it even produces valid mark-up. But still, I have to compile a DLL when making small updates. This is where XSLT rocks!

Because of this, I have waited (.NET 1.1)… and I have waited (.NET 2.0-3.5)… but there hasn’t been XSLT 2.0. Recently I read blog post in XML.com from M. David Peterson I am quoting him who quotes Microsoft XML Team’s WebLog : Chris Lovett Interview

“As for XSLT 2.0 – we’ve heard from customers and understand the improvements in XSLT 2.0 over XSLT 1.0, but right now we’re in the middle of a big strategic investment in LINQ and EDM for the future of the data programming platform which we think will create major improvements in programming against all types of data.”

DAMN!

Bad news for me… Now with all MVC/LINQ/WEB2.0 stuff… Isn’t XML cool anymore?

Simon Willison talks about OpenID

Wednesday, July 18th, 2007

[kml_flashembed movie="http://www.viddler.com/player/55d12336/" width="437" height="370"/]

Sorting Sitecore data to multicolumn html table

Sunday, May 27th, 2007

Sorting Sitecore data to multicolumn html table is quite hard in XSLT because data in XML is not sorted by item/@sortorder.

I finally found out how to do this so it will actually work and I am not loosing data. The trick is creating data first into a flat XML Nodeset and looping this data then to a multicolumn table using following-sibling::item commands. Here is the small sample code for this where I take abstract content structure from the Sitecore to a XML Nodeset <ul><li>xxxxxx</li></ul>.

First let’s make a variable.

<xsl:variable name=”keywords”>
<ul>
<xsl:for-each select=”$keywords”>
<xsl:for-each select=”descendant-or-self::item[(@template='keywords')]“>
<li>
<xsl:value-of select=”sc:fld(‘text’,.)”/>
</li>
</xsl:for-each>
</xsl:for-each>
</ul>
</xsl:variable>

Then using msxsl:node-set -function (http://msdn2.microsoft.com/en-us/library/hz88kef0(vs.71).aspx) I create nodeset out of the XSL variable and loop data to the html table.

<table>
<xsl:for-each select=”msxsl:node-set($keywords)/ul/li[position() mod 3 = 1]“>
<tr>
<td>
<xsl:value-of select=”.”/>
</td>
<xsl:for-each select=”following-sibling::li[position() < 3]“>
<td>
<xsl:value-of select=”.”/>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</table>

I would be very keen to know if you have done this in pure XSLT because msxsl:node-set seems to be quite slow.

From VSS to SVN

Tuesday, June 20th, 2006

I have been using MS Visual SourceSafe for source control in my work since 99 and I have never liked it. It has very limited features and not to mention random database crashes. If there is a one product I would like to send invoice to its creator from loose hours this would be it. It is a really bad product and nobody should use it.

Last year however I found a life savior. I made one project with Subversion SVN and it was a instant hit in my world. SVN delivers exactly what I need for developing projects, I can put everything to SVN not only code. Contracts, Specs, Photoshop layouts, Patches, DLL’s you name it.

Here is a little check list I found from MSDN Forums, this get’s you started with SVN.

  • TortoiseSVN, a good Windows Explorer extension, despite it’s lack of support of Unicode support in any of its Diff tools. http://tortoisesvn.tigris.org/download.html
  • AnkhSVN -not a true SCC plug-in, instead works as an add-in, but has much better functionality that the other couple of SCC controls that I’ve tried. http://ankhsvn.tigris.org/
  • SVN Explorer - pretty basic tool, but at least provides a stable Explorer-like stand-alone repository explorer. http://kafana.org/SvnExplorer/
  • WinMerge – an excellent freeware open-source file Difference viewer, and merge tool WITH unicode support (use the WinMergeU.exe file). http://winmerge.sourceforge.net/downloads.php
  • imageDiff – good free tool for comparing two images for changes. http://www.download.com/ImageDiff/3000-2192_4-10401779.html. Note: connects to the internet to display ads in a pane at the bottom, but if you use Zonealarm, then disable Internet access, whilst allowing access to the trusted zone. This prevents the program from freezing, without allowing it to display ads.
  • Finally – WebReports8, another VSS.NET add-in. I haven’t actually finished trying this, but it has some nice features. You’ll have to re-compile it with the “_scc” option. See here http://www.codeproject.com/dotnet/file_diff_and_webreports.asp#xx1167087xx read the details on the modification that needs to be performed, then scroll up to the main article)

Simple Sharing Extensions for RSS and OPML

Monday, November 21st, 2005

Microsoft has unveiled a new proposal called SSE, which stands for Simple Sharing Extensions for RSS and OPML. The SSE specification is under a Creative Commons license ? Attribution-ShareAlike.
This is looking really interesting, there is more blog posts about it at Dave Winer’s Scripting News, TechCrunch and Alex Barnett.

Converting xsl:variable to nodeset

Thursday, November 3rd, 2005

The msxsl:node-set function enables you to convert a result tree fragment into a node set. The resulting node set always contains a single node and is the root node of the tree.

<xsl:variable name="books">
<book author="Michael Howard">Writing Secure Code</book>
<book author="Michael Kay">XSLT Reference</book>
</xsl:variable>

<authors>
<xsl:for-each select="msxsl:node-set($books)/book">
<author><xsl:value-of select="@author"/)</author>
</xsl:for-each>
</authors>

Moving to vectorial

Sunday, September 18th, 2005

Last 1.5 years I have been drifting towards Linux world since Microsoft has been pretty much dead when it comes to interesting stuff for web developers. I can see that Microsoft is working hard on creating new API’s like XAML which is (IMHO) from web developer’s point of view quite useless. Hopefully someone in Microsoft soon wakes up for SVG.

I have been running latest Ubuntu on my laptop which works like a charm. But still I have windows in dual boot because I need to sometimes work on Photoshop, Flash and Visual Studio. But slowly I have started to move my development environment to Linux.

I think SVG is going to be big in following years; SVG has more potential than XAML simply because SVG was designed for web and it’s part of web standard. It will revolutionize interface in internet as well as on operating systems. Therefore I have decided to start move to SVG world with the Mono, Cairo and Gtk+. Gtk+ is a library used to build GUI applications on UNIX and the heart of the Gnome desktop. Gtk+ is built on top of the 2D graphics engine Cairo which released version 1.0 in August: every widget is now written using Cairo operations and most importantly developers can now draw their own widgets using the PDF-like rendering model offered by Cairo.

Cairo also brings to the end user nice touches like anti-aliased rendering for a more pleasant experience. Gtk builds on this new functionality to bring vector-based themes to the desktop as well.

AJAX links

Sunday, May 29th, 2005

Developers and designers have come really crazy about AJAX. I started to look for AJAX framework for some simple form validation and I found huge amount of code samples and frameworks which are under development or already on version 5.0.

(more…)