Thursday, October 20, 2011

XML Parser using XmlReader from an XML string in C#

System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
Byte[] pBytes = encoding.GetBytes(strXML);
MemoryStream pMem = new MemoryStream(pBytes, 0, pBytes.Length, true, true);
XmlReader reader = XmlReader.Create(pMem);
string s = Encoding.UTF8.GetString(pMem.GetBuffer(), 0, (int)pMem.Position);
XmlElement element;
XmlDocument xmlDoc = new XmlDocument();
pMem.Seek(0, SeekOrigin.Begin);


while (reader.Read())
{
XmlNode node = null;
switch (reader.NodeType)
{
case XmlNodeType.Element:
bool fEmptyElement = reader.IsEmptyElement;
element = xmlDoc.CreateElement(reader.Prefix, reader.LocalName, reader.NamespaceURI);
//element.IsEmpty = fEmptyElement;
//ReadAttributes(reader, element);
//if (!fEmptyElement) {
//parent.AppendChild(element);
//parent = element;
//continue;
//}
//node = element;
break;

case XmlNodeType.EndElement:
//if (parent.ParentNode == null)
//{
// syntax error in document.
// IXmlLineInfo li = (IXmlLineInfo)reader;
// throw new XmlException(string.Format(SR.UnexpectedToken,"", li.LineNumber, li.LinePosition), null, li.LineNumber, li.LinePosition);
// }
//parent = parent.ParentNode;
continue;

case XmlNodeType.EntityReference:
if (reader.CanResolveEntity)
{
reader.ResolveEntity();
}
continue;

case XmlNodeType.EndEntity:
continue;

case XmlNodeType.Attribute:
//node = LoadAttributeNode(parent);
break;

case XmlNodeType.Text:
node = xmlDoc.CreateTextNode(reader.Value);
break;

case XmlNodeType.SignificantWhitespace:
node = xmlDoc.CreateSignificantWhitespace(reader.Value);
break;

case XmlNodeType.Whitespace:
//if (preserveWhitespace) {
// node = xmlDoc.CreateWhitespace(reader.Value);
// break;
//}
//else {
//continue;
//}
continue;
case XmlNodeType.CDATA:
node = xmlDoc.CreateCDataSection(reader.Value);
break;

case XmlNodeType.XmlDeclaration:
break;

case XmlNodeType.ProcessingInstruction:
node = xmlDoc.CreateProcessingInstruction(reader.Name, reader.Value);
break;

case XmlNodeType.Comment:
node = xmlDoc.CreateComment(reader.Value);
break;

case XmlNodeType.DocumentType:
string pubid = r.GetAttribute("PUBLIC");
string sysid = r.GetAttribute("SYSTEM");
node = xmlDoc.CreateDocumentType(reader.Name, pubid, sysid, reader.Value);
break;

default:
//UnexpectedNodeType(reader.NodeType);
break;
}
}

Monday, October 17, 2011

SearchIndexer.exe really suck !!!

Will slow down your computer bit time....
Will suck 1 GB of memory in less than 5 minutes....

Whoever wrote this at Microsoft should be fire!!!

Turn off indexing and speed up Windows XP
If you don't use Windows XP's built-in search often (like every day), disabling indexing can significantly speed up your PC.

By default Windows XP indexes files on your hard drive and stores them in memory to speed up its' built-in search. But if you rarely use Windows search, turn off indexing to free up memory and CPU horsepower for the files and applications you actually do use. A few simple how-to steps after the jump.

To turn off indexing:

Open up "My Computer."
Right-click on your hard drive (usually "C:") and choose "Properties."
Uncheck the box at the bottom that reads "Allow Indexing Service to..."
Click OK, and files will be removed from memory. This removal may take a few minutes to complete.
To disable the indexing service:

In the "Start" menu, choose "Run."
Type "services.msc" and press Enter.
Scroll-down to "Indexing Service" and double-click it.
If the service status is "Running", then stop it by pressing the "Stop" button.
To make sure this service doesn't run again, under "Startup Type:", choose "Disabled."
Windows search will still work if you perform these steps, but it will work more slowly than if indexing was enabled.

Brute force WTF (aka What The Fuck!)

And to avoid rebooting the machine kill the process searchindexer.exe point to C:\WINDOWS\system32 and rename searchindexer.exe to searchindexer.exe.old.
This time you should be good. If you don't rename searchindexer.exe process will be automatically restarted....

Thursday, October 13, 2011

Farewell Dennis Ritchie

int main( int argc, char **argv )
{
printf( "Goodbye, world. :(\n" );
}



L'eulogie par Bjarne Stroustrup:

"
Before C, there was far more hardware diversity than we see in the
industry today. Computers proudly sported not just deliciously
different and offbeat instruction sets, but varied wildly in almost
everything, right down to even things as fundamental as character bit
widths (8 bits per byte doesn’t suit you? how about 9? or 7? or how
about sometimes 6 and sometimes 12?) and memory addressing (don’t like
16-bit pointers? how about 18-bit pointers, and oh by the way those
aren’t pointers to bytes, they’re pointers to words?).

There was no such thing as a general-purpose program that was both
portable across a variety of hardware and also efficient enough to
compete with custom code written for just that hardware. Fortran did
okay for array-oriented number-crunching code, but nobody could do it
for general-purpose code such as what you’d use to build just about
anything down to, oh, say, an operating system.

So this young upstart whippersnapper comes along and decides to try to
specify a language that will let people write programs that are: (a)
high-level, with structures and functions; (b) portable to just about
any kind of hardware; and (c) efficient on that hardware so that
they’re competitive with handcrafted nonportable custom assembler code
on that hardware. A high-level, portable, efficient systems
programming language.

How silly. Everyone knew it couldn’t be done.

C is a poster child for why it’s essential to keep those people who
know a thing can’t be done from bothering the people who are doing it.
(And keep them out of the way while the same inventors, being anything
but lazy and always in search of new problems to conquer, go on to use
the world’s first portable and efficient programming language to build
the world’s first portable operating system, not knowing that was
impossible too.)

Thanks, Dennis.
"

https://plus.google.com/u/0/101960720994009339267/posts/33mmANQZDtY

The UNIX Time-Sharing System
http://www.alcatel-lucent.com/bstj/vol57-1978/articles/bstj57-6-1905.pdf

UNIX Time-Sharing System: A Retrospective
http://www.alcatel-lucent.com/bstj/vol57-1978/articles/bstj57-6-1947.pdf

UNIX Time-Sharing System: The C Programming Language
http://www.alcatel-lucent.com/bstj/vol57-1978/articles/bstj57-6-1991.pdf

http://geektionnerd.net/un-genie-est-mort/

Friday, October 07, 2011

Farewell Steve

I remember when it all started, moving that turtle around on the screen in elementary school using Logo then came the Apple I.

I remember programming Basic on an Apple ][ playing, karateka, sorcelery choplifter and loderunner.

I remember playing chess master on the mac+ of my uncle.

I remember beeing impressed by the 16 millions color of the Next Cube and it's DSP processor and I remember looking at the Next computer in Reims and drooling on being able to compile anything on it.

I remember seeing Toy Story and some cool pixar CGI done with renderman.

I remember working on a car adapter for the iPod at Motorola when the stock rise begin

I remember the simplicity of the iPod Touch.

I remember trading an iPod touch against two Adobe products to listen to music in my car after quite some resistence.

I remember comparing Microsoft, Google, Apple and the NASDAQ chart on yahoo and Google finance web site and see how Apple reaches 400$ and became the largest company in US by passing Chevron.

I remember enjoying writing COCOA code for Adobe on a very slick Mac Book Pro 17 inch.

I remember seeing Steve so incredibly excited to give a “small token” of appreciation at the Apple all-hands by giving everyone an iPod shuffle.

I remember the war between Apple and Adobe around Flash and in the end I think you made the right decision and left an open window for engineer to replace FLash by HTML5.

I remember seeing the words pancreatic cancer on the internet.

I remember my first iPhone 4 and that I will have an iPad soon :)

I remember my optimism and the world optimisim of seeing Steve beating this thing like Phil Lesh, the bassist of the Grateful Dead who defeated prostate cancer. This is sad to see that the one-year relative survival rate for pancreatic cancer is 20%, and the five-year rate is 4%.


This week many folks stopped by the Apple campus to pay some respects and remember Steve.


The parking lot was packed. There was some security, a bench with some flowers, some candles, and an iPad with the photo of Steve on the display.


Silence, Sadness and Loss.

Steve touched our lives in so many personal, and emotional ways. Thanks you for being different and a genius leader!


You will be missed Steve!

http://www.cnn.com/2011/10/05/us/obit-steve-jobs/index.html